Pyside2显示opencv转换后的二值图

想在GUI上显示opencv转换后的二值图,但发现通过QIamge转换出来的图片会出现错位,代码如下:

    image = cv.imread('1.jpg', cv.IMREAD_GRAYSCALE)
    image_height, image_width = image.shape
    Qim = QImage(image_width, image_height, QImage.Format_Indexed8)

查了一下资料,只有RGB图的案例,并没有直接显示二值图的案例,更改如下代码后问题解决,需要再指定一下单行的数据长度

    image = cv.imread('1.jpg', cv.IMREAD_GRAYSCALE)
    image_height, image_width = image.shape
    Qim = QImage(image.data, image_width, image_height, image_width, QImage.Format_Indexed8)

 

你可能感兴趣的:(python)