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?
解决方案
The strlen method only works on strings, which are arrays of chars terminated by a special character:
You have cast a Mat type as a char*, so it is not a string.
Building on the solution here, try:
Mat mat;
int rows = mat.rows;
int cols = mat.cols;