Ask Your Question
0

What is the meaning of: TheMarkers[0].Tvec.at<Vec3f>(0,0)[0];

asked 2015-04-14 14:18:14 -0500

mirind4 gravatar image

updated 2015-04-14 14:37:24 -0500

berak gravatar image

Hey!

I would like to ask a question. I am using Aruco AR library, and I would like to define the coordinates of a marker. A part of my c++ code:

double x_t = -TheMarkers[0].Tvec.at<Vec3f>(0,0)[0];
double y_t = TheMarkers[0].Tvec.at<Vec3f>(0,0)[1];
double z_t = TheMarkers[0].Tvec.at<Vec3f>(0,0)[2];

To be honest I do not know what is the exact meaning of these lines. What I have so far figured out using stackoverflow and this site: (Let's see only the first line):

double x_t = -TheMarkers[0].Tvec.at<Vec3f>(0,0)[0];

TheMarkers[0]: the "0" index means that we want to inquire/get the first marker detected. It is clear.

Tvec: This is the 3D translation vector with x,y,z translation values. So how far is my marker relating to my camera coordinate system.

The next would be my first question: What does "at" mean at "Tvec.at"? I found an information on the internet about what does Vec3f mean: The Vec3f class provides a vector object for 3 dimensional locations or RGB pixel values.

After that the (0,0) part is also vague to me. Why should I use (0,0)?

The index at the end ([0]) is clear for me...

Thanks in advance for the answer!

edit retag flag offensive close merge delete

Comments

well I understand it party, but still have question, so I am not totally familiar with the example line. As far as I know Aruco is totally based on OpenCV...Sorry if I made mistake for putting this question here, but I am of the opinion of that it is the right site to place this question.

mirind4 gravatar imagemirind4 ( 2015-04-14 14:40:36 -0500 )edit

no fear. at least tell us the type of Markers.TVec. if it is Vec3f (or Vec3d), it should boil down to a simple: TheMarkers[0][0], TheMarkers[0][1], TheMarkers[0][2], etc.

berak gravatar imageberak ( 2015-04-14 14:46:23 -0500 )edit

the type of "TVec" is: cv::Mat

mirind4 gravatar imagemirind4 ( 2015-04-14 14:51:18 -0500 )edit
1

sad as it is, you'll have to query Markers[i].TVec.type(),

and use the appropriate at<type>(row,col)[channel] syntax then.

berak gravatar imageberak ( 2015-04-14 14:55:47 -0500 )edit

Really thanks for your help! TheMarkers[0].Tvec.type() = 5. To be honest I am suprised a bit, because of this "five" type...

mirind4 gravatar imagemirind4 ( 2015-04-14 15:01:55 -0500 )edit
1

5==CV_32F==float

stupid as it is, - you got a 1 element Mat(thus (0,0) index) with 3 float channels( thus the final [i] indexing) there.

(above is wrong, please see answer below)

(Vec3f is actually a Mat, too, but it has the additional [] shortcut)

berak gravatar imageberak ( 2015-04-14 15:24:26 -0500 )edit

ohh i see! Thank you very much! I think now I got the meaning of the line :)

mirind4 gravatar imagemirind4 ( 2015-04-14 15:51:44 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2015-04-19 04:40:55 -0500

sgarrido gravatar image

Hi,

TheMarkers[0].Tvec is a cv::Mat composed by 3 floats (3x1, 3 rows and 1 column), so this code is equivalent:

double x_t = -TheMarkers[0].Tvec.at<float>(0,0);
double y_t = TheMarkers[0].Tvec.at<float>(1,0);
double z_t = TheMarkers[0].Tvec.at<float>(2,0);

The problem is that sometimes you could forget if Tvec's size is 3x1 or 1x3 and confuse the at() indexes.

By using cv::Vec3f you avoid this problem since you dont need to specify columns or rows.

An alternative is using .ptr():

double x_t = -TheMarkers[0].Tvec.ptr<float>(0)[0];
double y_t = TheMarkers[0].Tvec.ptr<float>(0)[1];
double z_t = TheMarkers[0].Tvec.ptr<float>(0)[2];
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2015-04-14 14:18:14 -0500

Seen: 467 times

Last updated: Apr 19 '15