Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV Mat object - get data length

Tags:

c++

opencv

In OpenCV, I'm able to capture frames using VideoCapture in C++, however, when I try to get the data from a frame and calculate length, it just returns me 0.

Below is my sample code:

VideoCapture cap(0);
for(;;) {
  Mat frame;
  cap >> frame;
  int length = strlen((char*) frame.data); // returns 0
}

As I mentioned above that if I save the frame in a PNG file, I can actually see the image so I'm not able to understand why the data length is coming out to be zero.

Any clue?

like image 461
pree Avatar asked Apr 03 '14 21:04

pree


People also ask

What is CV_32F?

CV_32F : 4-byte floating point ( float ).

What is CV_64F?

That is, image of type CV_64FC1 is simple grayscale image and has only 1 channel: image[i, j] = 0.5. while image of type CV_64FC3 is colored image with 3 channels: image[i, j] = (0.5, 0.3, 0.7) (in C++ you can check individual pixels as image.at<double>(i, j) ) CV_64F is the same as CV_64FC1 .

What is mat object in OpenCV?

The Mat class of OpenCV library is used to store the values of an image. It represents an n-dimensional array and is used to store image data of grayscale or color images, voxel volumes, vector fields, point clouds, tensors, histograms, etc.

What is scalar OpenCV?

ScalarRepresents a 4-element vector. The type Scalar is widely used in OpenCV for passing pixel values. In this tutorial, we will use it extensively to represent BGR color values (3 parameters). It is not necessary to define the last argument if it is not going to be used.


1 Answers

You can also do:

Mat mat;
int len = mat.total() * mat.elemSize(); // or mat.elemSize1()
like image 196
Asalle Avatar answered Oct 22 '22 06:10

Asalle