Pyqt4 +opencv在Qlabel中显示图片

self.imgName = QFileDialog.getOpenFileName(None, “open image”, “/home/lvnianzu/图片”,“All Files();;.tif;;*.gif”) ##打开文件夹对话框,选取文件,并获得文件路径
self.imgName = unicode(self.imgName)
self.patient_img = np.asarray(Image.open(self.imgName)) ##不开辟一段新的内存来保存数据,array则会新开辟一段新的内存
self.patient_img = cv.resize(self.patient_img, (560, 560))
showImage = QtGui.QImage(self.patient_img.data, self.patient_img.shape[1], self.patient_img.shape[0],QtGui.QImage.Format_RGB888)
self.label.height(),QtGui.QImage.Format_RGB888)
self.label.setPixmap(QtGui.QPixmap.fromImage(showImage))
self.label.setScaledContents(True) #设置图片填充完整个label

发布了36 篇原创文章 · 获赞 1 · 访问量 6384

猜你喜欢

转载自blog.csdn.net/qq_34291583/article/details/90646756