I return an image from function (find_defects)
. and I see that it is a valid image.
I check image before return
using cv2.imshow
and it is also like i expected. But when i try to show this image on a GUI which i designed using PyQt, i see this error:
Process finished with exit code 1
EDIT: Minimum reproducible example:
from PyQt5.QtCore import *
import cv2
from PyQt5.QtWidgets import QLabel, QWidget, QPushButton, QVBoxLayout, QApplication
from PyQt5.QtGui import QPixmap, QImage
class first_GUI(QWidget):
def __init__(self):
# super(first_GUI, self).__init__()
# super().__init__()
QWidget.__init__(self)
self.frame_defects = cv2.imread('output.jpg')
self.label_text = QLabel("Hi")
self.label_text.setAlignment(Qt.AlignCenter)
self.label_text.setStyleSheet("color: rgb(0,0,255);font-weight: bold; font-size: 16pt")
pushButton_show = QPushButton("Show")
pushButton_show.setMinimumHeight(40)
pushButton_show.setStyleSheet("font-weight: bold; font-size: 16pt")
pushButton_show.clicked.connect(self.show_image)
vertical_layout = QVBoxLayout()
vertical_layout.addWidget(self.label_text)
vertical_layout.addWidget(pushButton_show)
self.setLayout(vertical_layout)
self.setWindowTitle("PyQt5 first GUI")
self.resize(400, 300)
def show_image(self):
if self.frame_defects is not None:
image = QImage(self.frame_defects, self.frame_defects.shape[1], self.frame_defects.shape[0],
QImage.Format_RGB888) # The image is stored using a 24-bit RGB format (8-8-8).
self.pixmap2 = QPixmap.fromImage(image)
self.label.setPixmap(self.pixmap2)
app = QApplication([])
widget = first_GUI()
widget.show()
app.exec_()
image: