As sadly as Python/PyQt does not give give specific error messages about things like these, I am only getting this error code when running my code.
Process finished with exit code -1073740791 (0xC0000409)
I am using PyQt and OpenCV to build an app that displays a webcam feed.
import sys
import cv2
from PyQt5.QtCore import QTimer
from PyQt5.QtGui import QImage, QPixmap
from PyQt5.QtWidgets import QApplication, QDialog
from PyQt5.uic import loadUi
from qtpy import QtGui
class MainUI(QDialog):
read=0;
def __init__(self):
super(MainUI,self).__init__()
loadUi('MainUI.ui',self)
self.image=None
self.btnPlay.clicked.connect(self.start_webcam)
self.btnStop.clicked.connect(self.stop_webcam)
def start_webcam(self):
self.capture=cv2.VideoCapture(0)
self.capture.set(cv2.CAP_PROP_FRAME_HEIGHT,480)
self.capture.set(cv2.CAP_PROP_FRAME_WIDTH,640)
self.timer=QTimer(self)
self.timer.timeout.connect(self.update_frame())
self.timer.start(5)
def stop_webcam(self):
self.timer.stop()
def update_frame(self):
#Take image from video feed
ret,self.image = self.capture.read()
self.image=cv2.flip(self.image,1)
self.displayImage(self.image,1)
def displayImage(self,img,window=1):
qformat=QImage.Format_Indexed8
if(len(img.shape)==3): #[0]rows,[1]=cols,[2]=channels
if img.shape[2]==4 :
qformat=QImage.Format_RGBA8888
else:
qformat=QImage.Format_RGB888
outImage=QImage(img,img.shape[1],img.shape[0],img.strides[0],qformat)
#BGR>>RGB
outImage = outImage.rgbSwapped()
if window==1:
#Problem occurs here V
self.imgLabel.setPixmap(QPixmap.fromImage(outImage))
self.imgLabel.setScaledContents(True)
if __name__=='__main__':
app=QApplication(sys.argv)
window = MainUI()
window.setWindowTitle('PYQt Webcam feed')
window.show()
sys.exit(app.exec_())
I've tried using a different approach to this, and I've done my research but I really don't understand what I'm doing wrong. :(
I am studying this code from:
OpenCV Python GUI Development Tutorial 10: Display WebCam Video Feed on QLabel
https://www.youtube.com/watch?v=MUpC6z32bCA&feature=youtu.be&t=3m30s
Any help would be much appreciated. Thank you!