Ask Your Question
0

What is the difference between pointer access of cv::Mat and CvMat?

asked 2018-09-17 01:32:18 -0500

Conundraah gravatar image

updated 2018-09-17 01:34:10 -0500

Hello!

I have a question regarding a certain difference between CvMat and cv::Mat. I am aware that cv::Mat is the C++ "version" of CvMat and they should work identically. But I encountered a problem two days ago, which I cannot get my head around: In an OpenCv source code I found the following line of code, which I would like to reuse for my own project:

cv::Ptr<cvmat> err = cvCreateMat(1, count, CV_32FC1); ...
double median = count % 2 != 0 ?
err->data.fl[count / 2] : (err->data.fl[count / 2 - 1] + err->data.fl[count / 2])*0.5;

Since the old C API is declared as deprecated in the documentary I would like to update it to the new C++ API. Unfortunately I have not found a way to implement this. I tried:

cv::Mat err(1, count, CV_32FC1);
double median = count % 2 != 0 ?
err.data[count / 2] : (err.data[count / 2 - 1] + err.data[count / 2])*0.5;

As far as I understand the documentation of both types, they should be equal but unfortunately both ways yield different results. Did I overlook something?

Thanks in advance!

edit retag flag offensive close merge delete

Comments

you probably should discard the whole "per-pixel" approach as well.

what is the context ? what are you trying to achieve ?

berak gravatar imageberak ( 2018-09-17 01:42:01 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-09-19 01:58:57 -0500

Conundraah gravatar image

err is a matrix which contains the distance of a pair of pixel after applying a transformation to them. Using the notation of CvMat above, the median should be computed of all elements in err. Since the CvMat is marked as deprecated, I wanted to rewrite this part using CvMat's C++ counterpart cv::Mat. I did not really find an equivalent pointer based solution but I found one, that gave me same results using a cv::Mat variable.

err.at<float>(0, (_numberOfMatches / 2)) : (err.at<float>(0, (_numberOfMatches / 2) - 1) + err.at<float>(0, (_numberOfMatches / 2))*0.5;

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2018-09-17 01:32:18 -0500

Seen: 110 times

Last updated: Sep 19 '18