--Launch the webcam attached to your PC --Taking a still image --Save locally
#Create an instance of the VideoCapture class
    #Specify 0 when using the built-in webcam
    cap = cv2.VideoCapture(0)
    #If it cannot be read normally
    if cap.isOpened() is False:
        print("IO Error")
    #When loaded normally
    else:
        #read method
        #Return value 1 ret:Was the frame image loaded?/Return value 2 frame:Array of images (ndarray)
        ret, frame = cap.read()
        image_path = "./images/"
        if (ret):
            #imwrite method
            #Argument 1: Image path Argument 2: ndarray object representing the image
            #The extension of the image path is.jpg and.You can use png.
            cv2.imwrite(image_path + "image.png ", frame)
        else:
            print("Read Error")
    cap.release() #Quit the camera device
        Recommended Posts