繁体   English   中英

图像在matplotlib.pyplot.imshow上看起来不错,但是当在QT GUi上使用Qimage显示时,图像却严重扭曲

[英]Image looks good on matplotlib.pyplot.imshow , but is horribly distorted when shown on QT GUi using Qimage

好的,我正在尝试从经过处理的正常人脸图像中提取本地二进制模式图像,然后将其显示在我的QT Gui中。 以下代码可以做到这一点:

def extractFace(self):
    try:



        self.lbpface = self.model.lbpface(self.face)
        height, width = self.self.lbpface.shape[:2]

        #plt.imshow(self.lbpface, cmap= 'gray')
        #plt.show()

        img = QtGui.QImage(self.lbpface,
                           width,
                           height,
                           QtGui.QImage.Format_Indexed8)
        return QtGui.QPixmap.fromImage(img)
    except:
        return QtGui.QPixmap("nosignal.jpg")

但这导致: 没有预期的结果。

现在,如果我取消对plt.imshow的注释,则会得到以下结果(这是我想在GUI中显示的内容): 预期结果。

我尝试了各种方法,如果尝试添加,则会获得最佳结果:

self.lbpface = np.asarray(self.model.lbpface(self.face), dtype = np.uint8)

导致: 再近一点...

任何想法如何解决这一问题? 我的意思是,它在Matplot图上显示正常,但是一旦变成QImage,它就会以某种方式严重失真

还要补充一点,我对QT4完全陌生。

在尝试了各种方法之后,我最终做到了这一点,尽管不是很理想,可能有点慢,但它可以工作并显示了一个人脸图像:

def extractFace(self):
    try:
        self.lbpface = self.model.lbpface(self.face)

        cv2.imwrite("TEST.JPG",self.lbpface)

        return QtGui.QPixmap('TEST.JPG')
    except:
        return QtGui.QPixmap("nosignal.jpg")

暂无
暂无

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

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