Save multiple images with OpenCV and Python

前端 未结 4 1679
再見小時候
再見小時候 2021-02-06 17:52

I\'m using OpenCV and Python to take images. However currently I can only take one picture at a time. I would like to have OpenCV to take multiple pictures. This is my current c

4条回答
  •  猫巷女王i
    2021-02-06 18:50

    change the name of the image to be saved to " [image name] [a number which increase after every loop] " By doing this your image will be stored with a new name after every loop.. otherwise all the images will overwrite the same name !

    import cv2.cv as cv
    import time
    
    cv.NamedWindow("camera", 1)
    
    capture = cv.CaptureFromCAM(0)
    num = 0
    while True:
        img = cv.QueryFrame(capture)
        cv.ShowImage("camera", img)
        cv.SaveImage('pic'+str(num)+'.jpg', img)
        if cv.WaitKey(10) == 27:
            break
        num += 1
    

    now your images will be saved as pic0.jpg, pic1.jpg, pic2.jpg and so on..

提交回复
热议问题