0

I have been trying to use 3 cameras with Python and OpenCV and I can do it. The problem is that the VideoCapture parameter changes, I've had the idea that it depends on the order of connecting the cameras, being 0 the webcam and external cams starting from 1, but sometimes the webcam turns on with a value different than 0, it gets a bit frustrating after a while and I can't seem to find a solution.

This is the code I have been using to start webcams, the weird thing is that most of the times it pops up the webcam when I dont put a 0, and the external camera opens with the 0.

# Starting Camera 1
self.cap = cv2.VideoCapture(1, cv2.CAP_DSHOW)
self.cap.set(self.FRAME_PROP_WIDTH, self.frame_w)
self.cap.set(self.FRAME_PROP_HEIGHT, self.frame_h)
self.cap.set(cv2.CAP_PROP_FPS,30)

# Starting Camera 2
self.cap = cv2.VideoCapture(2, cv2.CAP_DSHOW)
self.cap.set(self.FRAME_PROP_WIDTH, self.frame_w)
self.cap.set(self.FRAME_PROP_HEIGHT, self.frame_h)
self.cap.set(cv2.CAP_PROP_FPS,30)

# Starting Camera 3
self.cap = cv2.VideoCapture(3, cv2.CAP_DSHOW)
self.cap.set(self.FRAME_PROP_WIDTH, self.frame_w)
self.cap.set(self.FRAME_PROP_HEIGHT, self.frame_h)
self.cap.set(cv2.CAP_PROP_FPS,30)
Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
  • Did you check https://stackoverflow.com/q/58962748/18667225, https://stackoverflow.com/q/57577445/18667225, https://stackoverflow.com/q/34197825/18667225, https://stackoverflow.com/q/19796507/18667225 e.a. ? – Markus Nov 18 '22 at 08:59
  • Do you want to find a list of available cameras (like 0, 1, 2), or do you want to **distinguish** which number refers which camara (getting the device name of each camera or some kind of ID)? If it's the later, you may try `camera_guid = cap.get(cv2.CAP_PROP_GUID)`, but I don't think it's working... – Rotem Nov 18 '22 at 12:13
  • @Rotem Ya, based on a quick look at the source, that seems only supported by backends for V4L and FireWire. – Dan Mašek Nov 18 '22 at 23:55
  • Personally, I wouldn't consider using `VideoCapture` for anything more than a quick proof of concept where such things don't matter. Still doesn't seem like anything production ready, more of a least-common denominator, and wonky in many places. Have yet to see something to convince me otherwise. | I'd suggest to look for a library that would allow you to enumerate cameras on Windows (since you're using DSHOW), control them and read images from them. Something more focused at such task. – Dan Mašek Nov 19 '22 at 00:01

0 Answers0