4

I am new to C++ programming and OpenCV. I was going through this tutorial on Mat class in OpenCV. It says "each Mat object has its own header" and uses the term header many times. I was not sure what does header mean in this context?

I tried googling and found this page which says: "Mat is basically a class with two data parts: the matrix header (containing information such as the size of the matrix, the method used for storing, at which address is the matrix stored, and so on).........."

Now I understand what does size mean but I have two questions to clarify:

  1. What does "method used for storing" refer to? Which member in the Mat class denotes this?
  2. As for the address, does it correspond to "datastart" member in the Mat class?

Thanks!

Ruchir
  • 845
  • 2
  • 10
  • 24
  • maybe you can think of it as a 'packet', with a small descriptive section in the front (width,height, type, etc.) , followed by the actual content / data / pixels – berak Jun 25 '15 at 09:56
  • Thanks @berak for the reply. I just edited my question which seeks more detailed clarification. Kindly consider answering it. – Ruchir Jun 25 '15 at 10:00
  • 1
    for big data elements like images, the user does not want to copy all the data all the time (e.g. in each function call) but using pointers often isnt safe. So opencv uses those matrix headers (cv::Mat obhect) as objects which arent expensive to copy. the big amount of data instead is given by a pointer within that header. So whenever you copy a cv::Mat object (e.g. with copy-constructor) you dont copy the whole image/pixel data but just the header. – Micka Jun 25 '15 at 10:57
  • Thanks @Micka for the answer. – Ruchir Jun 26 '15 at 02:41

1 Answers1

1

As per the OpenCV documentation:

Mat is basically a class with two data parts: the matrix header (containing information such as the size of the matrix, the method used for storing, at which address is the matrix stored, and so on) and a pointer to the matrix containing the pixel values (taking any dimensionality depending on the method chosen for storing). The matrix header size is constant, however the size of the matrix itself may vary from image to image and usually is larger by orders of magnitude.

sehe
  • 374,641
  • 47
  • 450
  • 633
mystic_coder
  • 462
  • 2
  • 10
  • Thanks @mystic_coder for the reply. I just edited my question which seeks more detailed clarification on what you wrote. Kindly clarify. – Ruchir Jun 25 '15 at 10:01
  • @mystic_coder please start formatting your answers properly, so that they are readable. – sehe Jun 25 '15 at 10:38
  • What does it mean by 'matrix header size is constant' ? – skpro19 Mar 07 '21 at 21:03