opencv -- cvSaveImage图像正常, cvShowImage图像全黑

  • 今天遇到这样一个问题,同一个数据(IplImage *img),使用cvSaveImage可以保存正常的图像,而使用cvShowImage看到的图像却是黑色的。
    查找opencv文档发现是cvShowImage()时数值map的问题。我的原始数据是10bit的,所以在创建IplImage img时选用的是类型是IPL_DEPTH_16U,低10bit有效。通过阅读官方文档找到原因, imshow:

The function imshow
displays an image in the specified window. If the window was created with the CV_WINDOW_AUTOSIZE
flag, the image is shown with its original size, however it is still limited by the screen resolution. Otherwise, the image is scaled to fit the window. The function may scale the image, depending on its depth:

  • If the image is 8-bit unsigned, it is displayed as is.
  • If the image is 16-bit unsigned or 32-bit integer, the pixels are divided by 256. That is, the value range [0,255*256] is mapped to [0,255].
  • If the image is 32-bit floating-point, the pixel values are multiplied by 255. That is, the value range [0,1] is mapped to [0,255].
  • 看到了吧,这样就找到原因了,我是用IPL_DEPTH_16U存储pixel值的,当调用imshow时会做map处理,[0, 65535]----[0, 255]。而我的数据只有10bit有效,最大才1023,按照这个map方式1023对应的值是4。这样就造成全黑显示了!!

你可能感兴趣的:(opencv -- cvSaveImage图像正常, cvShowImage图像全黑)