Save multiple images with OpenCV and Python

前端 未结 4 1675
再見小時候
再見小時候 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条回答
  •  悲哀的现实
    2021-02-06 18:42

    Your code overwrite a file. Save to different file each time. For example:

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

提交回复
热议问题