【问题标题】:Image looks good on matplotlib.pyplot.imshow , but is horribly distorted when shown on QT GUi using Qimage图像在 matplotlib.pyplot.imshow 上看起来不错,但在使用 Qimage 在 QT GUI 上显示时会严重失真
【发布时间】:2016-09-18 19:41:07
【问题描述】:

好的,我正在尝试从处理过的正常人脸图像中提取我的本地二值模式图像,然后将其显示在我的 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 的新手。

【问题讨论】:

    标签: python numpy image-processing matplotlib pyqt4


    【解决方案1】:

    在尝试了各种方法后,我最终做到了这一点,虽然不是非常理想并且可能有点慢,但它确实有效并显示了一张面部图像:

    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")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-09
      • 1970-01-01
      • 2015-05-09
      相关资源
      最近更新 更多