I have a data collection software that requires camera feeds from two different camera sources one is a Brio webcam & the other one is an IP webcam connected via USB tethering. Now when I edited the code for streaming two multiple videos it was showing just one & not from the other. The code is given below:
import sys
import cv2
#from gsp import GstreamerPlayer
import datetime
from pyfirmata import util, Arduino
from PyQt5 import QtCore, QtGui
import openpyxl
from openpyxl import load_workbook
from PyQt5.QtCore import pyqtSlot, QThread, pyqtSignal
from PyQt5.QtGui import QImage, QPixmap
from PyQt5.QtWidgets import QLayout, QDialog, QApplication, QMainWindow, QFileDialog, QPushButton, QWidget, QLabel
from PyQt5.uic import loadUi
import xlrd
from xlutils.copy import copy
import serial
import xlsxwriter
from xlwt import Workbook
sys.setrecursionlimit(15000)
# For the camera feed
class Thread(QThread):
changePixmap = pyqtSignal(QImage)
def run(self):
cap = cv2.VideoCapture(0)
while True:
ret, frame = cap.read()
if ret:
rgbImage = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
convertToQtFormat = QImage(rgbImage.data, rgbImage.shape[1], rgbImage.shape[0], QImage.Format_RGB888)
p = convertToQtFormat.scaled(256, 181)
self.changePixmap.emit(p)
class Thread1(QThread):
changePixmap = pyqtSignal(QImage)
def run(self):
cap = cv2.VideoCapture('http://192.168.42.129:8080/video')
while True:
ret, frame = cap.read()
if ret:
rgbImage = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
convertToQtFormat = QImage(
rgbImage.data, rgbImage.shape[1], rgbImage.shape[0], QImage.Format_RGB888)
p1 = convertToQtFormat.scaled(111, 181)
self.changePixmap.emit(p1)
The calling functions in the main are as follows:
@pyqtSlot(QImage) def setImage(self, image): self.webcam.setPixmap(QPixmap.fromImage(image)) @pyqtSlot(QImage) def setImage1(self, image): self.webcam_2.setPixmap(QPixmap.fromImage(image)) def initUI(self): th = Thread(self) th1 = Thread1(self) th1.changePixmap1.connect(self.setImage1) th.changePixmap.connect(self.setImage) th.start()
I am new to python programming can anyone tell me what I am doing wrong here? I tried the other approach of doing the streaming in a function & setting streams up but this was not a conventional approach as my application kept crashing due to the while loop*( I guess)*. If I use one source at a time it works but I can't seem to get them working at a time.