Ask Your Question
0

CvMat vs cv::Mat data pointer

asked 2016-04-22 02:12:47 -0600

hyder gravatar image

Hi,

I am trying to convert some code using CvMat to cv::Mat, but I cannot seem to figure out how to access the float* fl field present in data union of CvMat using cv::Mat. For example,

CvMat* Y; 
Y->data.fl[0] = (float)(a);
Y->data.fl[1] = (float)(b);

how to convert the above code if Y is cv::Mat?

 cv::Mat* Y; 
 Y->data.fl[0] = (float)(a);         //data is a pointer instead of a union
 Y->data.fl[1] = (float)(b);

I think I will have to use double index in cv::Mat case such as data[x][y]. But how to decide the values of x and y using .fl[i] index.

Thanks!

edit retag flag offensive close merge delete

Comments

1
  • what are you trying to achieve ?
  • don't use pointers to cv::Mat, you're breaking the internal refcounting this way.
  • use Mat::at<type>(r,c) or Mat::ptr<type>(r), not the "raw" internal data member.
  • don't try to port your old code "literally". opencv has evolved a lot in the meantime, chances are, that there's a high level function already, for what you're trying to do. (so, again - what is it ?)
berak gravatar imageberak ( 2016-04-22 02:30:26 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-04-25 06:27:34 -0600

hyder gravatar image

updated 2016-04-25 06:29:50 -0600

@berak,

  • The CvMat* Y is actually a 2x1 measurement matrix used for Kalman correction cv::KalmanFilter::correct(Y) and I need to set the two values of the Y matrix with a and b (which I know realize can be set simply by Y(0) = (float)a and Y(1) = float(b) ).

  • Thanks for the suggestion. Removed the pointers.

  • I am now using Mat::at<float>(r) notation to access the values of Mat correction returned by cv::KalmanFilter::correct(Y).

  • Solved my problem. Thanks!
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-04-22 02:12:47 -0600

Seen: 2,150 times

Last updated: Apr 22 '16