Ask Your Question
0

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

asked 2013-05-15 18:35:57 -0600

orochi gravatar image

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

edit retag flag offensive close merge delete

Comments

after go through the Java API again, i should not convert this code CvMat pointMat = cvMat( 1, nLandmarks, CV_32SC2, pointsHull ); CvMat hullMat = cvMat( 1, nLandmarks, CV_32SC1, hull ); into this Mat pointMat = new Mat(1, nLandmarks, CvType.CV_32SC2, pointsHull); Mat hullMat = new Mat(1, nLandmarks, CvType.CV_32SC1, hull); i should convert it into this instead MatOfPoint pointMat = new MatOfPoint(pointsHull); MatOfInt hullMat = new MatOfInt(hull); am i correct?

orochi gravatar imageorochi ( 2013-05-15 21:59:39 -0600 )edit

Instead of commenting your question, you should better edit your question. This makes it easier to read. And actually you should ask a new question, because converting C++ code into Java code is something completely different than understanding C/C++ structures.

Ben gravatar imageBen ( 2013-05-21 09:15:53 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
3

answered 2013-05-16 03:06:01 -0600

Ben gravatar image

updated 2013-05-21 09:31:10 -0600

cv:: is just specifying the namespace. So you can either use cv::Mat or declare a using namespace cv; in your file and use Mat. CvMat is a C structure and cvMat(...) is just a function returning a CvMat structure, like a constructor.

In the above code, the 'cv::Mat' is not really necessary, as the namespace cv was included in PAW.h. And 'CvMat' is just a struct, which is basically a class without methods. 'cvMat(...)' is a function initializing the struct with data.

edit flag offensive delete link more

Comments

thank you Ben for the answer. i really appreciate it. referring to Head Pose Estimation sample, why the author sometime use Mat and cv::Mat and then sometime use CvMat and cvMat, is there any particular reason?

orochi gravatar imageorochi ( 2013-05-16 18:17:01 -0600 )edit

I'm glad I could help. When you're satisfied with an answer, you can accept it as answered. I edited my answer for your further questions.

Ben gravatar imageBen ( 2013-05-21 09:32:31 -0600 )edit

Hi Ben, thank you for the update, it's really help me a lot. now my problem is converting opencv c++ into java. I cant find method such as CvQuadEdge2D, CvSeq, cvStartReadSeq and many more in java doc. if you accidentally found any article or tutorial regarding converting opencv c++ into java, pls let me know. Thank you Ben.

orochi gravatar imageorochi ( 2013-05-21 09:48:51 -0600 )edit

Question Tools

Stats

Asked: 2013-05-15 18:35:57 -0600

Seen: 8,035 times

Last updated: May 21 '13