OpenCV: convertTo returns white image (sometimes)

后端 未结 1 1342
旧巷少年郎
旧巷少年郎 2021-02-05 16:36

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 ju

1条回答
  •  无人及你
    2021-02-05 17:04

    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)
    

    0 讨论(0)
提交回复
热议问题