I am new to pyqt5 when I am doing a program to develop a camera software, A click button is given to capture an image. when I press enter it clicks an image and saved in disk suddenly the window is closing with exit code
Process finished with exit code -1073740791 (0xC0000409) The code is given below
import sys
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
import cv2
cam = cv2.VideoCapture(0)
class camera(QWidget):
def __init__(self):
super().__init__()
self.camtitle = 'Camera'
self.camleft = 0
self.camtop = 0
self.camwidth = 640
self.camheight = 480
self.camera_button = QPushButton("camera_click", self)
self.camera_button.move(50, 50)
self.cameraUI()
def cameraUI(self):
self.setWindowTitle(self.camtitle)
self.setGeometry(self.camleft, self.camtop, self.camwidth, self.camheight)
self.setWindowIcon(QIcon('Logo.png'))
self.label = QLabel(self)
self.label.move(100, 100)
self.camerawindow()
def camerawindow(self):
# cam = cv2.VideoCapture(0)
while (True):
ret, frame = cam.read()
rgbImage = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
convertToQtFormat = QImage(rgbImage.data, rgbImage.shape[1], rgbImage.shape[0],
QImage.Format_RGB888)
convertToQtFormat = QPixmap.fromImage(convertToQtFormat)
pixmap = QPixmap(convertToQtFormat)
self.resizeImage = pixmap.scaled(300, 400, Qt.KeepAspectRatio)
self.label.setPixmap(self.resizeImage)
self.camera_button.clicked.connect(self.click_picture)
QApplication.processEvents()
self.show()
def click_picture(self): # click picture and close
img_counter = 0
while(True):
ret, frame = cam.read()
img_name = "opencv_frame_{}.png".format(img_counter)
cv2.imwrite(img_name, frame)
printret, frame = cam.read()("{} writtern ".format(img_counter))
print(printret)
img_counter += 1
if __name__ == '__main__':
app1 = QApplication(sys.argv)
ex2 = camera()
ex2.show()
sys.exit(app1.exec_())
Any suggestion is appreciated Thank you!