So I’ve been working a lot in the past day in ironing out part of the night side loop (loop 3 in this diagram). Basically, it starts recording based on an input from a sensor and continues to record until these inputs stop occurring.
My test code looks like this
1 2 3 4 5 6 7 8 9 10 11 12 13 |
v1 = CameraModuleVideo("/home/pi/CreatureCapture/", "video1") try: v1.startRecording() except ValueError as e: print(e) FilmDurationTrigger(5) try: v1.stopRecording() except ValueError as e: print(e) |
The interesting functions at work here are the following:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
def FilmDurationTrigger(time): t = CameraTimer(time) while True: continueFlag = False print "Filming For " + str(time) + " Seconds" t.run() while (t.isExpired() != True): if (GetContinueTrigger() == True): continueFlag = True print "Trigger Found, Continuing" print "Time Has Expired, Continue Flag Is Set To " + str(continueFlag) if (continueFlag == False): break |
FilmDurationTrigger()
Takes the period of time that will be filmed, in this example, it’s 5 seconds just to conserve time, but in application it will be 20 seconds. This code will pause for the input time, and continue to be paused upon inputs from GetContinueTrigger()
. This delay allows the code to continue filming until there are no inputs.
In this example, GetContinueTrigger()
returns a Boolean if a random event occurs, but in application it will return a Boolean based on the status of a motion detector.
1 2 3 4 |
def GetContinueTrigger(): z = randint(0,10000) k = ((z == 115)) return k |
I ran two tests, both of them produced separate results. The first one created a 10 second long video:
1 2 3 4 5 6 7 |
pi@raspberrypi ~/CreatureCapture $ python CreatureCaptureTest2.py Filming For 5 Seconds Trigger Found, Continuing Time Has Expired, Continue Flag Is Set To True Filming For 5 Seconds Time Has Expired, Continue Flag Is Set To False Terminated |
And the second created a 15 second long video:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
pi@raspberrypi ~/CreatureCapture $ python CreatureCaptureTest2.py Filming For 5 Seconds Trigger Found, Continuing Trigger Found, Continuing Trigger Found, Continuing Trigger Found, Continuing Time Has Expired, Continue Flag Is Set To True Filming For 5 Seconds Trigger Found, Continuing Time Has Expired, Continue Flag Is Set To True Filming For 5 Seconds Time Has Expired, Continue Flag Is Set To False Terminated |
These two test shows that variable capture length functionality works! As a note, the actual times on the output video varies from the amount of time that it’s designed to record for. This is because the variable frame rate nature of the video coming out of the camera module, it causes the videos to come out a little short, but they still contain all the frames of the amount of time desired to record, just scaled slightly by frame rate error.