I’m looking at the mjpeg_on_movement.py example.
I see that it triggers recording when the difference in the background image and the difference in the current image has happened for 10 frames (during that while loop).
What I don’t see immediately is a way to specify when the recording stops/ how long the recording lasts.
After running it awhile, it seems the recordings will last about 15sec … but is there a way to have recording stop if there’s no motion for a time?
(I’m not talking about turning off the camera… I saw the topic on that. I’d like to continue recording files/use a standard naming scheme in the order that the files are recorded).
I’m imagining something like
while(diff):
img = sensor.snapshot()
img.difference("temp/bg.bmp")
stats = img.statistics()
if (stats[5] > 20):
diff -= 1
m = mjpeg.Mjpeg("example-%d.mjpeg" % pyb.rng())
clock = time.clock() # Tracks FPS.
print("You're on camera!")
for i in range(200):
clock.tick()
m.add_frame(sensor.snapshot())
print(clock.fps())
# the idea is that the current image, when there's no motion for a short period of time, would be approximately
# equal to the original background image recorded above (since the camera hasn't moved) ... for 10 frames
[i][b] if ( (current image - "temp/bg.bmp") < diff_threshold_value && recording_off_counter == 10)
recording_off_counter = 1 + recording_off_counter
break for loop [/b][/i]
m.close(clock.fps())
pyb.LED(BLUE_LED_PIN).off()
print("Restarting...")
My question is about that sorta-psuedo code up there… is that the best way? Is there a better method I’m not thinking of?
Thank you!