
Read values from the camera object, using it's read method. Tells the program to loop the following indented code 10 times return_value, image = camera.read() Imports openCV for usage camera = cv2.VideoCapture(0)Ĭreates an object called camera, of type openCV video capture, using the first camera in the list of cameras connected to the computer. Note that the key events are from the cv2.namedWindow so it has to have focus.īreaking down your code example (Explanations are under the line of code.) import cv2 If you need to grab multiple images per press of the SPACE key, you will need an inner loop or perhaps just make a function that grabs a certain number of images. If there is any line of it that you don't understand let me know and I'll add comments. I think this should answer your question for the most part.

Img_name = "opencv_frame_.png".format(img_counter)

Here is a simple program that displays the camera feed in a cv2.namedWindow and will take a snapshot when you hit SPACE.
