I am using opencv to open an image and putting qimage into qpixmap.
Since the Korean route is included, imread is performed in the following way.
def imread(filename, flags=cv2.IMREAD_COLOR, dtype=np.uint8): try: n = np.fromfile(filename, dtype) img = cv2.imdecode(n, flags) return img except Exception as e: print(e) return None
The image you want to pixmap
Photos were captured using the Windows built-in capture function.
Pixmap image in the program
The picture is straight, but when I print it out in the program, it comes out weird.
qimage = QImage(img.data.tobytes(), img.shape, img.shape, QImage.Format_RGB888).rgbSwapped()
I think there is a problem with this code.
Currently, only the two photos I captured are having this problem.
There is no error in one picture, but it is tinggi and the other picture is printed in a different shape as above.
Properties of both photos. [Photo resolution
, pixel, Bit level]
def pixmap_image(self, img): qimage = QImage(img.data.tobytes(), img.shape, img.shape, QImage.Format_RGB888).rgbSwapped() qpixmap = QPixmap.fromImage(qimage).scaled(self.img_preview_viewer.width(), self.img_preview_viewer.height(), aspectRatioMode=Qt.KeepAspectRatio) self.img_preview_viewer.setPixmap(qpixmap)
I would like to know why some pictures come out correctly and some do not come out properly.
Is the code wrong?
I assume this is the problem with the odd-resolution picture. I hope I’m right.