参考 Stack Overflow ,成功解决。
QString sss = "path";
cv::Mat img = cv::imread(sss.toStdString());
cv::cvtColor(img,img,CV_BGR2RGB);//in your code cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
QImage image1((uchar*)img.data,img.cols,img.rows,QImage::Format_RGB888);
//in your code QtGui.QImage(image.data, width, height, QtGui.QImage.Format_RGB888)
//same problem
QPixmap px1(QPixmap::fromImage(image1));
ui->label_2->setPixmap(px1);
替换成:
//...
QImage image1((uchar*)img.data,img.cols,img.rows,img.step,QImage::Format_RGB888);
//...
image = cv2.imread(str(file_path))
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
height, width = image.shape[:2]
self.scene.clear()
self.frame = QtGui.QImage(image.data, width, height, QtGui.QImage.Format_RGB888)
self.scene.addPixmap(QtGui.QPixmap.fromImage(self.frame))
self.scene.update()
self.graphicsView.setScene(self.scene)
替换成:
//...
widthStep = width * 3
self.frame = QtGui.QImage(image.data, width, height, widthStep, QtGui.QImage.Format_RGB888)
//...