Ask Your Question
0

How to check if camera is opened by any application

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

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 = cam.read()
cv2.imwrite('image.jpg', frame)
cam.release()
cv2.destroyAllWindows()

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
0

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

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

Comments

import cv2

cam = cv2.VideoCapture(0)

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

else:
    print('Cam is available')

Not working. Is my code correct?

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

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

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

here

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 -0600 )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 -0600 )edit

Question Tools

1 follower

Stats

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

Seen: 2,869 times

Last updated: Sep 13 '18