notphunny
notphunny

Reputation: 55

OpenCV 2.3 Mat accessing single channel matrix elements

This is how it should be done, and if i try simple code it works:

Mat a= Mat(4,3, CV_32FC1);
float elem_a= a.at<float>(i,j); 

But after doing some math, this code gives worng results

Mat intrinsics(3, 3, CV_32FC1 );  
Mat distortion( 5, 1, CV_32FC1 );
fs["camera_matrix"] >> intrinsics; //3*3
fs["distortion_coefficients"] >> distortion; //5*1

Mat rvec( 1, 3, CV_32FC1 );
Mat tvec( 1, 3, CV_32FC1 );
Mat R( 3, 3, CV_32FC1 );
Mat A( 3, 3, CV_32FC1 );

solvePnP( Mat(objectPoints), Mat(imagePoints), intrinsics, distortion, rvec, tvec, false );

Rodrigues( rvec, R );
A = intrinsics * R;

cout << "A = " << A << endl;
cout << "A[0] = " << A.at<float>(0,0) << "A[1] = " << A.at<float>(0,1) << endl;

Output:

A = 
 [-123.6820813196553, 792.0751394843999, -359.9404307669494;
  668.8426426360758, -15.08087511838299, -513.8498143647524;
  -0.3389607187919322, -0.03644067597638417, -0.9400945209128925]

A[0] = 4.12987e+09 A[1] = -3.48313

What Am I doing wrong? Ty

Upvotes: 1

Views: 4852

Answers (1)

Andrey Kamaev
Andrey Kamaev

Reputation: 30122

Please check the data type of A matrix. I think it was silently converted to CV_64F.

Upvotes: 1

Related Questions