Trying to display a live video from a webcam and don't know what is wrong with the code

0

Display live video in python. after running the code I get this message:

Process finished with exit code -1073740791 (0xC0000409)

The gui is on display but the camera footage does not show.

What I'm trying to do, is make the footage from the usb camera appear on the gui I've made. I followed all steps from a tutorial I have seen but still can't manage to get it done.

Code:

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

class Appl(QDialog):
    def __init__(self):
        super(Appl, self).__init__()
        loadUi('App.ui', self)

        self.image=None
        self.startButton.clicked.connect(self.start_webcam)
        self.stopButton.clicked.connect(self.stop_webcam)

    def start_webcam(self):
        self.capture = cv2.VideoCapture(0)
        self.capture.set(cv2.CAP_PROP_FRAME_HEIGHT, 210)
        self.capture.set(cv2.CAP_PROP_FRAME_WIDTH, 250)

        self.timer = QTimer(self)
        self.timer.timeout.connect(self.update_frame)
        self.timer.start(5)

    def update_frame(self):
        ret,self.image = self.capture.read()
        self.image = cv2.flip(self.image, 1)
        self.displayImage(self.image, 1)

    def stop_webcam(self):
        self.timer.stop()

    def displayImage(self, img, window=1):
        qformat = QImage.Format_Indexed8
        if len(img.shape) ==3 :
            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:
            self.imgLabel.setPixmap(QPixmap.fromImage(outImage))
            self.imgLabel.setScaledContents(True)

if __name__=='__main__':
    app=QApplication(sys.argv)
    window=Appl()
    window.setWindowTitle('Licenta- C.A')
    window.show()
    sys.exit(app.exec_())
python
pyqt5
asked on Stack Overflow Jan 3, 2019 by Andi Andreea • edited Jan 3, 2019 by martineau

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0