How can I access my camera in Pycharm?

I wrote a simple code page that supposed to turn on my camera but it's not working.

That's the code:

import cv2
cap=cv2.VideoCapture(0)
while True:
ret,img=cap.read()
cv2.imshow('webcam',img)
k=cv2.waitKey(10)
if k==27:
break;
cap.release()
cv2.destroyAllWindows()
0
5 comments

Hello, 

 

I am wondering if it works the code is executed in the terminal? 

 

For more information on how to run your code from the terminal outside of IDE, please see the following article:
https://docs.python.org/3/using/cmdline.html#command-line

If you're using virtualenv interpreter in PyCharm, you may need to activate it in the command line prior to running your code:
https://virtualenv.pypa.io/en/latest/user_guide.html#activators

0
Avatar
Permanently deleted user

Hello,

I am using virtualenv interpreter in Pycharm, but I don't know what to active and how.

I just can't see my camera in the window when I run it. If I run an image it's working correctly.

0
Avatar
Permanently deleted user

Can you help me with that problem?

0

To activate the same venv: 

1. Go to File | Settings | Project: <project_name> | Project Interpreter (Preferences | Project: <project_name> | Project Interpreter for macOS) to find where your environment/interpreter is located;

2. Open your system terminal/cmd prompt and activate the same environment;

E.g. source .virtualenvs/<environment_name>/bin/activate or conda activate <environment_name>

3.  run python <path_to_script>

 

Feel free to ask any questions if more details required. 

 

 

0
Avatar
Permanently deleted user

Thank you!

0

Please sign in to leave a comment.