Ask Your Question
0

Matrix rotation error and how pull out a single element

asked 2016-11-10 04:37:04 -0600

DrN22 gravatar image

updated 2016-11-10 04:37:46 -0600

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 flag offensive close merge delete

Comments

  • where did you get that formula ? (context matters)
  • rvecs is already rotation around principal axes
  • what is your required output ?
berak gravatar imageberak ( 2016-11-10 04:43:26 -0600 )edit

*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

DrN22 gravatar imageDrN22 ( 2016-11-10 04:50:44 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-11-10 11:07:08 -0600

Tetragramm gravatar image

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(...

edit flag offensive delete link more

Comments

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 *'

DrN22 gravatar imageDrN22 ( 2016-11-14 03:43:30 -0600 )edit

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

Tetragramm gravatar imageTetragramm ( 2016-11-14 17:41:17 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-11-10 04:37:04 -0600

Seen: 548 times

Last updated: Nov 10 '16