I’m currently making a defect inspection GUI using QtDesigner and PySide6. my goals is to display a webcam’s capture in a Qlabel name oriCamLabel
while on the other side, I also need to display an image processing result of the webcam capture with the following process:
- take the original webcam feeds
- processed the feeds (Grayscale, roi extract, blob analysis etc) using openCV
- display the result by real time in a different Qlabel named
ProcessedCamLabel
- also displaying the captured image where it produce defects in Qlabel
ResultDisplaylabel
But I hardly find the clear instruction tutorial/guide of using PySide6 especially in VSCode to help me achieve my project goals above.
Image of My GUI
I already utilize the QThread
class to display the webcam feed (which is a good practice i guess so that my GUI wouldn’t freeze(?)). do not mind the complex camidx
things, it’s a matter of adjusting between Qcombobox
index and the actual camera index which is not a problem for now.
class ThreadClass(QThread):
ImageUpdate = Signal(QImage)
global camIndex
def run(self):
camidx = camIndex
Capture = cv2.VideoCapture(camidx, cv2.CAP_DSHOW)
if camidx == 0:
camidx+=1
Capture = cv2.VideoCapture(camidx,cv2.CAP_DSHOW)
elif camidx == 1:
camidx-=1
Capture = cv2.VideoCapture(camidx,cv2.CAP_DSHOW)
self.ThreadActive = True
while self.ThreadActive:
global ret, frame
ret, frame = Capture.read()
if ret:
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
flipped = cv2.flip(src=frame, flipCode=1)
ConvertQtFormat = QImage(flipped.data,flipped.shape[1],flipped.shape[0], QImage.Format.Format_RGB888)
pic = ConvertQtFormat.scaled(640,480)
self.ImageUpdate.emit(pic)
def stop(self):
self.ThreadActive = False
self.quit()
What the actual problem is I would like to ask is, should I have a two different threads, one for the direct webcam display and another one for the image processing? or i can use the same thread with just a tweak in the later function definition? i still don’t understand how to pass the image/frame after capturing to another image processing function and then displaying it in a different display Qlabel widget. here’s my function definition inside mainWindow
class mainWindow(QMainWindow, Ui_MainWindow,ThreadClass):
def __init__(self):
.....
self.StartButton.clicked.connect(self.StartCam)
self.InspectButton.clicked.connect(self.ImageProcessing)
.....
def StartCam(self):
self.StartButton.setDisabled(True)
self.StopButton.setDisabled(False)
self.Worker_CV1 = ThreadClass()
self.Worker_CV1.ImageUpdate.connect(self.openCV_emit)
self.Worker_CV1.start()
.....
def openCV_emit(self, Image):
self.OriCamlabel.setPixmap(QPixmap.fromImage(Image))
.....
def ImageProcessing(self):
self.statsLabel.setText("Inspecting")
*#I don't know the rest to put here*
zhilaanabdrsyd is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.