Resize template image

OpenMV related project discussion.
hadidimad
Posts: 4
Joined: Thu Aug 02, 2018 5:36 am

Resize template image

Postby hadidimad » Fri Aug 03, 2018 7:03 pm

I have a project that it should find black blobs and then search for a template inside the blob.
This is some how like multiscale template match.
For this i need to resize my template in size of the blob (even a little smaller)
How can i resize the template i load for template match?
I really need to do this project. i would be very grateful if someone show me a way to do this
User avatar
kwagyeman
Posts: 2277
Joined: Sun May 24, 2015 2:10 pm

Re: Resize template image

Postby kwagyeman » Sat Aug 04, 2018 12:13 pm

We need to add a resize method to do this. Right now there's nothing in the library for this.

Would you be comfortable editing the C code? I don't have the bandwidth to add this feature right now.

It's pretty trival to add this.
Nyamekye,
hadidimad
Posts: 4
Joined: Thu Aug 02, 2018 5:36 am

Re: Resize template image

Postby hadidimad » Sat Aug 04, 2018 2:03 pm

kwagyeman wrote:
Sat Aug 04, 2018 12:13 pm
We need to add a resize method to do this. Right now there's nothing in the library for this.

Would you be comfortable editing the C code? I don't have the bandwidth to add this feature right now.

It's pretty trival to add this.
Yes i am good at C language but i dont know how the code of image resizing works.
User avatar
kwagyeman
Posts: 2277
Joined: Sun May 24, 2015 2:10 pm

Re: Resize template image

Postby kwagyeman » Sat Aug 04, 2018 2:26 pm

Okay, install the build system here and let me know if you can compile the firmware:

https://github.com/openmv/openmv/wiki
Nyamekye,
hadidimad
Posts: 4
Joined: Thu Aug 02, 2018 5:36 am

Re: Resize template image

Postby hadidimad » Sun Aug 05, 2018 2:28 am

kwagyeman wrote:
Sat Aug 04, 2018 2:26 pm
Okay, install the build system here and let me know if you can compile the firmware:

https://github.com/openmv/openmv/wiki
I installed the build system and i can build firmware using qt creator.
whats next?
User avatar
kwagyeman
Posts: 2277
Joined: Sun May 24, 2015 2:10 pm

Re: Resize template image

Postby kwagyeman » Sun Aug 05, 2018 3:11 am

Great.

Okay, can you describe to me what you're trying to do and then I can just tell you where to edit the code to minimize your work.
Nyamekye,
User avatar
kwagyeman
Posts: 2277
Joined: Sun May 24, 2015 2:10 pm

Re: Resize template image

Postby kwagyeman » Sun Aug 05, 2018 3:12 am

Like, post the code or describe the method call flow.
Nyamekye,
hadidimad
Posts: 4
Joined: Thu Aug 02, 2018 5:36 am

Re: Resize template image

Postby hadidimad » Sun Aug 05, 2018 3:28 pm

kwagyeman wrote:
Sun Aug 05, 2018 3:11 am
Great.

Okay, can you describe to me what you're trying to do and then I can just tell you where to edit the code to minimize your work.
at first thank you for helping me :D :D

this is the code i trying to make

Code: Select all

thresholds = (0, 20)

sensor.reset()
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.QQVGA)
sensor.skip_frames(time = 2000)
sensor.set_auto_gain(False) # must be turned off for color tracking
sensor.set_auto_whitebal(False) # must be turned off for color tracking
clock = time.clock()
template = image.Image("/H.pgm") # read the template image


while(True):
    clock.tick()
    img = sensor.snapshot().binary((0,10)) #change image to binary
    for blob in img.find_blobs([thresholds], pixels_threshold=100, area_threshold=100, merge=True): #find black blobs in white area
        template.resize([blob.w(),blob.h()]) # change the template size to blob size   (this is the method i need)
        res=img.find_template(template,roi=blob.rect())
        r = img.find_template(template,roi=blob.rect(), 0.65, step=5, search=SEARCH_EX)
        if r:
            img.draw_rectangle(r)
    print(clock.fps())
i need to resize template to find it in multiple sizes
i need method like opencv resize method.

the main issue of project is detecting letter H ,S and U with black color in white area(this should be done by moving robot. the robot have to move over walls and search for letters) i am going to use this way to detect them from multiple distances .
what do you think? is this a good way to do this?
User avatar
kwagyeman
Posts: 2277
Joined: Sun May 24, 2015 2:10 pm

Re: Resize template image

Postby kwagyeman » Sun Aug 05, 2018 3:43 pm

Okay, so, here's the issue. The OpenMV Cam is a microcontroller and doesn't have a ton of RAM. So, the reason we don't have resize() is because it's really not possible to store a large template in RAM. Additionally, template matching on large templates is really slow. So, what you actually want to do is to resize the area that you found to be the size of the template which is small. Then this could work.

So, you don't need resize() to do this.

Use the copy() method. This takes an ROI and spits out a cut out area of the main image. You can then template match on it.

Anyway, so the copy method right now does not support resizing code. However, if it did this would do everything you need. That said, you can modify copy int he firmware for the image you want to mess with to do what you need. Is the template size fixed? If so, I can point you to the code for copy and you can make some edits, recompile the firmware and you'll be good to go.

otherwise, you can also edit copy to accept a new size value such that you can handle multiple template sizes.
Nyamekye,

Return to “Project Discussion”

Who is online

Users browsing this forum: No registered users and 0 guests