I don't know what's wrong but when I use stream (io.BytesIO()) when I want to save one picture after another from time to time I get same picture saved. Code:

from picamera import PiCamera
import io
import time
from datetime import datetime
from PIL import Image

capture_fps = 30
camera_fps = 2 * capture_fps
camera_width = 640
camera_height = 480
camera = PiCamera()

path = "/home/pi/Pictures/"
extension = ".jpg"

# from 0000.py
def str_number(recieved_int_number):
    if recieved_int_number < 10:
        return "0" + str(recieved_int_number)
        return str(recieved_int_number)

def create_image_date():
    now = datetime.now()
    return str(now.year) + str_number(now.month) + str_number(now.day) + " " + \
           str_number(now.hour) + str_number(now.minute) + str_number(now.second) + \
           "-" + str(now.microsecond)

def outputs():
    stream = io.BytesIO()
    for image in range(capture_fps):
        # This returns the stream for the camera to capture to
        yield stream
        # Once the capture is complete, the loop continues here
        # (read up on generator functions in Python to understand
        # the yield statement). Here you could do some processing
        # on the image...
        img = Image.open(stream)
        image_date = create_image_date()
        img.save(path + image_date + extension)

        # Finally, reset the stream for the next capture

camera.resolution = (camera_width, camera_height)
camera.framerate = camera_fps
start = time.time()
camera.capture_sequence(outputs(), 'jpeg', use_video_port=True)
finish = time.time()
print('Captured %s images at %.2f fps at %s x %s resolution.' % (capture_fps, camera_fps / (finish - start), camera_width, camera_height))
print('Real capture fps: %.2f' % (float(camera_fps / (finish - start)) * 0.5))
  • I get same picture saved .... what does this mean? – jsotola May 19 '18 at 22:40
  • that's weird after copying this code you should get same output as me unless this have something to do with picamera (mine version is 2.1) – Hsin May 20 '18 at 7:39
  • i do not have a picamera, so i did not try your code .... please answer my question ... i do not know if you mean that you get multiple files with the same image, or if the code overwrites pictures by using a duplicate file name for multiple images – jsotola May 20 '18 at 7:51
  • Oh. It's hard to explain. I get frames saved one after another but sometimes it saves older (already saved) frame and I don't understand why does this happen. – Hsin May 20 '18 at 7:56
  • do you end up with two copies of the older (already saved) image? .... you still have not really answered my question – jsotola May 20 '18 at 7:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.