This is my first time using OpenCV and I'm having some difficulties. I just made a simple program to see if it was imported correctly:
import cv2
import numpy as np
print("hi")
cap = cv2.VideoCapture(0)
print(cap.isOpened())
print("hi")
while True:
ret, frame = cap.read()
cv2.imshow('frame', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
When I run this file on the MacOS terminal, it works fine and opens up the video window, but when I run this file with IDLE nothing happens. No errors or warnings, the first "hi" prints but nothing else and the program ends. It's like as soon as I try to use cv2 directly after the first "hi", the program just ends. I believe I'm using the same version of python in both my terminal and IDLE, and I've tried uninstalling and reinstalling OpenCV using pip. Did I not install OpenCV correctly to be using with IDLE? Any help is greatly appreciated!
Edit: Not sure if this is causing any problems, but when I first ran it from IDLE, it had a few "Python quit unexpectedly" windows before I tried it in terminal. When I tried it there, it asked for access to my computer's webcam. Since then, the "Python quit unexpectedly" windows haven't showed up when I tried IDLE, so maybe it just needs access to my camera? I don't see an option for that in my Mac settings though, there's no IDLE app option to give access to.
.profileor equivalent was run -- but that was rather a long time ago).os.environbetween the working and broken environments, and set variables from the working environment into the broken one one-by-one until you find out which one, when set, solves the problem. The set of environment variables isn't the only possible problem, but it's by far the most likely one.