How To Display A Cv2 Video Inside A Python GUI?
I'm creating a GUI using Python/PyQt5 which should display a video along with other widgets in the same window. I've tried different approaches to this problem but stil can't seem
Solution 1:
Inside the while
loop, you need to convert frame
into a QPixmap
again, similar to what you did above, and then update ui
:
cap = cv2.VideoCapture('video.mov')
while (cap.isOpened()):
ret, frame = cap.read()
if not ret:
break
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
img = QImage(frame, frame.shape[1], frame.shape[0], QImage.Format_RGB888)
pix = QPixmap.fromImage(img)
pix = pix.scaled(600, 400, Qt.KeepAspectRatio, Qt.SmoothTransformation)
self.ui.label_7.setPixmap(pix)
self.ui.frame = pix # or img depending what `ui.frame` needs
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
Post a Comment for "How To Display A Cv2 Video Inside A Python GUI?"