[英]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)
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.