将cv类型的图片转换为Qpixmap显示在Qlabel上出现扭曲的问题,如图所示:
此处代码为:
img = QImage(img.data, img.shape[1], img.shape[0],QImage.Format.Format_BGR888) pixmap = QPixmap.fromImage(img) self.__ui.label_blueImage.setPixmap(pixmap)
问题解决
上述代码中
showImage = QImage(img.data, img.shape[1], img.shape[0],QImage.Format_RGB888)
参数不完全导致错误,应该更正为:
img = QImage(img.data, img.shape[1], img.shape[0], img.shape[1] * 3,QImage.Format.Format_BGR888)
或者重新规划大小,叫字节对齐。
height = img.shape[0] width = img.shape[1] img = cv.resize(img, (int(width / 4) * 4, int(height / 4) * 4)) img = QImage(img.data, img.shape[1], img.shape[0], QImage.Format.Format_BGR888) pixmap = QPixmap.fromImage(img)



