How to Run Multiple Cameras live in a single window using Python PYQT Desktop?

Here is my code, It's Flashing When I runs it bur working both cameras, Also It is a Very difficult for me to put the camera display correctly one camera on left and other on right but tried a lot to do so. Actually I am a Beginner right now. It a Python Code in PYQT5 with OpenCV(Python) in it. I am going to use it on Raspberry.

    import sys
    from PyQt5.QtGui import *
    from PyQt5.QtWidgets import *
    from PyQt5.QtCore import *
    import cv2
    from PyQt5 import QtCore, QtGui, QtWidgets

    class MainWindow(QWidget):
        def __init__(self):
            super(MainWindow, self).__init__()
            self.VBL = QVBoxLayout()
            self.showMaximized()
            self.FeedLabel = QLabel()
            self.VBL.addWidget(self.FeedLabel)
            self.setGeometry(0, 0, 1920, 1000)


            self.VBL1 = QVBoxLayout()
            # self.showMaximized()
            # self.FeedLabel = QLabel()
            # self.VBL1.addWidget(self.FeedLabel)
            self.VBL1.setGeometry(QtCore.QRect(0, 0, 900, 1000))
            self.setLayout(self.VBL)

            self.VBL2 = QVBoxLayout()
            # self.showMaximized()
            # self.FeedLabel = QLabel()
            # self.VBL2.addWidget(self.FeedLabel)
            self.setGeometry(QtCore.QRect(QPoint(100, 200), QSize(11, 16)))

            # self.setGeometry()
            self.setLayout(self.VBL)


            # self.CancelBTN = QPushButton(Cancel)
            # self.CancelBTN.clicked.connect(self.CancelFeed)
            # self.VBL.addWidget(self.CancelBTN)

            # self.frame = QtWidgets.QFrame(self)
            # self.frame.setGeometry(QtCore.QRect(1, 1, 200, 200))
            # self.frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
            # self.frame.setFrameShadow(QtWidgets.QFrame.Raised)

            self.Worker1 = Worker1()
            self.Worker1.start()
            self.Worker1.ImageUpdate1.connect(self.ImageUpdateSlot1)
            self.setLayout(self.VBL1)

            self.Worker2 = Worker2()
            self.Worker2.start()


            self.Worker2.ImageUpdate.connect(self.ImageUpdateSlot)

            self.setLayout(self.VBL2)

        def ImageUpdateSlot(self, Image):
            self.FeedLabel.setPixmap(QPixmap.fromImage(Image))

        def ImageUpdateSlot1(self, Image):
            self.FeedLabel.setPixmap(QPixmap.fromImage(Image))

        def CancelFeed(self):
            self.Worker1.stop()


    class Worker1(QThread):
        ImageUpdate1 = pyqtSignal(QImage)

        def run(self):
            self.ThreadActive = True

            Capture = cv2.VideoCapture(0)
            while self.ThreadActive:
                ret, frame = Capture.read()
                if ret:
                    Image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
                    FlippedImage = cv2.flip(Image, 1)
                    ConvertToQtFormat = QImage(FlippedImage.data, FlippedImage.shape[1], FlippedImage.shape[0], QImage.Format_RGB888)
                    Pic = ConvertToQtFormat.scaled(960, 1080)
                    self.ImageUpdate1.emit(Pic)

        def stop(self):
            self.ThreadActive = False
            self.quit()


    class Worker2(QThread):
        ImageUpdate = pyqtSignal(QImage)

        def run(self):
            self.ThreadActive = True

            Capture = cv2.VideoCapture(1)
            while self.ThreadActive:
                ret, frame = Capture.read()
                if ret:
                    Image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
                    FlippedImage = cv2.flip(Image, 1)
                    ConvertToQtFormat = QImage(FlippedImage.data, FlippedImage.shape[1], FlippedImage.shape[0], QImage.Format_RGB888)

                    Pic = ConvertToQtFormat.scaled(400, 800)
                    self.ImageUpdate.emit(Pic)

        def stop(self):
            self.ThreadActive = False
            self.quit()


    if __name__ == "__main__":
        App = QApplication(sys.argv)
        Root = MainWindow()
        Root.show()
        sys.exit(App.exec())
How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum