2

I try to convert a boost::array rightCamInfo.K to an opencv Mat cv::Mat K. I didn't found any functions for this setting so I wrote an iterative approach:

float tempK[9];
cv::Mat K;
for (int i = 0; i < 9; i++) {
   tempK[i] = rightCamInfo.K[i];
}
K = cv::Mat(3, 3, CV_64F, &tempK);

But this is giving me strange results. The range of the given data is between 400 and 0 and the result matrix is around 5 * 10^(-315). So obviously there are some conversion errors. What is wrong? Did I chose the wrong type for the matrix or does this array type is not fitting?

1 Answer 1

6

You should use CV_32F not CV_64F and point the first element of tempK

K = cv::Mat(3, 3, CV_32F, &tempK[0]);

or

Mat K(3, 3, CV_32F, &tempK[0]);
Sign up to request clarification or add additional context in comments.

2 Comments

Such a small thing but it works. Thanks. Can you shortly explain why this is making a difference?
CV_32F (32 bit) says the byte I'm reading now is float whereas CV_64F says it is double (64 bit). When you try to read with CV_64F, you try to read a float value as if it is double.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.