cv::Mat initialization

asked 2020-03-22 07:03:35 -0600

Suom gravatar image

updated 2020-03-22 07:39:16 -0600

Hello everyone I have a question regarding cv::mat and how to deal with them for example if I use this

 double mydata[9] = { 3.3319948389423814e+02, 0., 6.4337005710516598e+02, 0.,
 3.3365591993191464e+02 ,5.3634048332458769e+02, 0. ,0. ,1. };
 Mat mycameraMatrix = Mat(3, 3, CV_64F, mydata);

and then I used

cout<<mycameraMatrix

or

cout<<mycameraMatrix.at<double>(0,0)

I got completely different values from the values of array (mydata)

so instead I wrote this

Mat mycameraMatrix = Mat(3, 3, cv::DataType<double>::type);
mycameraMatrix.at<double>(0, 0) = 3.3319948389423814e+02;
mycameraMatrix.at<double>(0, 1) = 0.0;
......

so is that correct? and why the values are changing in the first method

edit retag flag offensive close merge delete

Comments

mycameraMatrix.at(0,0) defaults to mycameraMatrix.at<uchar>(0,0) -- clearly wrong. at<double>(0, 0) -- correct

berak gravatar imageberak ( 2020-03-22 07:14:36 -0600 )edit

sorry I mean at<double>(0,0) it was typo I will fix it

Suom gravatar imageSuom ( 2020-03-22 07:38:57 -0600 )edit

cout<< mycameraMatrix.at<double>(0,0) << endl;

333.199

no problem here

berak gravatar imageberak ( 2020-03-22 08:35:42 -0600 )edit

I was getting strange results, I re-wrote the program again carefully and the problem was gone .. I believe it was a dirty code problem ..thank you

Suom gravatar imageSuom ( 2020-03-24 05:57:37 -0600 )edit