Ask Your Question

How to check if camera is opened by any application

asked 2018-09-12 12:46:27 -0500

Ghantey gravatar image

Cv2 module does not capture any image if my camera is used by other application like facebook (video chatting).

My Script:

import cv2
cam = cv2.VideoCapture(cv2.CAP_DSHOW)
ret, frame =
cv2.imwrite('image.jpg', frame)

When I run my script then it does not throw any error instead it creates a image.jpg having size of 0 bytes.

Can't I use my camera in two or more application?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2018-09-13 00:52:23 -0500

berak gravatar image

Can't I use my camera in two or more application?

no, you can't. and you have to CHECK if your capture opened, like:

if not cam.isOpened():
   # cam is not available
edit flag offensive delete link more


import cv2

cam = cv2.VideoCapture(0)

if not cam.isOpened():
    print('Cam is not available')

    print('Cam is available')

Not working. Is my code correct?

Ghantey gravatar imageGhantey ( 2018-09-13 01:32:42 -0500 )edit

your code is correct, but "not working" is never helpful anywhere ...

berak gravatar imageberak ( 2018-09-13 01:41:46 -0500 )edit


if not cam.isOpened():
     # It means that my camera is being used by other appliction like Chrome

Am I right berak?

Ghantey gravatar imageGhantey ( 2018-09-13 01:57:10 -0500 )edit

ah, it only means, that you cannot access this camera, there could be various reasons for that ! (it could also be unplugged, etc.)

berak gravatar imageberak ( 2018-09-13 01:58:38 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2018-09-12 12:46:27 -0500

Seen: 22 times

Last updated: Sep 13