Capture single picture with opencv

后端 未结 3 2356
迷失自我
迷失自我 2021-02-20 10:20

I have seen several things about capturing frames from a webcam stream using python and opencv, But how do you capture only one picture at a specified resolution with python and

3条回答
  •  心在旅途
    2021-02-20 11:20

    import cv2
    cap = cv2.VideoCapture(0)
    cap.set(3,640) #width=640
    cap.set(4,480) #height=480
    
    if cap.isOpened():
        _,frame = cap.read()
        cap.release() #releasing camera immediately after capturing picture
        if _ and frame is not None:
            cv2.imwrite('img.jpg', frame)
            cv2.imwrite(name, frame)
    

提交回复
热议问题