I am trying to use OpenCV to video capture my webcam. Each time I run the program, python quits unexpectedly, and the code says [Finishd in 0.3s with exit code -6] Operating System - Catalina 10.15.3 Using sublime text 3 Python 3.8
import cv2
cap = cv2.VideoCapture(0)
while(True):
ret, frame = cap.read()
cv2.imshow('frame', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
The problem is that Sublime's build systems can't handle GUI window creation like cv2.imshow()
. I believe it has to do with how the build system is executed using the subprocess
module. You'd run into the same problem if you were trying to display an image using Pillow
or matplotlib
, for example. Please note that you can do image processing just fine within Sublime, as long as you don't try to display the results.
The easiest way around it is to just keep a Terminal window open and manually run your scripts from the command line after saving.