Title: Can't capture image with opencv when camera is in use
Tags: windows;python-2.7;opencv
Question: 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?
Comment: But I can use my webcam for video chatting as well as taking pic online simultaneously. But why can't I do with this script?

Comment: I mean taking pic from online sites like webcamtoy.com, pixect.com,etc. I can use this site to take pic while having video chatting but why can't I use with my script simultaneously?

Comment: yeah I asked the same question because I could not find the solution.

Comment: Oh that's awesome. I didn't see coming that. So there is no way to capture image from my script if my camera is used by Chrome or other application right ? Or is there any way to deal with? But still there might be the way to know if my camera is being used via python script?

Comment: What's your question? | Most webcam drivers are designed to allow only a single client to use the camera at a time.

Comment: What does "taking pic online" mean exactly? Elaborate.

Comment: @markkeven I assume it's the same browser that you're using for both facebook and the sites that let you take pictures? Then the browser has exclusive access to that camera, and it can provide the media stream to multiple web pages it displays. Try to have each page open in a different browser (say one in Firefox, other in Chrome, etc.) and you'll see it will no longer work. | If you [search around](https://www.google.com/search?q=using+webcam+from+multiple+programs) you can find software that allows one camera to be used in multiple programs.

Comment: You can call [`cv.VideoCapture.isOpened()`](https://docs.opencv.org/3.4.3/d8/dfe/classcv_1_1VideoCapture.html#a9d2ca36789e7fcfe7a7be3b328038585) to test whether the program succeeded in opening the camera. If it failed, then the camera may be used by other application (or is not connected, etc.). | [There are options to deal with it](https://stackoverflow.com/questions/13262836/access-webcam-from-multiple-applications-simultaneously), but I can't make any recommendations.

Comment: Possible duplicate of [Check with Python that webcam is being used in Chrome](https://stackoverflow.com/questions/52302176/check-with-python-that-webcam-is-being-used-in-chrome)



{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 0, 'CommentCount': 9, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2018:00:09/12/18', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<windows><python-2.7><opencv>', 'Title': "Can't capture image with opencv when camera is in use", 'ViewCount': 513, 'id': 52300145, 'user_AboutMe': '<p>I am python developer who wants to learn more and more about just about python</p>\n', 'user_AccountId': 12679157.0, 'user_DisplayName': 'Ghantey', 'user_Reputation': 544.0, 'user_Views': 91.0, 'user_id': 9213601.0}}