Reputation: 55
I am trying to create a 4x4 matrix with cv::Mat(4,4,CV_64F, data_m);
,
where data_m is a float array
float data_m[] = {rmatrix.at<float>(0,0),rmatrix.at<float>(0,1), rmatrix.at<float>(0,2), tvec[0],rmatrix.at<float>(1,0), rmatrix.at<float>(1,1), rmatrix.at<float>(1,2), tvec[1], rmatrix.at<float>(2,0), rmatrix.at<float>(2,1), rmatrix.at<float>(2,2), tvec[2],0.f ,0.f ,0.f, 1.f};
and rmatrix is a 3x3 matrix, tvec is a 3x1 vector.
However, when initializing translation_m
cv::Mat translation_m = cv::Mat(4,4,CV_64F, data_m);
the last eight elements were not successfully initialized in translation_m
matrix. It returns some weird alien number like 4.59121e-41
.
Does anyone have an insight on what is going on here?
Upvotes: 0
Views: 1084
Reputation: 41776
You're mixing double
(64 bit, CV_64F
) and float
(32 bit, CV_32F
).
When reading your float array as double your're going after the end of the vector, and you're reading uninitialized data.
Use either:
float data_m[] = ...
cv::Mat translation_m = cv::Mat(4,4,CV_32F, data_m);
or
double data_m[] = ...
cv::Mat translation_m = cv::Mat(4,4,CV_64F, data_m);
Upvotes: 1