1

While running a simple opencv video capture script, i am getting False as the result. I suspect it is due to some security setting in Windows 10 which is not allowing camera access. I checked Privacy > Camera settings, but there was no option to allow a script to access the camera. I can see that the camera is not turned on when running the following opencv based test script.

import cv2

cap = cv2.VideoCapture(0)

while(True):
    ret, frame = cap.read()
    print(ret)
Pratik Khadloya
  • 12,509
  • 11
  • 81
  • 106
  • 1
    Is it a camera connected by USB or internal webcam like on your laptop? Because it could be something simple as trying another position in `cv2.VideoCapture()`. Have you tried 1 or 2? – Christoffer Sep 12 '18 at 10:01
  • Yes i have tried 0 and 1, that didn't help. What helped was since it was a new laptop where i never used the camera before, I had to manually turn the camera on with Fn+F6 and then turn it off. After that procedure, the python script was able to do it. – Pratik Khadloya Sep 12 '18 at 15:37
  • Happened to my last project, can you try to open windows 10 camera app when your program is running? And see whether your program will open the camera right after – gameon67 Feb 15 '19 at 00:35

3 Answers3

1

The Key to the answer is "Give time for Microsoft Windows to initalize WebCAM"

import time

   capWebcam = cv2.VideoCapture(0) 

   time.sleep(1.000) # Make sure, you need to give time
                     # for MS Windows to initialize Camera
Jake
  • 1,207
  • 2
  • 28
  • 46
Henry
  • 11
  • 1
  • Unfortunately that doesn't do the trick for me. I'm on Win10 and the webcam application shows a working camera. Also calling capWebcam.isOpened() returns true, so it is open. Still I run into the same FALSE aftwards. – BmyGuest Oct 09 '19 at 16:12
1

It's called "Allow access to classic application" or "Desktop applications" something like this in the bottom of the setting page, under Windows Store type applications. This gain camera access to all EXE and DLL standalone applications. One setting for all of them. More info on exceptions here https://support.microsoft.com/en-us/help/4468234/windows-10-desktop-apps-and-privacy

Works for me in

'cv2.__version__ 4.2.0'
0

just installed latest opencv and python8 on latest windows10. As suggested in previous helpful answers, after checking windows camera security setting, adding time delay, and running windows camera app, the program works fine.

Nick
  • 97
  • 10