I am trying to install OpenCv and run some code on PyCharm on Mac.
I have installed the opencv package as well as numpy but when I run the code this error shows up on Pycharm IDE: "cannot find reference 'VideoCapture' in __init__.py"
In fact, every time I write example_variable = cv2., PyCharm is not giving me any option to autocomplete with a function attached to cv2. Why is this happening?
Here's the code I am trying to run. I tried also running other codes but the same error displays:
import cv2
import numpy as np
cap = cv2.VideoCapture()
while True:
ret, frame = cap.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.imshow('frame',gray)
if cv2.waitKey(1) & OxFF == ord('q'):
break
cap.release
cv2.destroyAllWindows()
Any tips on how to run this code smoothly? The end goal is to have my front webcam capture live video and react to it.
Use this command line to avoid the reference issue
pip install --force-reinstall --no-cache -U opencv-python==4.5.5.62
Try one of this solutions:
OR:
After all that, you can also delete the .idea folder in your root directory and restart the IDE.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With