I have the problem that I cannot connect the implementation between two buttons. After I pressed the "Grayscale" button and got the grayscale image, I pressed the "Canny" button but the user interface suddenly closed.
I don't know what's wrong in my code.
def getImage(self):
global fname
fname = QFileDialog.getOpenFileName(self, 'Open file',
'C:\Usersinil-pingDesktopCODE',"Image Files (*.jpg *.gif *.bmp *.png)")
pixmap = QPixmap(fname[0])
self.label.setPixmap(QPixmap(pixmap))
self.resize(pixmap.width(), pixmap.height())
def Grayscale(self):
global edges
edges = cv2.imread(fname[0], 0)
edges = cv2.GaussianBlur(edges, (5, 5), 0)
height, width = edges.shape[:2]
ret,edges = cv2.threshold(edges,150,255,cv2.THRESH_BINARY)
kernel = np.ones((5,5),np.uint8)
edges = cv2.morphologyEx(edges, cv2.MORPH_OPEN, kernel)
edges = cv2.morphologyEx(edges, cv2.MORPH_OPEN, kernel)
edges = QImage(edges, width, height, QImage.Format_Grayscale8)
pixmap = QPixmap.fromImage(edges)
self.label.setPixmap(pixmap)
self.resize(pixmap.width(), pixmap.height())
def Canny(self):
edges2 = cv2.imread(edges[0],-1)
edges2 = cv2.Canny(edges2,180,200)
edges2 = QImage(edges2, width, height, QImage.Format_Grayscale8)
pixmap = QPixmap.fromImage(edges2)
self.label.setPixmap(pixmap)
self.resize(pixmap.width(), pixmap.height())
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…