Reputation: 15
I know this question has been asked and answered by others. But I still can't not solve my question. I read a frame from a video, which has format unsigned char (CV_8U). I hope to convert it to double precision(CV_64F). I do as following:
VideoCapture capture(fileName);
Mat image;
capture >> image;
cvtColor(image, image, CV_BGR2GRAY);
image.convertTo(image, CV_32FC1, 1.0/255);
cout << typeid(image.data[0]).name() << endl;
But the result shows the image is still unsigned char. What's wrong with my code? Thank.
Upvotes: 0
Views: 1044
Reputation: 2660
This is not the right way to test for type conversion.
OpenCV's data
variable in cv::Mat
is always of type uchar
. It is basically a pointer to memory, but it doesn't mean that the data is uchar
.
To get the type of the image data use the type()
function. Here is an example to test if the type was successfully converted to float (which will be)
cv::DataType<float>::type == image.type();
Upvotes: 2