I have weird error. When I resize the img2 (it is cropped image from img1), there is no error. The code I wrote is like this:
@pyqtSlot(np.ndarray, np.ndarray)
def update_image(self, img1, img2):
scale_percent1 = 50
scale_percent2 = 50
height1 = int(img1.shape[0] * (scale_percent1 / 100))
width1 = int(img1.shape[1] * (scale_percent1 / 100))
height2 = int(img2.shape[0] * (scale_percent2 / 100))
width2 = int(img2.shape[1] * (scale_percent2 / 100))
dim1 = (width1, height1)
dim2 = (width2, height2)
img1 = cv2.resize(img1, dim1, interpolation=cv2.INTER_AREA)
img2 = cv2.resize(img2, dim2, interpolation=cv2.INTER_AREA)
h1, w1, ch1 = img1.shape
stride1 = img1.strides[0]
convert_to_Qt_format1 = QtGui.QImage(img1, w1, h1, stride1, QtGui.QImage.Format.Format_BGR888)
qt_img1 = QPixmap.fromImage(convert_to_Qt_format1)
h2, w2, ch2 = img2.shape
stride2 = img2.strides[0]
convert_to_Qt_format2 = QtGui.QImage(img2, w2, h2, stride2, QtGui.QImage.Format.Format_BGR888)
qt_img2 = QPixmap.fromImage(convert_to_Qt_format2)
self.img1.setPixmap(qt_img1)
self.img2.setPixmap(qt_img2)
But, when I remove or comment this img2 resize code:
img1 = cv2.resize(img1, dim1, interpolation=cv2.INTER_AREA)
#img2 = cv2.resize(img2, dim2, interpolation=cv2.INTER_AREA)
This error happens:
TypeError: arguments did not match any overloaded call:
QImage(): too many arguments
QImage(QSize, QImage.Format): argument 1 has unexpected type 'numpy.ndarray'
QImage(int, int, QImage.Format): argument 1 has unexpected type 'numpy.ndarray'
QImage(bytes, int, int, QImage.Format, cleanupFunction: Callable[..., None] = 0, cleanupInfo: object = 0): argument 1 has unexpected type 'numpy.ndarray'
QImage(bytes, int, int, int, QImage.Format, cleanupFunction: Callable[..., None] = 0, cleanupInfo: object = 0): argument 1 has unexpected type 'numpy.ndarray'
QImage(PyQt6.sip.voidptr, int, int, QImage.Format, cleanupFunction: Callable[..., None] = 0, cleanupInfo: object = 0): argument 1 has unexpected type 'numpy.ndarray'
QImage(PyQt6.sip.voidptr, int, int, int, QImage.Format, cleanupFunction: Callable[..., None] = 0, cleanupInfo: object = 0): argument 1 has unexpected type 'numpy.ndarray'
QImage(List[str]): argument 1 has unexpected type 'numpy.ndarray'
QImage(str, format: str = None): argument 1 has unexpected type 'numpy.ndarray'
QImage(QImage): argument 1 has unexpected type 'numpy.ndarray'
QImage(Any): too many arguments
It is weird because img1 has no errors even without resizing. It only happens to img2.