I am trying to re-produce a simple code using opencv with python 3.9.7 on ArchLinux using gnome as a desktop environment. I installed opencv with the command pip3 install --upgrade opencv-python. My current code is shown below.
import cv2
cap = cv2.VideoCapture(0)
cap.set(3, 640)
cap.set(4, 480)
while True:
success, img = cap.read()
cv2.imshow("Video", img) # This is where the code fails
if cv2.waitKey(1) & 0xFF == ord('q'):
break
The code runs if I remove everything below the imshow() command, but when I add that single line, the execution fails with the following error
Segmentation fault (core dumped)
It appears that a number of people have had this issue, but I have not seen a resolution. Does anyone know how I can fix this?
cv2.CAP_PROP_FRAME_WIDTHand height