March 2019
Intermediate to advanced
532 pages
13h 2m
English
This first example, read_camera.py, shows you how to read frames from a camera that's connected to your computer. The required argument is index_camera, which indicates the index of the camera to read. If you have connected a webcam to your computer, it has an index of 0. Additionally, if you have a second camera, you can select it by passing 1. As you can see, the type of this parameter is int.
The first step to work with cv2.VideoCapture is to create an object to work with. In this case, the object is capture, and we call the constructor like this:
# We create a VideoCapture object to read from the camera (pass 0):capture = cv2.VideoCapture(args.index_camera)
If index_camera is 0 (your first connected camera), it ...