简体   繁体   English

无法将OpenCV 16位灰度图像写入/显示到磁盘

[英]Unable to write/display a OpenCV 16 bit grayscale image to disk

I have a 2D unsigned short array from which I am trying to create a 16-bit grayscale image using the OpenCV. 我有一个2D无符号短数组,我正在尝试使用OpenCV从中创建16位灰度图像。 The code tried is shown below. 尝试的代码如下所示。 But when I try to display or save to disk I get a black image with all pixel values zeros. 但是,当我尝试显示或保存到磁盘时,我得到的黑色图像的所有像素值均为零。

unsigned short Img_2D_array [SIZE_X][SIZE_Y];
for(int vr=1; vr<20; vr++)
    {
        for(int vc=1; vc<16; vc++)
        {
          Img_2D_array[(vr)][(vc)] = (unsigned short)(varPixelValue);
        }
    }
Mat var_mat = Mat(SIZE_X,SIZE_Y,CV_16UC1,&Img_2D_array);
imwrite("testImage.png",var_mat);

Note : Edited the code 注意:编辑代码

There was no problem with the code snippet. 代码段没有问题。 But the viewer with which I was viewing the image didn't support 16-bit grayscale images, Nothing to do with the code. 但是与我一起查看图像的查看器不支持16位灰度图像,与代码无关。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM