Resize template image

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

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.

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

I installed the build system and i can build firmware using qt creator.
whats next?

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.

Like, post the code or describe the method call flow.

at first thank you for helping me :smiley: :smiley:

this is the code i trying to make

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?

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.