Wu Yuxiong - born natural python learning Notes: python crawling camera video image using Open CV

Open CV In addition to reading and displaying still pictures, you can also load and play motion video, and
Read image information of the built-in or external camera. Many laptops have a camera, OpenCV by
VideoC apture way to open the camera, the syntax is:

Wherein, is an integer of n-built-in camera is 0, then if there are other cameras were 1, 2 ,.... E.g,
Open the built-in camera to save the camera well to cap the variable:

The camera is in the open state can be determined by the method is Opened, the syntax is:

If the camera is turned on, True is returned; otherwise it returns False a 
Open rear camera, the camera can be read by the image information read method, the syntax is:

For example, the reading camera images, ret Boolean variable stored in the image stored in the img:

Get user input keyboard
The image of the camera to obtain a dynamic image, how to get a static image of a certain time it? By allowing users
Pressing a specific key to capture still pictures at that time. The first chapter 1 section we mentioned the Open CV
waitKey ways of obtaining user input, this method may also be acquired while the ASCII value of the key, the syntax is:

Key variables to hold ASCII key, in the range from 0 to 255 . For example: ASCII code A is
 provided under the code 65 domestic user key 10 seconds, and the ASCII code for the key is returned to the key variables:
If the user presses A, the key 65 value.

Gripping the moving image information by the camera is turned
Automatically turning on the camera after the program execution, the captured image saved when the user presses the wells Z.
import cv2

cv2.namedWindow("frame")
cap = cv2.VideoCapture(0)
while(cap.isOpened()):
    right, img = cap.read ()
     if the right == True:
        cv2.imshow("frame", img)
        k = cv2.waitKey(100)
        if((k == ord("z"))or(k == ord("Z"))):
            cv2.imwrite("E:\\catch.jpg", img)
            break
cap.release()
cv2.waitKey(0)
cv2.destroyWindow("frame")

Guess you like

Origin www.cnblogs.com/tszr/p/12032904.html