Skip to content
Advertisement

How do I run a video in a PyQt container?

In the QVideoWidget container on PyQt, you need to start a video from the computer, on which objects are to be searched through TensorFlow (openCV, cv2). The problem is that when the button is pressed, the video only shows one frame and nothing else. What could be the problem? Made in PyCharm, Python 3.7.

JavaScript

Advertisement

Answer

All problem is because you have wrong indentations – and you run cap.release() inside while-loop so it releases stream after the first frame.

JavaScript

You don’t create window in cv2 so you don’t cv2.destroyAllWindows(). And cv2.waitKey(1) will be also useless because the system sends key/mouse events to cv2 only when it displays the window and this window is active (focused).


EDIT:

Full working code. It uses a webcam.

It doesn’t need a UI file.

It has buttons to start and stop streaming,

It has also buttons to switch: RGB <-> GRAYSCALE, NORMAL <-> BLURED.

JavaScript

RGB, NORMAL:

enter image description here

GRAYSCALE, BLURED:

enter image description here

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement