简体   繁体   中英

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. 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): 预期结果。

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

Will also add that I'm totally new with 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")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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