2

I am trying to make a cctv system.

Currently, the connected camera number is checked in advance and videocapture is called with that number.

In this way, we want to check the camera number up to 10 and use only the camera number that exists within it.

This is the code I made now.

camNums = []
for i in range(10):
    if cv2.VideoCapture(i).isOpened():
        camNums.append(i)

Only the camera number in this camNums is used.

However, if I do this, a WARN message is printed, and I want to get rid of it.

[ WARN:0] global /io/opencv/modules/videoio/src/cap_v4l.cpp (887) open VIDEOIO(V4L2:/dev/video1): can't open camera by index

The WARN message seems to be caused by trying to call VideoCapture on a camera that doesn't exist.

Is there a way to check the connected camera number without getting this error message?

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
leecs
  • 21
  • 2
  • afaik opencv has no means to list available devices. nobody seems to have bothered so far. the information is necessarily available (but not exposed) because most backends don't just go by number, they go by GUIDs or something -- if you're on linux, you could glob for `/dev/video*` and get those numbers. that's all the cameras that'll ever be there. – Christoph Rackwitz Oct 11 '21 at 14:42
  • @ChristophRackwitz oh... i never thought about /dev/video. it seems good idea. thanks a lot!!! – leecs Oct 11 '21 at 16:01

0 Answers0