Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Difference between CvMat, cvMat, cv::Mat, and Mat

Hi everyone,

i am quite new into opencv, i will go straight forward, just like title of my question, what is the difference between CvMat, cvMat, cv::Mat, and Mat. i found out that cv::Mat is c++ version of cvMat, but then, is CvMat is same with Mat? and is cvMat is a constructor of CvMat?

The reason i am asking this because i want to write Head Pose Estimation sample using Java. In that sample, inside PAW.cpp i found code like this

Mat warp = cv::Mat(nTriangles, 6, CV_64FC1);

which based on my knowledge, if i turn this code into Java it will become like this

Mat warp = new Mat(nTriangles, 6, CvType.CV_64FC1);

but then when i scroll down PAW.cpp file, i found

//calc scrLandmarks convex hull
    CvPoint* pointsHull = (CvPoint*)malloc( nLandmarks * sizeof(pointsHull[0]));
    int* hull = (int*)malloc( nLandmarks * sizeof(hull[0]));
    CvMat pointMat = cvMat( 1, nLandmarks, CV_32SC2, pointsHull );
    CvMat hullMat = cvMat( 1, nLandmarks, CV_32SC1, hull );

my question is, why the author sometime use Mat and cv::Mat and then sometime use CvMat and cvMat, is there any particular reason?

and if i convert the above code into Java, it will become like this

Point[] pointsHull = new Point[nLandmarks];
int[] hull = new int[nLandmarks];
Mat pointMat = new Mat(1, nLandmarks, CvType.CV_32SC2, pointsHull);
Mat hullMat = new Mat(1, nLandmarks, CvType.CV_32SC1, hull);

but this code will generate an error because in opencv 2.4.5 Java api, i cannot found Mat constructor with argument (int, int, int, Point[]) or (int, int, int, int[]). is the constructor deprecated in opencv 2.4.5 or am i doing it wrongly? i am not a java expert and only has a little knowledge about c++. any hint or suggestion about how to do it correctly?

please excuse my English :D