Python 2.7 如何在Qt设计器窗体上加载图像
我正在尝试在Qt Designer窗体上加载图像。我编写的代码在加载后在新窗口中显示精细图像,但当我试图在Qt Designer中设计的窗体上显示相同的图像时,它不会在该窗体上显示图像,也不会给出任何错误。下面是Qt表单及其调用的主类的代码 主文件:Python 2.7 如何在Qt设计器窗体上加载图像,python-2.7,pyqt4,Python 2.7,Pyqt4,我正在尝试在Qt Designer窗体上加载图像。我编写的代码在加载后在新窗口中显示精细图像,但当我试图在Qt Designer中设计的窗体上显示相同的图像时,它不会在该窗体上显示图像,也不会给出任何错误。下面是Qt表单及其调用的主类的代码 主文件: #!/usr/bin/python """ imageProc is an application to do several simple operations in image processing""" from PyQt4 import
#!/usr/bin/python
""" imageProc is an application to do several simple operations in image processing"""
from PyQt4 import QtGui
import sys
#from gui1 import *
import sip
from form import *
from form1 import *
from process import *
class MyForm(QtGui.QMainWindow):
def __init__(self,parent=None):
super(MyForm, self).__init__()
QtGui.QWidget.__init__(self,parent)
self.u=U_Form()
self.u.setupUi(self)
self.imgProc = imagePreProcessor()
self.label = QtGui.QLabel(self)
QtCore.QObject.connect(self.u.pushButton, QtCore.SIGNAL('clicked()'), self.load)
def load(self):
filepath = QtGui.QFileDialog.getOpenFileName(
self, 'Open File', '', 'All Files (*.*);;jpeg (*.jpeg);;jpg (*.jpg);;png (*.png);;ppm (*.ppm)')
filename=filepath.toLocal8Bit().data()
if filepath:
self.open(filepath)
def open(self, filepath):
self.form1= Ui_DiabeticRetinopathy1()
self.form1.setupUi(self)
self.form1.imgPreProc.loadImage(str(filepath))
self.form1.prnt()
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
form=MyForm()
form.show()
app.exec_()
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'form1.ui'
#
# Created: Sat Aug 23 03:10:41 2014
# by: PyQt4 UI code generator 4.11.1
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
from PyQt4.QtGui import *
from PyQt4.QtCore import *
import Image, ImageQt
from process import imagePreProcessor
import sip
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_DiabeticRetinopathy1(QtGui.QMainWindow):
def __init__(self):
super(Ui_DiabeticRetinopathy1, self).__init__()
self.imgPreProc = imagePreProcessor()
#self.rightbottom = QtGui.QWidget(mainWidget)
#self.label = QtGui.QLabel(self)
#self.setupUi(self)
def setupUi(self, DiabeticRetinopathy):
#mainWidget = QtGui.QWidget()
#hbox = QtGui.QVBoxLayout(mainWidget)
#self.grid = QtGui.QGridLayout()
#self.rightbottom = QtGui.QWidget(mainWidget)
#self.label.setLayout(grid)
DiabeticRetinopathy.setObjectName(_fromUtf8("DiabeticRetinopathy"))
DiabeticRetinopathy.resize(640, 480)
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap(_fromUtf8("../im0003.jpg")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
DiabeticRetinopathy.setWindowIcon(icon)
DiabeticRetinopathy.setStyleSheet(_fromUtf8("background-color: rgb(0, 86, 86);"))
self.centralwidget = QtGui.QWidget(DiabeticRetinopathy)
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
self.verticalLayoutWidget = QtGui.QWidget(self.centralwidget)
self.verticalLayoutWidget.setGeometry(QtCore.QRect(850, 80, 181, 131))
self.verticalLayoutWidget.setObjectName(_fromUtf8("verticalLayoutWidget"))
self.verticalLayout = QtGui.QVBoxLayout(self.verticalLayoutWidget)
self.verticalLayout.setMargin(0)
self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
self.pushButton = QtGui.QPushButton(self.verticalLayoutWidget)
self.pushButton.setStyleSheet(_fromUtf8("background-color: rgb(191, 191, 191);\n"
"font: 75 8pt \"Verdana\";"))
self.pushButton.setObjectName(_fromUtf8("pushButton"))
self.verticalLayout.addWidget(self.pushButton)
self.pushButton_2 = QtGui.QPushButton(self.verticalLayoutWidget)
self.pushButton_2.setStyleSheet(_fromUtf8("background-color: rgb(191, 191, 191);\n"
"font: 75 8pt \"Verdana\";"))
self.pushButton_2.setObjectName(_fromUtf8("pushButton_2"))
self.verticalLayout.addWidget(self.pushButton_2)
self.pushButton_3 = QtGui.QPushButton(self.verticalLayoutWidget)
self.pushButton_3.setStyleSheet(_fromUtf8("background-color: rgb(191, 191, 191);\n"
"font: 75 8pt \"Verdana\";"))
self.pushButton_3.setObjectName(_fromUtf8("pushButton_3"))
self.verticalLayout.addWidget(self.pushButton_3)
self.pushButton_4 = QtGui.QPushButton(self.verticalLayoutWidget)
self.pushButton_4.setStyleSheet(_fromUtf8("background-color: rgb(191, 191, 191);\n"
"font: 75 8pt \"Verdana\";"))
self.pushButton_4.setObjectName(_fromUtf8("pushButton_4"))
self.verticalLayout.addWidget(self.pushButton_4)
self.verticalLayoutWidget_2 = QtGui.QWidget(self.centralwidget)
self.verticalLayoutWidget_2.setGeometry(QtCore.QRect(850, 250, 182, 141))
self.verticalLayoutWidget_2.setObjectName(_fromUtf8("verticalLayoutWidget_2"))
self.verticalLayout_2 = QtGui.QVBoxLayout(self.verticalLayoutWidget_2)
self.verticalLayout_2.setMargin(0)
self.verticalLayout_2.setObjectName(_fromUtf8("verticalLayout_2"))
self.pushButton_5 = QtGui.QPushButton(self.verticalLayoutWidget_2)
self.pushButton_5.setStyleSheet(_fromUtf8("background-color: rgb(191, 191, 191);\n"
"font: 75 8pt \"Verdana\";"))
self.pushButton_5.setObjectName(_fromUtf8("pushButton_5"))
self.verticalLayout_2.addWidget(self.pushButton_5)
self.pushButton_6 = QtGui.QPushButton(self.verticalLayoutWidget_2)
self.pushButton_6.setStyleSheet(_fromUtf8("background-color: rgb(191, 191, 191);\n"
"font: 75 8pt \"Verdana\";"))
self.pushButton_6.setObjectName(_fromUtf8("pushButton_6"))
self.verticalLayout_2.addWidget(self.pushButton_6)
self.pushButton_7 = QtGui.QPushButton(self.verticalLayoutWidget_2)
self.pushButton_7.setStyleSheet(_fromUtf8("background-color: rgb(191, 191, 191);\n"
"font: 75 8pt \"Verdana\";"))
self.pushButton_7.setObjectName(_fromUtf8("pushButton_7"))
self.verticalLayout_2.addWidget(self.pushButton_7)
self.pushButton_8 = QtGui.QPushButton(self.verticalLayoutWidget_2)
self.pushButton_8.setStyleSheet(_fromUtf8("background-color: rgb(191, 191, 191);\n"
"font: 75 8pt \"Verdana\";"))
self.pushButton_8.setObjectName(_fromUtf8("pushButton_8"))
self.verticalLayout_2.addWidget(self.pushButton_8)
DiabeticRetinopathy.setCentralWidget(self.centralwidget)
self.statusbar = QtGui.QStatusBar(DiabeticRetinopathy)
self.statusbar.setObjectName(_fromUtf8("statusbar"))
DiabeticRetinopathy.setStatusBar(self.statusbar)
self.retranslateUi(DiabeticRetinopathy)
QtCore.QMetaObject.connectSlotsByName(DiabeticRetinopathy)
def retranslateUi(self, DiabeticRetinopathy):
DiabeticRetinopathy.setWindowTitle(_translate("DiabeticRetinopathy", "Diabetic Retinopathy Detection", None))
self.pushButton.setText(_translate("DiabeticRetinopathy", "Grayscale", None))
self.pushButton_2.setText(_translate("DiabeticRetinopathy", "Zero Padding", None))
self.pushButton_3.setText(_translate("DiabeticRetinopathy", "Normalize", None))
self.pushButton_4.setText(_translate("DiabeticRetinopathy", "Smoothing", None))
self.pushButton_5.setText(_translate("DiabeticRetinopathy", "Detection of Micro-Aneurysms", None))
self.pushButton_6.setText(_translate("DiabeticRetinopathy", "Detection of Hemorrhages", None))
self.pushButton_7.setText(_translate("DiabeticRetinopathy", "Detection of Exudates", None))
self.pushButton_8.setText(_translate("DiabeticRetinopathy", "Grading", None))
def prnt(self):
self.label = QtGui.QLabel(self)
self.label.setPixmap(self.imgPreProc.pixmap)
x, y, w, h = 10, 10, 700, 605
self.label.setGeometry(x, y, w, h)
self.label.resize(w, h)
class imagePreProcessor():
def __init__(self):
self.Qimg = None
self.img = None
self.image=QImage()
def loadImage(self, imgFile):
self.img = cv2.imread(imgFile)
#cv2.imshow('image',self.img)
#def toQimage(self):
if self.img != None:
self.pixmap = QtGui.QPixmap(imgFile)
表单文件:
#!/usr/bin/python
""" imageProc is an application to do several simple operations in image processing"""
from PyQt4 import QtGui
import sys
#from gui1 import *
import sip
from form import *
from form1 import *
from process import *
class MyForm(QtGui.QMainWindow):
def __init__(self,parent=None):
super(MyForm, self).__init__()
QtGui.QWidget.__init__(self,parent)
self.u=U_Form()
self.u.setupUi(self)
self.imgProc = imagePreProcessor()
self.label = QtGui.QLabel(self)
QtCore.QObject.connect(self.u.pushButton, QtCore.SIGNAL('clicked()'), self.load)
def load(self):
filepath = QtGui.QFileDialog.getOpenFileName(
self, 'Open File', '', 'All Files (*.*);;jpeg (*.jpeg);;jpg (*.jpg);;png (*.png);;ppm (*.ppm)')
filename=filepath.toLocal8Bit().data()
if filepath:
self.open(filepath)
def open(self, filepath):
self.form1= Ui_DiabeticRetinopathy1()
self.form1.setupUi(self)
self.form1.imgPreProc.loadImage(str(filepath))
self.form1.prnt()
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
form=MyForm()
form.show()
app.exec_()
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'form1.ui'
#
# Created: Sat Aug 23 03:10:41 2014
# by: PyQt4 UI code generator 4.11.1
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
from PyQt4.QtGui import *
from PyQt4.QtCore import *
import Image, ImageQt
from process import imagePreProcessor
import sip
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_DiabeticRetinopathy1(QtGui.QMainWindow):
def __init__(self):
super(Ui_DiabeticRetinopathy1, self).__init__()
self.imgPreProc = imagePreProcessor()
#self.rightbottom = QtGui.QWidget(mainWidget)
#self.label = QtGui.QLabel(self)
#self.setupUi(self)
def setupUi(self, DiabeticRetinopathy):
#mainWidget = QtGui.QWidget()
#hbox = QtGui.QVBoxLayout(mainWidget)
#self.grid = QtGui.QGridLayout()
#self.rightbottom = QtGui.QWidget(mainWidget)
#self.label.setLayout(grid)
DiabeticRetinopathy.setObjectName(_fromUtf8("DiabeticRetinopathy"))
DiabeticRetinopathy.resize(640, 480)
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap(_fromUtf8("../im0003.jpg")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
DiabeticRetinopathy.setWindowIcon(icon)
DiabeticRetinopathy.setStyleSheet(_fromUtf8("background-color: rgb(0, 86, 86);"))
self.centralwidget = QtGui.QWidget(DiabeticRetinopathy)
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
self.verticalLayoutWidget = QtGui.QWidget(self.centralwidget)
self.verticalLayoutWidget.setGeometry(QtCore.QRect(850, 80, 181, 131))
self.verticalLayoutWidget.setObjectName(_fromUtf8("verticalLayoutWidget"))
self.verticalLayout = QtGui.QVBoxLayout(self.verticalLayoutWidget)
self.verticalLayout.setMargin(0)
self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
self.pushButton = QtGui.QPushButton(self.verticalLayoutWidget)
self.pushButton.setStyleSheet(_fromUtf8("background-color: rgb(191, 191, 191);\n"
"font: 75 8pt \"Verdana\";"))
self.pushButton.setObjectName(_fromUtf8("pushButton"))
self.verticalLayout.addWidget(self.pushButton)
self.pushButton_2 = QtGui.QPushButton(self.verticalLayoutWidget)
self.pushButton_2.setStyleSheet(_fromUtf8("background-color: rgb(191, 191, 191);\n"
"font: 75 8pt \"Verdana\";"))
self.pushButton_2.setObjectName(_fromUtf8("pushButton_2"))
self.verticalLayout.addWidget(self.pushButton_2)
self.pushButton_3 = QtGui.QPushButton(self.verticalLayoutWidget)
self.pushButton_3.setStyleSheet(_fromUtf8("background-color: rgb(191, 191, 191);\n"
"font: 75 8pt \"Verdana\";"))
self.pushButton_3.setObjectName(_fromUtf8("pushButton_3"))
self.verticalLayout.addWidget(self.pushButton_3)
self.pushButton_4 = QtGui.QPushButton(self.verticalLayoutWidget)
self.pushButton_4.setStyleSheet(_fromUtf8("background-color: rgb(191, 191, 191);\n"
"font: 75 8pt \"Verdana\";"))
self.pushButton_4.setObjectName(_fromUtf8("pushButton_4"))
self.verticalLayout.addWidget(self.pushButton_4)
self.verticalLayoutWidget_2 = QtGui.QWidget(self.centralwidget)
self.verticalLayoutWidget_2.setGeometry(QtCore.QRect(850, 250, 182, 141))
self.verticalLayoutWidget_2.setObjectName(_fromUtf8("verticalLayoutWidget_2"))
self.verticalLayout_2 = QtGui.QVBoxLayout(self.verticalLayoutWidget_2)
self.verticalLayout_2.setMargin(0)
self.verticalLayout_2.setObjectName(_fromUtf8("verticalLayout_2"))
self.pushButton_5 = QtGui.QPushButton(self.verticalLayoutWidget_2)
self.pushButton_5.setStyleSheet(_fromUtf8("background-color: rgb(191, 191, 191);\n"
"font: 75 8pt \"Verdana\";"))
self.pushButton_5.setObjectName(_fromUtf8("pushButton_5"))
self.verticalLayout_2.addWidget(self.pushButton_5)
self.pushButton_6 = QtGui.QPushButton(self.verticalLayoutWidget_2)
self.pushButton_6.setStyleSheet(_fromUtf8("background-color: rgb(191, 191, 191);\n"
"font: 75 8pt \"Verdana\";"))
self.pushButton_6.setObjectName(_fromUtf8("pushButton_6"))
self.verticalLayout_2.addWidget(self.pushButton_6)
self.pushButton_7 = QtGui.QPushButton(self.verticalLayoutWidget_2)
self.pushButton_7.setStyleSheet(_fromUtf8("background-color: rgb(191, 191, 191);\n"
"font: 75 8pt \"Verdana\";"))
self.pushButton_7.setObjectName(_fromUtf8("pushButton_7"))
self.verticalLayout_2.addWidget(self.pushButton_7)
self.pushButton_8 = QtGui.QPushButton(self.verticalLayoutWidget_2)
self.pushButton_8.setStyleSheet(_fromUtf8("background-color: rgb(191, 191, 191);\n"
"font: 75 8pt \"Verdana\";"))
self.pushButton_8.setObjectName(_fromUtf8("pushButton_8"))
self.verticalLayout_2.addWidget(self.pushButton_8)
DiabeticRetinopathy.setCentralWidget(self.centralwidget)
self.statusbar = QtGui.QStatusBar(DiabeticRetinopathy)
self.statusbar.setObjectName(_fromUtf8("statusbar"))
DiabeticRetinopathy.setStatusBar(self.statusbar)
self.retranslateUi(DiabeticRetinopathy)
QtCore.QMetaObject.connectSlotsByName(DiabeticRetinopathy)
def retranslateUi(self, DiabeticRetinopathy):
DiabeticRetinopathy.setWindowTitle(_translate("DiabeticRetinopathy", "Diabetic Retinopathy Detection", None))
self.pushButton.setText(_translate("DiabeticRetinopathy", "Grayscale", None))
self.pushButton_2.setText(_translate("DiabeticRetinopathy", "Zero Padding", None))
self.pushButton_3.setText(_translate("DiabeticRetinopathy", "Normalize", None))
self.pushButton_4.setText(_translate("DiabeticRetinopathy", "Smoothing", None))
self.pushButton_5.setText(_translate("DiabeticRetinopathy", "Detection of Micro-Aneurysms", None))
self.pushButton_6.setText(_translate("DiabeticRetinopathy", "Detection of Hemorrhages", None))
self.pushButton_7.setText(_translate("DiabeticRetinopathy", "Detection of Exudates", None))
self.pushButton_8.setText(_translate("DiabeticRetinopathy", "Grading", None))
def prnt(self):
self.label = QtGui.QLabel(self)
self.label.setPixmap(self.imgPreProc.pixmap)
x, y, w, h = 10, 10, 700, 605
self.label.setGeometry(x, y, w, h)
self.label.resize(w, h)
class imagePreProcessor():
def __init__(self):
self.Qimg = None
self.img = None
self.image=QImage()
def loadImage(self, imgFile):
self.img = cv2.imread(imgFile)
#cv2.imshow('image',self.img)
#def toQimage(self):
if self.img != None:
self.pixmap = QtGui.QPixmap(imgFile)
加载图像:
#!/usr/bin/python
""" imageProc is an application to do several simple operations in image processing"""
from PyQt4 import QtGui
import sys
#from gui1 import *
import sip
from form import *
from form1 import *
from process import *
class MyForm(QtGui.QMainWindow):
def __init__(self,parent=None):
super(MyForm, self).__init__()
QtGui.QWidget.__init__(self,parent)
self.u=U_Form()
self.u.setupUi(self)
self.imgProc = imagePreProcessor()
self.label = QtGui.QLabel(self)
QtCore.QObject.connect(self.u.pushButton, QtCore.SIGNAL('clicked()'), self.load)
def load(self):
filepath = QtGui.QFileDialog.getOpenFileName(
self, 'Open File', '', 'All Files (*.*);;jpeg (*.jpeg);;jpg (*.jpg);;png (*.png);;ppm (*.ppm)')
filename=filepath.toLocal8Bit().data()
if filepath:
self.open(filepath)
def open(self, filepath):
self.form1= Ui_DiabeticRetinopathy1()
self.form1.setupUi(self)
self.form1.imgPreProc.loadImage(str(filepath))
self.form1.prnt()
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
form=MyForm()
form.show()
app.exec_()
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'form1.ui'
#
# Created: Sat Aug 23 03:10:41 2014
# by: PyQt4 UI code generator 4.11.1
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
from PyQt4.QtGui import *
from PyQt4.QtCore import *
import Image, ImageQt
from process import imagePreProcessor
import sip
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_DiabeticRetinopathy1(QtGui.QMainWindow):
def __init__(self):
super(Ui_DiabeticRetinopathy1, self).__init__()
self.imgPreProc = imagePreProcessor()
#self.rightbottom = QtGui.QWidget(mainWidget)
#self.label = QtGui.QLabel(self)
#self.setupUi(self)
def setupUi(self, DiabeticRetinopathy):
#mainWidget = QtGui.QWidget()
#hbox = QtGui.QVBoxLayout(mainWidget)
#self.grid = QtGui.QGridLayout()
#self.rightbottom = QtGui.QWidget(mainWidget)
#self.label.setLayout(grid)
DiabeticRetinopathy.setObjectName(_fromUtf8("DiabeticRetinopathy"))
DiabeticRetinopathy.resize(640, 480)
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap(_fromUtf8("../im0003.jpg")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
DiabeticRetinopathy.setWindowIcon(icon)
DiabeticRetinopathy.setStyleSheet(_fromUtf8("background-color: rgb(0, 86, 86);"))
self.centralwidget = QtGui.QWidget(DiabeticRetinopathy)
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
self.verticalLayoutWidget = QtGui.QWidget(self.centralwidget)
self.verticalLayoutWidget.setGeometry(QtCore.QRect(850, 80, 181, 131))
self.verticalLayoutWidget.setObjectName(_fromUtf8("verticalLayoutWidget"))
self.verticalLayout = QtGui.QVBoxLayout(self.verticalLayoutWidget)
self.verticalLayout.setMargin(0)
self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
self.pushButton = QtGui.QPushButton(self.verticalLayoutWidget)
self.pushButton.setStyleSheet(_fromUtf8("background-color: rgb(191, 191, 191);\n"
"font: 75 8pt \"Verdana\";"))
self.pushButton.setObjectName(_fromUtf8("pushButton"))
self.verticalLayout.addWidget(self.pushButton)
self.pushButton_2 = QtGui.QPushButton(self.verticalLayoutWidget)
self.pushButton_2.setStyleSheet(_fromUtf8("background-color: rgb(191, 191, 191);\n"
"font: 75 8pt \"Verdana\";"))
self.pushButton_2.setObjectName(_fromUtf8("pushButton_2"))
self.verticalLayout.addWidget(self.pushButton_2)
self.pushButton_3 = QtGui.QPushButton(self.verticalLayoutWidget)
self.pushButton_3.setStyleSheet(_fromUtf8("background-color: rgb(191, 191, 191);\n"
"font: 75 8pt \"Verdana\";"))
self.pushButton_3.setObjectName(_fromUtf8("pushButton_3"))
self.verticalLayout.addWidget(self.pushButton_3)
self.pushButton_4 = QtGui.QPushButton(self.verticalLayoutWidget)
self.pushButton_4.setStyleSheet(_fromUtf8("background-color: rgb(191, 191, 191);\n"
"font: 75 8pt \"Verdana\";"))
self.pushButton_4.setObjectName(_fromUtf8("pushButton_4"))
self.verticalLayout.addWidget(self.pushButton_4)
self.verticalLayoutWidget_2 = QtGui.QWidget(self.centralwidget)
self.verticalLayoutWidget_2.setGeometry(QtCore.QRect(850, 250, 182, 141))
self.verticalLayoutWidget_2.setObjectName(_fromUtf8("verticalLayoutWidget_2"))
self.verticalLayout_2 = QtGui.QVBoxLayout(self.verticalLayoutWidget_2)
self.verticalLayout_2.setMargin(0)
self.verticalLayout_2.setObjectName(_fromUtf8("verticalLayout_2"))
self.pushButton_5 = QtGui.QPushButton(self.verticalLayoutWidget_2)
self.pushButton_5.setStyleSheet(_fromUtf8("background-color: rgb(191, 191, 191);\n"
"font: 75 8pt \"Verdana\";"))
self.pushButton_5.setObjectName(_fromUtf8("pushButton_5"))
self.verticalLayout_2.addWidget(self.pushButton_5)
self.pushButton_6 = QtGui.QPushButton(self.verticalLayoutWidget_2)
self.pushButton_6.setStyleSheet(_fromUtf8("background-color: rgb(191, 191, 191);\n"
"font: 75 8pt \"Verdana\";"))
self.pushButton_6.setObjectName(_fromUtf8("pushButton_6"))
self.verticalLayout_2.addWidget(self.pushButton_6)
self.pushButton_7 = QtGui.QPushButton(self.verticalLayoutWidget_2)
self.pushButton_7.setStyleSheet(_fromUtf8("background-color: rgb(191, 191, 191);\n"
"font: 75 8pt \"Verdana\";"))
self.pushButton_7.setObjectName(_fromUtf8("pushButton_7"))
self.verticalLayout_2.addWidget(self.pushButton_7)
self.pushButton_8 = QtGui.QPushButton(self.verticalLayoutWidget_2)
self.pushButton_8.setStyleSheet(_fromUtf8("background-color: rgb(191, 191, 191);\n"
"font: 75 8pt \"Verdana\";"))
self.pushButton_8.setObjectName(_fromUtf8("pushButton_8"))
self.verticalLayout_2.addWidget(self.pushButton_8)
DiabeticRetinopathy.setCentralWidget(self.centralwidget)
self.statusbar = QtGui.QStatusBar(DiabeticRetinopathy)
self.statusbar.setObjectName(_fromUtf8("statusbar"))
DiabeticRetinopathy.setStatusBar(self.statusbar)
self.retranslateUi(DiabeticRetinopathy)
QtCore.QMetaObject.connectSlotsByName(DiabeticRetinopathy)
def retranslateUi(self, DiabeticRetinopathy):
DiabeticRetinopathy.setWindowTitle(_translate("DiabeticRetinopathy", "Diabetic Retinopathy Detection", None))
self.pushButton.setText(_translate("DiabeticRetinopathy", "Grayscale", None))
self.pushButton_2.setText(_translate("DiabeticRetinopathy", "Zero Padding", None))
self.pushButton_3.setText(_translate("DiabeticRetinopathy", "Normalize", None))
self.pushButton_4.setText(_translate("DiabeticRetinopathy", "Smoothing", None))
self.pushButton_5.setText(_translate("DiabeticRetinopathy", "Detection of Micro-Aneurysms", None))
self.pushButton_6.setText(_translate("DiabeticRetinopathy", "Detection of Hemorrhages", None))
self.pushButton_7.setText(_translate("DiabeticRetinopathy", "Detection of Exudates", None))
self.pushButton_8.setText(_translate("DiabeticRetinopathy", "Grading", None))
def prnt(self):
self.label = QtGui.QLabel(self)
self.label.setPixmap(self.imgPreProc.pixmap)
x, y, w, h = 10, 10, 700, 605
self.label.setGeometry(x, y, w, h)
self.label.resize(w, h)
class imagePreProcessor():
def __init__(self):
self.Qimg = None
self.img = None
self.image=QImage()
def loadImage(self, imgFile):
self.img = cv2.imread(imgFile)
#cv2.imshow('image',self.img)
#def toQimage(self):
if self.img != None:
self.pixmap = QtGui.QPixmap(imgFile)
问题是您设置的
QLabel
image的父项是错误的。要修复它们,请设置trueparentQWidget
def prnt(self):
self.label = QtGui.QLabel(self.centralwidget)
self.label.setPixmap(self.imgPreProc.pixmap)
x, y, w, h = 10, 10, 700, 605
self.label.setGeometry(x, y, w, h)
self.label.resize(w, h)
…谢谢您的回复,但我正在开发一个应用程序,需要从计算机浏览图像。这似乎只适用于特定图像。我需要使图像路径动态化。你能告诉我怎么做吗?对不起,我弄错了你的问题。请看我上次编辑的答案。