I am using https://github.com/theAIGuysCode/yolov4-custom-functions this repository. I want to crop and save pictures while running on webcam. But when I run the following code:
python detect_video.py --weights ./checkpoints/yolov4-416 --size 416 --model yolov4 --video ./data/video/bobinmi.mp4 --output ./detections/results.avi --crop
I can just detect the first frame of the video. Then it gives error and not detect. What should I do?
I'm using CUDA 10.1, Python 3.7 and Tensorflow 2.3. The error is same in CPU and GPU working environments.
The error message is:
FPS: 1.50
qt.qpa.xcb: could not connect to display
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "/usr/local/lib/python3.7/dist-packages/cv2/qt/plugins" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
Available platform plugins are: xcb.
Fatal Python error: Aborted
Current thread 0x00007fbeed09b780 (most recent call first):
File "detect_video.py", line 165 in main
File "/usr/local/lib/python3.7/dist-packages/absl/app.py", line 254 in _run_main
File "/usr/local/lib/python3.7/dist-packages/absl/app.py", line 308 in run
File "detect_video.py", line 178 in <module>
CodePudding user response:
The error message is only caused in Colab at line 165, that is with the following instruction:
cv2.namedWindow("result", cv2.WINDOW_AUTOSIZE)
From the documentation this function is used to create a window. The reason is that Colab does not have a screen and some cv2 functions need a screen to perform the operations. Creating a windows is definitely one of them.
To fix the error in Colab should be enough to install a virtual screen. The code (from this stack answer):
!apt-get install -y xvfb # Install X Virtual Frame Buffer
import os
os.system('Xvfb :1 -screen 0 1600x1200x16 &') # create virtual display with size 1600x1200 and 16 bit color. Color can be changed to 24 or 8
os.environ['DISPLAY']=':1.0' # tell X clients to use our virtual DISPLAY :1.0