pageauc / pi-timolo

Raspberry PI-TIMOLO ( PI-TImelapse, MOtion, LOwLight ) uses RPI picamera and OpenCV for Remote Headless Security Monitoring using Motion Tracking, Rclone Auto Sync files with remote storage services. Auto Twilight Transitions and Low Light Camera Settings. Panoramic images using PanTiltHat and More. This project is featured on GitHub Awesome software.
MIT License
552 stars 102 forks source link

Quick Time Lapse does not save last image #92

Closed NelsonPJ closed 6 years ago

NelsonPJ commented 6 years ago

When using the "quick time lapse" feature, the very last picture in the burst will not get a title written to it, and will get overwritten by the next motion capture.

Looking at the code, the function takeQuickTimeLapse is taking pictures with the "yield" function, and if the timer is exceeded, the loop is exited - but this happens before the post image processing.

def takeQuickTimeLapse(moPath, imagePrefix, NumOn, motionNumCount,
                       currentDayMode, NumPath):
    """ Take a quick timelapse sequence using yield if motion triggered """
    logging.info("motion Quick Time Lapse for %i sec every %i sec",
                 motionQuickTLTimer, motionQuickTLInterval)
    checkTimeLapseTimer = datetime.datetime.now()
    keepTakingImages = True
    filename = getImageName(moPath, imagePrefix, NumOn, motionNumCount)
    while keepTakingImages:
        yield filename
        rightNow = datetime.datetime.now()
        timelapseDiff = (rightNow - checkTimeLapseTimer).total_seconds()
        if timelapseDiff > motionQuickTLTimer:
            keepTakingImages = False
        else:
            motionNumCount = postImageProcessing(NumOn,
                                                 motionNumStart,
                                                 motionNumMax,
                                                 motionNumCount,
                                                 motionNumRecycle,
                                                 NumPath, filename,
                                                 currentDayMode)
            filename = getImageName(moPath, imagePrefix, NumOn, motionNumCount)
            time.sleep(motionQuickTLInterval)

Moving the "if" statement to the bottom fixes the issue

    while keepTakingImages:
        yield filename
        rightNow = datetime.datetime.now()
        timelapseDiff = (rightNow - checkTimeLapseTimer).total_seconds()
        #Peter moved the if statement below the processing so last image will be saved
        motionNumCount = postImageProcessing(NumOn,
                                             motionNumStart,
                                             motionNumMax,
                                             motionNumCount,
                                             motionNumRecycle,
                                             NumPath, filename,
                                             currentDayMode)
        filename = getImageName(moPath, imagePrefix, NumOn, motionNumCount)
        time.sleep(motionQuickTLInterval)
        if timelapseDiff > motionQuickTLTimer:
            keepTakingImages = False
pageauc commented 6 years ago

Updated GitHub pi-timolo.py ver 10.93 per your suggested fix. Decided to release based on your testing. Will give it a try when I get a chance Your work is appreciated. Thanks Claude ...