Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV: convertTo returns white image (sometimes)

Tags:

c++

opencv

I'm relatively new to OpenCV and i've stumpled upon a problem. I've got an input image and want to convert it from Type CV_8U to CV_32F.

With some images it works just fine via input.convertTo(output, CV_32F) but with other images output would only give an completly white image.

Number of channels, dims is equal as well as depth. What is the problem?

like image 295
moatilliatta Avatar asked Oct 11 '12 10:10

moatilliatta


1 Answers

I believe the result is normal.

When you use convertTo from CV_8U1 to CV32F1, a pixel value, for example, 255 becomes 255.0. But when you try `imshow' the resulting image, the command expects all pixel values to be between 0.0 and 1.0. that's why, without rescaling the image, the image will look all white.

So this will do the trick as zzz pointed out (thanks).

input.convertTo(output, CV_32F, 1.0/255.0)
like image 96
Tae-Sung Shin Avatar answered Nov 06 '22 06:11

Tae-Sung Shin