[英]How to determine the colours when using matplotlib.pyplot.imshow()?
[英]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.