# Taking snapshot immediately.

**URL:** <https://forums.openmv.io/t/taking-snapshot-immediately/1394>\
**Category:** OpenMV Boards\
**Created:** [September 1, 2019, 8:34am UTC](https://forums.openmv.io/t/taking-snapshot-immediately/1394 "2019-09-01T08:34:29Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jimmie](https://avatars.discourse-cdn.com/v4/letter/j/e95f7d/32.png) [@jimmie](https://forums.openmv.io/u/jimmie)\
**Post date:** [September 1, 2019, 8:34am UTC](https://forums.openmv.io/t/taking-snapshot-immediately/1394/1 "2019-09-01T08:34:29Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![iabdalkader](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/iabdalkader/32/1169_2.png) [@iabdalkader](https://forums.openmv.io/u/iabdalkader)\
**Post date:** [September 1, 2019, 4:08pm UTC](https://forums.openmv.io/t/taking-snapshot-immediately/1394/2 "2019-09-01T16:08:04Z")

</div>

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

```python
    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.

```

---

<div class="post-metadata">

**Author:** ![jimmie](https://avatars.discourse-cdn.com/v4/letter/j/e95f7d/32.png) [@jimmie](https://forums.openmv.io/u/jimmie)\
**Post date:** [September 1, 2019, 4:49pm UTC](https://forums.openmv.io/t/taking-snapshot-immediately/1394/3 "2019-09-01T16:49:49Z")

</div>

> [@](#):
>
> The example saves the image after detecting 10 frames of motion, try this:
> 
> ```python
> 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?

---

<div class="post-metadata">

**Author:** ![iabdalkader](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/iabdalkader/32/1169_2.png) [@iabdalkader](https://forums.openmv.io/u/iabdalkader)\
**Post date:** [September 1, 2019, 5:02pm UTC](https://forums.openmv.io/t/taking-snapshot-immediately/1394/4 "2019-09-01T17:02:55Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![jimmie](https://avatars.discourse-cdn.com/v4/letter/j/e95f7d/32.png) [@jimmie](https://forums.openmv.io/u/jimmie)\
**Post date:** [September 1, 2019, 9:05pm UTC](https://forums.openmv.io/t/taking-snapshot-immediately/1394/5 "2019-09-01T21:05:06Z")

</div>

Thank you.

---

<div class="post-metadata">

**Author:** ![vsheno7](https://avatars.discourse-cdn.com/v4/letter/v/8e7dd6/32.png) [@vsheno7](https://forums.openmv.io/u/vsheno7)\
**Post date:** [April 7, 2024, 10:12am UTC](https://forums.openmv.io/t/taking-snapshot-immediately/1394/6 "2024-04-07T10:12:08Z")

</div>

Unable to Capture Snapshots “OSError: Failed to write requested bytes!”. What could be the possible Reasons?

---

<div class="post-metadata">

**Author:** ![kwagyeman](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/kwagyeman/32/4_2.png) [@kwagyeman](https://forums.openmv.io/u/kwagyeman)\
**Post date:** [April 7, 2024, 3:25pm UTC](https://forums.openmv.io/t/taking-snapshot-immediately/1394/7 "2024-04-07T15:25:13Z")

</div>

Don’t write pictures to the internal flash. Please use an SD card. The internal flash is very small.
