I am importing my GUI script and running it with an extended class. When on of the check boxes are clicked I want it to run the function imageChange. I have tried a lot of methods to do this but all the methods crash my python kernel without output an error.
Below is my running code, focused on the checkbox checkBox_BL
from MSCVgui_script import Ui_MainWindow
from PyQt5 import QtCore, QtGui, QtWidgets
import sys
import glob
import cv2
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QInputDialog, QLineEdit, QFileDialog
from PyQt5.QtGui import QIcon
class Main(QtWidgets.QMainWindow, Ui_MainWindow):
#List of image types
image_Types=["photo_NIR", "photo_UV", "photo_Unfiltered", "photo_Polarized","photo_DarkRed","photo_LightRed","photo_Orange","photo_LightGreen","photo_Cyan","photo_Blue"]
#first stack of images
imageFiles1 = {}
#images to process
images_to_process=[]
def __init__(self):
QtWidgets.QMainWindow.__init__(self)
self.setupUi(self)
self.setupInputs()
def setupInputs(self):
self.File01.clicked.connect(self.openFolder)
self.checkBox_BL.stateChanged.connect(self.imageChange)
#self.checkBox_UV.clicked.connect(self.image1Change()
#self.checkBox_NIR.clicked.toggle.onnect(self.image1Change(0))
def openFileNameDialog(self):
options = QFileDialog.Options()
options |= QFileDialog.DontUseNativeDialog
fileName = QFileDialog.getExistingDirectory()
if fileName:
print("file")
print(fileName)
return fileName
self.close
#open folder and import images into code
def assingPics(self,folder):
path = folder+"/*.jpg"
print("AssingPics",path)
image_files = glob.glob(path)
print("imageFiles",image_files)
for filepath in image_files:
print("PATH")
print(filepath)
for i in self.image_Types:
if(i in filepath):
print(filepath)
im = cv2.imread(filepath,0)
self.imageFiles1[i] = im
break
print("done")
#open the folder containing the images to build a stack from
def openFolder(self):
folderName = self.openFileNameDialog()
imgFiles = self.assingPics(folderName)
return imgFiles
#change image 1 according to check box
def imageChange(self,state):
print("CHANGE")
if(self.checkBox_BL.isChecked()):
print("start")
imag = self.imageFiles1['photo_Blue']
imag = QtGui.QImage(imag.data, imag.shape[1], imag.shape[0], QtGui.QImage.Format_RGB888).rgbSwapped()
if(self.checkBox_CY.isChecked()):
print("dumb")
if(self.checkBox_DR.isChecked()):
print("dumb")
if(self.checkBox_LG.isChecked()):
print("dumb")
if(self.checkBox_LP.isChecked()):
print("dumb")
if(self.checkBox_LR.isChecked()):
print("dumb")
if(self.checkBox_NIR.isChecked()):
print("dumb")
if(self.checkBox_OR.isChecked()):
print("dumb")
if(self.checkBox_UF.isChecked()):
print("dumb")
if(self.checkBox_UV.isChecked()):
print("dumb")
if __name__ == "__main__":
sys._excepthook = sys.excepthook
def exception_hook(exctype, value, traceback):
print(exctype, value, traceback)
sys._excepthook(exctype, value, traceback)
sys.exit(1)
sys.excepthook = exception_hook
# from multiprocessing import freeze_support
# freeze_support()
app = QtWidgets.QApplication(sys.argv)
window = Main()
# icon = QtGui.QIcon()
# icon.addPixmap(QtGui.QPixmap("exe/xrt.ico"),QtGui.QIcon.Normal, QtGui.QIcon.Off)
# window.setWindowIcon(icon)
window.show()
sys.exit(app.exec_())
Any suggestions on where my error might be?
Below is the GUI script
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(1640, 900)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.File01 = QtWidgets.QPushButton(self.centralwidget)
self.File01.setGeometry(QtCore.QRect(20, 5, 200, 40))
self.File01.setObjectName("File01")
self.Image01 = QtWidgets.QLabel(self.centralwidget)
self.Image01.setGeometry(QtCore.QRect(30, 85, 1000, 300))
self.Image01.setObjectName("Image01")
self.checkBox_UV = QtWidgets.QCheckBox(self.centralwidget)
self.checkBox_UV.setGeometry(QtCore.QRect(100, 45, 87, 20))
self.checkBox_UV.setObjectName("checkBox_UV")
self.checkBox_NIR = QtWidgets.QCheckBox(self.centralwidget)
self.checkBox_NIR.setGeometry(QtCore.QRect(300, 45, 87, 20))
self.checkBox_NIR.setObjectName("checkBox_NIR")
self.checkBox_DR = QtWidgets.QCheckBox(self.centralwidget)
self.checkBox_DR.setGeometry(QtCore.QRect(500, 45, 87, 20))
self.checkBox_DR.setObjectName("checkBox_DR")
self.checkBox_LR = QtWidgets.QCheckBox(self.centralwidget)
self.checkBox_LR.setGeometry(QtCore.QRect(700, 45, 87, 20))
self.checkBox_LR.setObjectName("checkBox_LR")
self.checkBox_OR = QtWidgets.QCheckBox(self.centralwidget)
self.checkBox_OR.setGeometry(QtCore.QRect(900, 45, 87, 20))
self.checkBox_OR.setObjectName("checkBox_OR")
self.checkBox_LG = QtWidgets.QCheckBox(self.centralwidget)
self.checkBox_LG.setGeometry(QtCore.QRect(100, 405, 97, 20))
self.checkBox_LG.setObjectName("checkBox_LG")
self.checkBox_CY = QtWidgets.QCheckBox(self.centralwidget)
self.checkBox_CY.setGeometry(QtCore.QRect(300, 405, 87, 20))
self.checkBox_CY.setObjectName("checkBox_CY")
self.checkBox_BL = QtWidgets.QCheckBox(self.centralwidget)
self.checkBox_BL.setGeometry(QtCore.QRect(500, 405, 87, 20))
self.checkBox_BL.setObjectName("checkBox_BL")
self.checkBox_LP = QtWidgets.QCheckBox(self.centralwidget)
self.checkBox_LP.setGeometry(QtCore.QRect(700, 405, 87, 20))
self.checkBox_LP.setObjectName("checkBox_LP")
self.checkBox_UF = QtWidgets.QCheckBox(self.centralwidget)
self.checkBox_UF.setGeometry(QtCore.QRect(900, 405, 87, 20))
self.checkBox_UF.setObjectName("checkBox_UF")
self.File02 = QtWidgets.QPushButton(self.centralwidget)
self.File02.setGeometry(QtCore.QRect(20, 440, 200, 40))
self.File02.setObjectName("File02")
self.Image02 = QtWidgets.QLabel(self.centralwidget)
self.Image02.setGeometry(QtCore.QRect(30, 515, 1000, 300))
self.Image02.setObjectName("Image02")
self.checkBox_UV2 = QtWidgets.QCheckBox(self.centralwidget)
self.checkBox_UV2.setGeometry(QtCore.QRect(100, 480, 87, 20))
self.checkBox_UV2.setObjectName("checkBox_UV2")
self.checkBox_NIR2 = QtWidgets.QCheckBox(self.centralwidget)
self.checkBox_NIR2.setGeometry(QtCore.QRect(300, 480, 87, 20))
self.checkBox_NIR2.setObjectName("checkBox_NIR2")
self.checkBox_DR2 = QtWidgets.QCheckBox(self.centralwidget)
self.checkBox_DR2.setGeometry(QtCore.QRect(500, 480, 87, 20))
self.checkBox_DR2.setObjectName("checkBox_DR2")
self.checkBox_LR2 = QtWidgets.QCheckBox(self.centralwidget)
self.checkBox_LR2.setGeometry(QtCore.QRect(700, 480, 87, 20))
self.checkBox_LR2.setObjectName("checkBox_LR2")
self.checkBox_OR2 = QtWidgets.QCheckBox(self.centralwidget)
self.checkBox_OR2.setGeometry(QtCore.QRect(900, 480, 87, 20))
self.checkBox_OR2.setObjectName("checkBox_OR2")
self.checkBox_LG2 = QtWidgets.QCheckBox(self.centralwidget)
self.checkBox_LG2.setGeometry(QtCore.QRect(90, 830, 97, 20))
self.checkBox_LG2.setObjectName("checkBox_LG2")
self.checkBox_CY2 = QtWidgets.QCheckBox(self.centralwidget)
self.checkBox_CY2.setGeometry(QtCore.QRect(300, 830, 87, 20))
self.checkBox_CY2.setObjectName("checkBox_CY2")
self.checkBox_BL2 = QtWidgets.QCheckBox(self.centralwidget)
self.checkBox_BL2.setGeometry(QtCore.QRect(500, 830, 87, 20))
self.checkBox_BL2.setObjectName("checkBox_BL2")
self.checkBox_LP2 = QtWidgets.QCheckBox(self.centralwidget)
self.checkBox_LP2.setGeometry(QtCore.QRect(700, 830, 87, 20))
self.checkBox_LP2.setObjectName("checkBox_LP2")
self.checkBox_UF2 = QtWidgets.QCheckBox(self.centralwidget)
self.checkBox_UF2.setGeometry(QtCore.QRect(900, 830, 87, 20))
self.checkBox_UF2.setObjectName("checkBox_UF2")
self.line_vert = QtWidgets.QFrame(self.centralwidget)
self.line_vert.setGeometry(QtCore.QRect(1050, 30, 20, 801))
self.line_vert.setFrameShape(QtWidgets.QFrame.VLine)
self.line_vert.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line_vert.setObjectName("line_vert")
self.ImageAnalysisHeading = QtWidgets.QLabel(self.centralwidget)
self.ImageAnalysisHeading.setGeometry(QtCore.QRect(1190, 20, 329, 22))
font = QtGui.QFont()
font.setPointSize(18)
self.ImageAnalysisHeading.setFont(font)
self.ImageAnalysisHeading.setObjectName("ImageAnalysisHeading")
self.radioButton_ImageDif = QtWidgets.QRadioButton(self.centralwidget)
self.radioButton_ImageDif.setGeometry(QtCore.QRect(1090, 670, 141, 20))
self.radioButton_ImageDif.setObjectName("radioButton_ImageDif")
self.radioButton_Otsu = QtWidgets.QRadioButton(self.centralwidget)
self.radioButton_Otsu.setGeometry(QtCore.QRect(1090, 120, 211, 20))
self.radioButton_Otsu.setObjectName("radioButton_Otsu")
self.label_EdgeDetHeading = QtWidgets.QLabel(self.centralwidget)
self.label_EdgeDetHeading.setGeometry(QtCore.QRect(1090, 180, 111, 16))
self.label_EdgeDetHeading.setObjectName("label_EdgeDetHeading")
self.radioButton_Canny = QtWidgets.QRadioButton(self.centralwidget)
self.radioButton_Canny.setGeometry(QtCore.QRect(1090, 220, 161, 20))
self.radioButton_Canny.setObjectName("radioButton_Canny")
self.radioButton_laplacian = QtWidgets.QRadioButton(self.centralwidget)
self.radioButton_laplacian.setGeometry(QtCore.QRect(1320, 220, 100, 20))
self.radioButton_laplacian.setObjectName("radioButton_laplacian")
self.radioButton_sobelx = QtWidgets.QRadioButton(self.centralwidget)
self.radioButton_sobelx.setGeometry(QtCore.QRect(1090, 260, 100, 20))
self.radioButton_sobelx.setObjectName("radioButton_sobelx")
self.radioButton_sobely = QtWidgets.QRadioButton(self.centralwidget)
self.radioButton_sobely.setGeometry(QtCore.QRect(1320, 260, 100, 20))
self.radioButton_sobely.setObjectName("radioButton_sobely")
self.radioButton_XRcustum = QtWidgets.QRadioButton(self.centralwidget)
self.radioButton_XRcustum.setGeometry(QtCore.QRect(1090, 630, 100, 20))
self.radioButton_XRcustum.setObjectName("radioButton_XRcustum")
self.radioButton_plotH = QtWidgets.QRadioButton(self.centralwidget)
self.radioButton_plotH.setGeometry(QtCore.QRect(1090, 710, 121, 20))
self.radioButton_plotH.setObjectName("radioButton_plotH")
self.radioButton_CLAHE = QtWidgets.QRadioButton(self.centralwidget)
self.radioButton_CLAHE.setGeometry(QtCore.QRect(1530, 320, 100, 20))
self.radioButton_CLAHE.setObjectName("radioButton_CLAHE")
self.radioButton_Watershed = QtWidgets.QRadioButton(self.centralwidget)
self.radioButton_Watershed.setGeometry(QtCore.QRect(1090, 320, 221, 20))
self.radioButton_Watershed.setObjectName("radioButton_Watershed")
self.radioButton_contours = QtWidgets.QRadioButton(self.centralwidget)
self.radioButton_contours.setGeometry(QtCore.QRect(1320, 320, 100, 20))
self.radioButton_contours.setObjectName("radioButton_contours")
self.label_MorphHeading = QtWidgets.QLabel(self.centralwidget)
self.label_MorphHeading.setGeometry(QtCore.QRect(1090, 380, 191, 16))
self.label_MorphHeading.setObjectName("label_MorphHeading")
self.radioButton_erosion = QtWidgets.QRadioButton(self.centralwidget)
self.radioButton_erosion.setGeometry(QtCore.QRect(1090, 410, 100, 20))
self.radioButton_erosion.setObjectName("radioButton_erosion")
self.radioButton_dilation = QtWidgets.QRadioButton(self.centralwidget)
self.radioButton_dilation.setGeometry(QtCore.QRect(1320, 410, 100, 20))
self.radioButton_dilation.setObjectName("radioButton_dilation")
self.radioButton_closing = QtWidgets.QRadioButton(self.centralwidget)
self.radioButton_closing.setGeometry(QtCore.QRect(1530, 410, 100, 20))
self.radioButton_closing.setObjectName("radioButton_closing")
self.radioButton_opening = QtWidgets.QRadioButton(self.centralwidget)
self.radioButton_opening.setGeometry(QtCore.QRect(1090, 450, 100, 20))
self.radioButton_opening.setObjectName("radioButton_opening")
self.radioButton_morphgradient = QtWidgets.QRadioButton(self.centralwidget)
self.radioButton_morphgradient.setGeometry(QtCore.QRect(1320, 450, 171, 20))
self.radioButton_morphgradient.setObjectName("radioButton_morphgradient")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(1200, 760, 291, 61))
font = QtGui.QFont()
font.setPointSize(18)
self.pushButton.setFont(font)
self.pushButton.setObjectName("pushButton")
self.line = QtWidgets.QFrame(self.centralwidget)
self.line.setGeometry(QtCore.QRect(27, 425, 1001, 20))
self.line.setFrameShape(QtWidgets.QFrame.HLine)
self.line.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line.setObjectName("line")
self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_2.setGeometry(QtCore.QRect(1200, 510, 291, 61))
font = QtGui.QFont()
font.setPointSize(18)
self.pushButton_2.setFont(font)
self.pushButton_2.setObjectName("pushButton_2")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(1090, 80, 131, 16))
font = QtGui.QFont()
font.setPointSize(14)
self.label.setFont(font)
self.label.setObjectName("label")
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(1090, 590, 131, 16))
font = QtGui.QFont()
font.setPointSize(14)
self.label_2.setFont(font)
self.label_2.setObjectName("label_2")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 1640, 22))
self.menubar.setObjectName("menubar")
self.menuMulti_Spectrum_Computer_Vision = QtWidgets.QMenu(self.menubar)
font = QtGui.QFont()
font.setPointSize(18)
self.menuMulti_Spectrum_Computer_Vision.setFont(font)
self.menuMulti_Spectrum_Computer_Vision.setObjectName("menuMulti_Spectrum_Computer_Vision")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.menubar.addAction(self.menuMulti_Spectrum_Computer_Vision.menuAction())
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.File01.setText(_translate("MainWindow", "Browse File (Image 1)"))
self.Image01.setText(_translate("MainWindow", "Image01"))
self.checkBox_UV.setText(_translate("MainWindow", "UV"))
self.checkBox_NIR.setText(_translate("MainWindow", "NIR"))
self.checkBox_DR.setText(_translate("MainWindow", "Dark Red"))
self.checkBox_LR.setText(_translate("MainWindow", "Light Red"))
self.checkBox_OR.setText(_translate("MainWindow", "Orange"))
self.checkBox_LG.setText(_translate("MainWindow", "Light Green"))
self.checkBox_CY.setText(_translate("MainWindow", "Cyan"))
self.checkBox_BL.setText(_translate("MainWindow", "Blue"))
self.checkBox_LP.setText(_translate("MainWindow", "Polarized"))
self.checkBox_UF.setText(_translate("MainWindow", "Unfiltered"))
self.File02.setText(_translate("MainWindow", "Browse File (Image 2)"))
self.Image02.setText(_translate("MainWindow", "Image02"))
self.checkBox_UV2.setText(_translate("MainWindow", "UV"))
self.checkBox_NIR2.setText(_translate("MainWindow", "NIR"))
self.checkBox_DR2.setText(_translate("MainWindow", "Dark Red"))
self.checkBox_LR2.setText(_translate("MainWindow", "Light Red"))
self.checkBox_OR2.setText(_translate("MainWindow", "Orange"))
self.checkBox_LG2.setText(_translate("MainWindow", "Light Green"))
self.checkBox_CY2.setText(_translate("MainWindow", "Cyan"))
self.checkBox_BL2.setText(_translate("MainWindow", "Blue"))
self.checkBox_LP2.setText(_translate("MainWindow", "Polarized"))
self.checkBox_UF2.setText(_translate("MainWindow", "Unfiltered"))
self.ImageAnalysisHeading.setText(_translate("MainWindow", "SELECT IMAGE ANALYSIS TO PERFORM"))
self.radioButton_ImageDif.setText(_translate("MainWindow", "Image Difference"))
self.radioButton_Otsu.setText(_translate("MainWindow", "Binarization (Otsu Threshold)"))
self.label_EdgeDetHeading.setText(_translate("MainWindow", "Edge Detection"))
self.radioButton_Canny.setText(_translate("MainWindow", "Canny Edge Detection"))
self.radioButton_laplacian.setText(_translate("MainWindow", "Laplacian"))
self.radioButton_sobelx.setText(_translate("MainWindow", "Sobel X"))
self.radioButton_sobely.setText(_translate("MainWindow", "Sobel Y"))
self.radioButton_XRcustum.setText(_translate("MainWindow", "XR Custom"))
self.radioButton_plotH.setText(_translate("MainWindow", "Plot Histogram"))
self.radioButton_CLAHE.setText(_translate("MainWindow", "CLAHE"))
self.radioButton_Watershed.setText(_translate("MainWindow", "Watershed Image Segmentation"))
self.radioButton_contours.setText(_translate("MainWindow", "Contours"))
self.label_MorphHeading.setText(_translate("MainWindow", "Morphological Transformations"))
self.radioButton_erosion.setText(_translate("MainWindow", "Erosion"))
self.radioButton_dilation.setText(_translate("MainWindow", "Dilation"))
self.radioButton_closing.setText(_translate("MainWindow", "Closing"))
self.radioButton_opening.setText(_translate("MainWindow", "Opening"))
self.radioButton_morphgradient.setText(_translate("MainWindow", "Morphological Gradient"))
self.pushButton.setText(_translate("MainWindow", "RUN & SAVE"))
self.pushButton_2.setText(_translate("MainWindow", "SAVE OUTPUT"))
self.label.setText(_translate("MainWindow", "PREPROCESSING"))
self.label_2.setText(_translate("MainWindow", "IMAGE ANALYSIS"))
self.menuMulti_Spectrum_Computer_Vision.setTitle(_translate("MainWindow", "Multi-Spectrum Computer Vision"))
Aucun commentaire:
Enregistrer un commentaire