Taking snapshot immediately.

I have been testing the “Snapshot on Movement” example outdoors.

The program works but the snapshot is executed after a relatively long time even though the motion itself is very pronounced (big object passing in front of lens).

How can I execute a snapshot IMMEDIATELY upon detecting a pronounced motion?

Thanks in advance.

The example saves the image after detecting 10 frames of motion, try this:

    while(True):
        img = sensor.snapshot()
        img.difference("temp/bg.bmp")
        stats = img.statistics()
        if (stats[5] > 20):
            img.save("temp/snapshot-%d.jpg" % pyb.rng()) # Save Pic.

Thank you Ibrahim.

Does the example show 10 frames or 20?

The example waits until it counts 10 frames where motion is detected. The 20 is a threshold for the difference.

    diff = 10 # We'll say we detected motion after 10 frames of motion.

Thank you.