Assign value to image box

Discussion related to "under the hood" OpenMV topics.
mmmarouen
Posts: 5
Joined: Sat Oct 27, 2018 10:47 am

Assign value to image box

Postby mmmarouen » Thu Nov 01, 2018 10:10 am

Hi,

Noob question here :D : is there a way to assign a constant value for a rectangle in an image object?
I'm trying to have a black image and update it with white boxes. This would look something like:

Code: Select all

while(True):
    img = sensor.snapshot().histeq() # data image
    imbin=img.clear() #mask image to be updated, initially set to zero
    for r in ROIS: #I establish a ROIS list
        blobs = img.find_blobs([thresholds[threshold_index]], roi=r[0:4], merge=False)
        if blobs: # Find index of blob with most pixels.
            most_pixels = 0
            largest_blob = 0
            for i in range(len(blobs)):
                if blobs[i].pixels() > most_pixels:
                    most_pixels = blobs[i].pixels()
                    largest_blob = i
	     #Now I want update binary image with value= (255,255,255) for blobs[largest_blob].rect()
	     imbin.set_value(blobs[largest_blob].rect(),(255,255,255)) #What is the best way for this??
User avatar
kwagyeman
Posts: 2401
Joined: Sun May 24, 2015 2:10 pm

Re: Assign value to image box

Postby kwagyeman » Thu Nov 01, 2018 11:11 am

Hi, I'm not sure what your code is doing:

imbin=img.clear()

Makes the image black then you try to use find_blobs() on it. This will have no affect.

Anyway, if you want to draw a rectangle use the draw_rect() method which can fill the rectangle.
Nyamekye,
mmmarouen
Posts: 5
Joined: Sat Oct 27, 2018 10:47 am

Re: Assign value to image box

Postby mmmarouen » Thu Nov 01, 2018 1:41 pm

Hello,

Thanks for reply.
imbin=img.clear()

Makes the image black then you try to use find_blobs() on it. This will have no affect.
Got your point. What would be then a good way to create a mask with zeros having same size as image?
So my purpose is to have 1 images "img" and a mask "imgbin"
Thanks and keep awesome support :D
Marouen
User avatar
kwagyeman
Posts: 2401
Joined: Sun May 24, 2015 2:10 pm

Re: Assign value to image box

Postby kwagyeman » Fri Nov 02, 2018 1:21 am

Yeah, you need to allocate a second frame buffer. See the Frame differencing example scripts for how to do this.
Nyamekye,

Return to “Technical Discussion”

Who is online

Users browsing this forum: No registered users and 5 guests