Ask Your Question

Revision history [back]

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];