# Matrix rotation error and how pull out a single element

Hi, I have problem with matrix rotation. I am using the module Aruco to receive marker position. Then I use the function Rodrigues () to receive a rotation matrix. I would like to pull out of the matrix as a single element needs to calculate the orientation of the marker. But all the time I error. The following code:

cv::Mat rvecs, tvecs;

// detect markers and estimate pose
aruco::detectMarkers(image, dictionary, corners, ids, detectorParams, rejected);
if (estimatePose && ids.size() > 0)
aruco::estimatePoseSingleMarkers(corners, markerLength, camMatrix, distCoeffs, rvecs, tvecs);
double currentTime = ((double)getTickCount() - tick) / getTickFrequency();

Mat R = Mat::zeros(3, 3, CV_64F);
Rodrigues(rvecs, R);


Here is the formula:

Mat Thz = (atan2 (R (3), R (0))) * (180 / M_PI)


But the problem is in the variables.

When I'm use R.at <double> (1, 1) displays a single element matrix. For example, when I give Mat thz = atan2 (R.at <double> (1, 1), R.at <double> (1, 2)); ,

displays error C2440: 'initializing': can not convert from 'double' this' cv :: Mat

How do I convert the matrix R so I can use them with designs and functions atan2?

edit retag close merge delete

• where did you get that formula ? (context matters)
• rvecs is already rotation around principal axes
• what is your required output ?

*Professor at the University gave me this formula

*I know that it is a vector of rotation, according to Professor I do with this design, which is why it needs rotation matrix.

*The main idea is that I received the position and orientation of the marker relative to the camera. I needs this to the vision system robot. To be able later to steer the robot at reasonably "When X> 10 move to the left of 5, etc." when the camera will centered over the marker the robot takes the object

Sort by » oldest newest most voted The error is not in the .at<double>() function. It is properly returning a double. You are trying to assign that double to a Mat, which doesn't work.

Either change Thz to a double, or create it as a 1x1 matrix and use Thx.at<double>(0,0) = atan2(...

more

I create

Mat Thx = Mat::zeros(1, 1, CV_64F);
Thx.at<double>(0, 0) = (atan2(R(3), R(0))) * (180 / M_PI)


And error Error 1 error C2664: 'cv::Mat cv::Mat::operator ()(cv::Range,cv::Range) const' : cannot convert argument 1 from 'int' to 'const cv::Range *'

You are doing R(0) and R(3). You need to figure out what index that actually is, and use R.at<double>(whatever).

Official site

GitHub

Wiki

Documentation