简体   繁体   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

Okay, I'm trying to extract my local binary pattern image from a processed normal face image and then show it in my QT Gui. 好的,我正在尝试从经过处理的正常人脸图像中提取本地二进制模式图像,然后将其显示在我的QT Gui中。 The following code to do this is: 以下代码可以做到这一点:

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

But this results in: 但这导致: 没有预期的结果。 .

Now, If i uncomment the plt.imshow I get the following result (Which is what I want to show in my GUI): 现在,如果我取消对plt.imshow的注释,则会得到以下结果(这是我想在GUI中显示的内容): 预期结果。

I've tried various stuff and got the best result if I tried adding: 我尝试了各种方法,如果尝试添加,则会获得最佳结果:

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

resulting in: 导致: 再近一点...

Any ideas how to fix this? 任何想法如何解决这一问题? I mean, it shows fine on the matplot figure, but somehow gets badly distorted once turned into a QImage 我的意思是,它在Matplot图上显示正常,但是一旦变成QImage,它就会以某种方式严重失真

Will also add that I'm totally new with QT4. 还要补充一点,我对QT4完全陌生。

After trying various stuff I ended up doing this, although not very optimal and probably a tad slow, but it works and shows me a faceimage: 在尝试了各种方法之后,我最终做到了这一点,尽管不是很理想,可能有点慢,但它可以工作并显示了一个人脸图像:

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.

相关问题 使用matplotlib.pyplot.imshow()时如何确定颜色? - How to determine the colours when using matplotlib.pyplot.imshow()? matplotlib.pyplot.imshow 中的神器 - Artifact in matplotlib.pyplot.imshow 使用 matplotlib.pyplot.imshow() 绘制二维直方图时出现“TypeError:dtype 对象的图像数据无法转换为浮点数” - "TypeError: Image data of dtype object cannot be converted to float" when drawing 2d histogram using matplotlib.pyplot.imshow() 使用Jupyter重新绘制matplotlib.pyplot.imshow - Redraw matplotlib.pyplot.imshow in place using Jupyter 在子图环境中使用时,matplotlib.pyplot.imshow的边距 - Margins of matplotlib.pyplot.imshow when used in subplot environment matplotlib.pyplot.imshow:使用属性“sharex”和“sharey”时删除绘图中的空白区域 - matplotlib.pyplot.imshow: removing white space within plots when using attributes “sharex” and “sharey” 使用矩阵第一行的值作为matplotlib.pyplot.imshow的刻度 - Using the values of the first row of a matrix as ticks for matplotlib.pyplot.imshow 如何在matplotlib.pyplot.imshow中使用“范围” - how to use 'extent' in matplotlib.pyplot.imshow python matplotlib.pyplot.imshow tkinter错误 - python matplotlib.pyplot.imshow tkinter error 为什么 matplotlib.pyplot.imsave() 和 matplotlib.pyplot.imshow() 图像质量不同? 如何保证同样的质量? - Why matplotlib.pyplot.imsave() and matplotlib.pyplot.imshow() image qualities are different? How to ensure the same quality?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM