# find template

**URL:** <https://forums.openmv.io/t/find-template/545>\
**Category:** OpenMV Boards\
**Created:** [January 10, 2018, 9:03am UTC](https://forums.openmv.io/t/find-template/545 "2018-01-10T09:03:50Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![jade](https://avatars.discourse-cdn.com/v4/letter/j/a8b319/32.png) [@jade](https://forums.openmv.io/u/jade)\
**Post date:** [January 10, 2018, 9:03am UTC](https://forums.openmv.io/t/find-template/545/1 "2018-01-10T09:03:50Z")

</div>

Hi.  
I using a find\_template function.  
but if moving snapshot images  
camera connections are fail

how can i stay clearly connection state

---

<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:** [January 10, 2018, 3:42pm UTC](https://forums.openmv.io/t/find-template/545/2 "2018-01-10T15:42:12Z")

</div>

Hi, what’s the hardware you are using M4/M7, ide version, operating system, and firmware version?

---

<div class="post-metadata">

**Author:** ![jade](https://avatars.discourse-cdn.com/v4/letter/j/a8b319/32.png) [@jade](https://forums.openmv.io/u/jade)\
**Post date:** [January 11, 2018, 12:45am UTC](https://forums.openmv.io/t/find-template/545/3 "2018-01-11T00:45:48Z")

</div>

> [@](#):
>
> Hi, what’s the hardware you are using M4/M7, ide version, operating system, and firmware version?

I using M7 and firmware version is 2.6.0  
camera is connected on PC  
PC is operating Windows 7

python program is operating on my pc

i want to find some point of image  
so template is part of image (snapshot → save(roi))

usually disconnecting at image change  
(image or camera is moving  
and focus out or can not find template on image)

---

<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:** [January 11, 2018, 2:19am UTC](https://forums.openmv.io/t/find-template/545/4 "2018-01-11T02:19:18Z")

</div>

Hi, do you have an SD Card with the camera? You can save images to the internal flash. Otherwise, it seems like the camera should be fine with your PC.

---

<div class="post-metadata">

**Author:** ![jade](https://avatars.discourse-cdn.com/v4/letter/j/a8b319/32.png) [@jade](https://forums.openmv.io/u/jade)\
**Post date:** [January 11, 2018, 3:20am UTC](https://forums.openmv.io/t/find-template/545/5 "2018-01-11T03:20:51Z")

</div>

> [@](#):
>
> Hi, do you have an SD Card with the camera? You can save images to the internal flash. Otherwise, it seems like the camera should be fine with your PC.

Hi.  
if i insert SD Card, how can i check Card was connected successfully

after insert SD Card, and try advanced\_frame\_differencing project  
and occurs error  
OSError : Failed to write requested bytes!

Do i something at SD Card?

SD Card is 8GB and FAT32 Format and also exFAT Format do not work too

---

<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:** [January 11, 2018, 3:31am UTC](https://forums.openmv.io/t/find-template/545/6 "2018-01-11T03:31:09Z")

</div>

Hi, the SD card should appear when you plug the camera into the PC and you should see it as a USB drive on the computer. You should be able to open files and save files using Windows explorer.

---

<div class="post-metadata">

**Author:** ![jade](https://avatars.discourse-cdn.com/v4/letter/j/a8b319/32.png) [@jade](https://forums.openmv.io/u/jade)\
**Post date:** [January 11, 2018, 10:14am UTC](https://forums.openmv.io/t/find-template/545/7 "2018-01-11T10:14:53Z")

</div>

> [@](#):
>
> Hi, the SD card should appear when you plug the camera into the PC and you should see it as a USB drive on the computer. You should be able to open files and save files using Windows explorer.

Hi.  
insert SD Card, but it have same symptoms.

always disconnected after print(“1”) and before print(“2”) at code  
so i can see printed 1 but cannot see printed 2

if it have small size template image , it have much better connecting time  
but it also disconnected few minutes ago.

I think it happens when the images are constantly moving and there is more tracking of the images.

i need connection for 24 hours.  
so it must not disconnect

and if i set roi, but it isn’t work .  
the template match location was out of roi

```python
import time, sensor, image
from image import SEARCH_EX, SEARCH_DS

sensor.reset()
#sensor.set_auto_gain(True);
#sensor.set_auto_whitebal(True);
sensor.set_contrast(3)
#sensor.set_gainceiling(8)
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 1000)

clock = time.clock()

#img = sensor.snapshot()
#img.save("/desc.pgm",roi = (57,142,53,64))
template = image.Image("/desc.pgm") #,copy_to_fb = True
#img = sensor.snapshot()

while(True):
    clock.tick()
    img = sensor.snapshot()
    #print("1")
    r = img.find_template(template, 0.60, step=8, search=SEARCH_DS, roi=(1,1,118,238)) #, roi=(10, 0, 60, 60))
    #print("2")
    if r:
        print(r)
        img.draw_rectangle(r)
    print(clock.fps())

```

---

<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:** [January 11, 2018, 4:20pm UTC](https://forums.openmv.io/t/find-template/545/8 "2018-01-11T16:20:29Z")

</div>

Hi, please upload all assets for me to reproduce the behavior. I.e. the template image and target image. Please save them both as PPM files using the OpenMV Cam’s save method.

Your running into a bug right now. The question is if I can work around it in the mean time.

---

<div class="post-metadata">

**Author:** ![jade](https://avatars.discourse-cdn.com/v4/letter/j/a8b319/32.png) [@jade](https://forums.openmv.io/u/jade)\
**Post date:** [January 12, 2018, 1:00am UTC](https://forums.openmv.io/t/find-template/545/9 "2018-01-12T01:00:13Z")

</div>

> [@](#):
>
> Hi, please upload all assets for me to reproduce the behavior. I.e. the template image and target image. Please save them both as PPM files using the OpenMV Cam’s save method.
> 
> Your running into a bug right now. The question is if I can work around it in the mean time.

maybe you can see how i tried through attached video  
and this video have roi (1,1,118,238)  
it was out of roi that template matched location

i can not save ppm file  
if i try save to desc.ppm  
Occurs ErrorMessage - OSError: Image is not PPM  
so files are pgm file

and I attached the code below

image save code

```python
img = sensor.snapshot()
img.save("/desc.pgm",roi = (104,127,34,34))
template = image.Image("/desc.pgm",copy_to_fb = True) #
img = sensor.snapshot()

```

template\_matching test code

```python
template = image.Image("/desc.pgm")
while(True):
    clock.tick()
    img = sensor.snapshot()
    #print("1")
    r = img.find_template(template, 0.60, step=8, search=SEARCH_DS, roi=(1,1,118,238)) #, roi=(10, 0, 60, 60))
    #print("2")
    if r:
        print(r)
        img.draw_rectangle(r)
    print(clock.fps())

```

I write down before  
i need connection for 24 hours.  
[pgm\_file.zip](https://forums.openmv.io/uploads/short-url/cTgs29Oj8St9wNzCcHVZ3tBbTYy.zip) (43.1 KB)  
[test.mp4](https://forums.openmv.io/uploads/short-url/uJr1R8X7us6JLmn48ZdggBiqAsQ.mp4) (1 MB)  
 ![target_point.PNG](https://canada1.discourse-cdn.com/flex029/uploads/openmv1/original/1X/91009e9a7a8cd65ff790d14b5b4712a8a8db4910.png)  
 ![template_image.PNG](https://canada1.discourse-cdn.com/flex029/uploads/openmv1/original/1X/548d8509bb573cc576b2b939af3cd500850e7497.png)  
 ![target_image.PNG](https://canada1.discourse-cdn.com/flex029/uploads/openmv1/original/1X/404e22ef3d965073e15e9ecc67b4cf7bd7801ae6.png)

---

<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:** [January 12, 2018, 6:23pm UTC](https://forums.openmv.io/t/find-template/545/10 "2018-01-12T18:23:11Z")

</div>

Hi, I can reproduce this bug, will look into it and get back to you.
