Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does Mat::checkVector do in OpenCV?

I tried to use the following function in OpenCV (C++)

calcOpticalFlowPyrLK(prev_frame_gray, frame_gray, points[0], points[1], status, err, winSize, 3, termcrit, 0, 0.001);

and I get this error

OpenCV Error: Assertion failed ((npoints = prevPtsMat.checkVector(2, CV_32F, true)) >= 0) in calcOpticalFlowPyrLK,
file /home/rohit/OpenCV_src/opencv-2.4.9/modules/video/src/lkpyramid.cpp, line 845
terminate called after throwing an instance of 'cv::Exception'
what():  /home/rohit/OpenCV_src/opencv-2.4.9/modules/video/src/lkpyramid.cpp:845:
error: (-215) (npoints = prevPtsMat.checkVector(2, CV_32F, true)) >= 0 in function calcOpticalFlowPyrLK

Both of the following return -1

frame_gray.checkVector(2, CV_32F, true)
prev_frame_gray.checkVector(2, CV_32F, true)

I wanted to know what checkVector actually does because it is leading to the assertion error as you can see above.

like image 957
rohit-biswas Avatar asked May 06 '15 20:05

rohit-biswas


People also ask

What does MAT mean 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 does MAT mean in C++?

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 ...

What is Vec3b?

Vec3b is the abbreviation for "vector with 3 byte entries" Here those byte entries are unsigned char values to represent values between 0 .. 255. Each byte typically represents the intensity of a single color channel, so on default, Vec3b is a single RGB (or better BGR) pixel.

What is CV_64FC1?

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 .


1 Answers

The official OpenCV's doc says:

cv::Mat::checkVector() returns N if the matrix is 1-channel (N x ptdim) or ptdim-channel (1 x N) or (N x 1); negative number otherwise

OpenCV considers some data types equivalent in case of some functions i.e. objectPoints of cv::solvePnP() can be:

  • 1xN/Nx1 1-channel cv::Mat
  • 3xN/Nx3 3-channel cv::Mat
  • std::vector<cv::Point3f>

With checkVector you can make sure that you are passing the correct representation of your data.

like image 70
Kornel Avatar answered Oct 04 '22 05:10

Kornel