Creating threshold for color blob tracking.

OpenMV related project discussion.
layne_ok
Posts: 1
Joined: Wed May 25, 2016 7:40 pm

Creating threshold for color blob tracking.

Postby layne_ok » Wed May 25, 2016 7:48 pm

Using the blob_detection.py as an example, I'm having trouble figuring out how to create my own theshold value.

Is there a way to train OpenMV to lean a color to track? Or to capture the threshold value from the IDE?


Thanks!
User avatar
kwagyeman
Posts: 2399
Joined: Sun May 24, 2015 2:10 pm

Re: Creating threshold for color blob tracking.

Postby kwagyeman » Wed May 25, 2016 8:18 pm

Yes, just select the frame buffer in the IDE and click copy color. This will paste the color values into you code. It also generates suggested color tracking values to start with. The values the IDE provides are narrow however. So you'll need to widen them for more general color tracking.

Um, so, a note about color tracking. It's hard. In general colors move around alot. If you really want good color tracking performance you have to control the lighting so that there aren't any shadows in the scene and you also need to keep the unique color areas in the scene low.

Also, make sure to turn auto gain and auto white balance off once the camera has taken a few frames.

In the future, I'll add a shadow removal function (extremely computationally heavy) and the ability to save and restore auto gain and auto white balance setting so color tracking is predictable when you change environments.
Nyamekye,
LuisK
Posts: 1
Joined: Sun Oct 30, 2016 8:50 am

Re: Creating threshold for color blob tracking.

Postby LuisK » Sun Oct 30, 2016 9:04 am

This doesn't work for me in OpenMV IDE 1.2.
Frame Buffer only has the Buttons "Zoom" and "Disable".
Could you please tell me how it works?

Thanks
User avatar
kwagyeman
Posts: 2399
Joined: Sun May 24, 2015 2:10 pm

Re: Creating threshold for color blob tracking.

Postby kwagyeman » Sun Oct 30, 2016 10:55 am

Literally click on the area of the image you want to track colors of and the histogram will now update to just the color distribution of that area. You just select the area of the image by click and dragging.
Nyamekye,
User avatar
rommel
Posts: 12
Joined: Tue Jul 11, 2017 5:42 pm

Re: Creating threshold for color blob tracking.

Postby rommel » Fri Oct 13, 2017 7:44 pm

I had an additional question about the shadow removal. I get shadows that trigger the blob, so I wanted to ask what is the basic idea of filtering out the shadows?
User avatar
kwagyeman
Posts: 2399
Joined: Sun May 24, 2015 2:10 pm

Re: Creating threshold for color blob tracking.

Postby kwagyeman » Sat Oct 14, 2017 12:01 am

Shadow removal is actually a separate task that's extremely computationally expensive if you'd like to remove all shadows from the image. I didn't think it could be done on the M4 but it can probably be done on the m7. I will look into porting an algorithm for that. It will make color tracking way easier.

As of right now, you should constrain your L channel to reject dark things.
Nyamekye,
User avatar
rommel
Posts: 12
Joined: Tue Jul 11, 2017 5:42 pm

Re: Creating threshold for color blob tracking.

Postby rommel » Fri Dec 08, 2017 2:08 pm

Hello Kwagyeman, is it possible to have shadow removal for the next release? If not, do you have an estimate on when it'll be implemented?

:geek: :ugeek:
User avatar
kwagyeman
Posts: 2399
Joined: Sun May 24, 2015 2:10 pm

Re: Creating threshold for color blob tracking.

Postby kwagyeman » Sat Dec 09, 2017 2:34 pm

Hi Rommel,

The next release, v2.6. does not include shadow removal. However, I've been looking into the feature... and there's one easy way to do it involving looking for similar chroma regions and making the l-channel similar for that. I could implement that one quickly... but, it will fail for images with very little color info.
Nyamekye,
SARAVANABAVAN
Posts: 32
Joined: Thu May 10, 2018 12:19 am
Location: Karaikal

Re: Creating threshold for color blob tracking.

Postby SARAVANABAVAN » Thu May 24, 2018 6:47 am

What is the procedure to track the white color alone in an image ?
User avatar
kwagyeman
Posts: 2399
Joined: Sun May 24, 2015 2:10 pm

Re: Creating threshold for color blob tracking.

Postby kwagyeman » Fri May 25, 2018 11:46 pm

Verbatim example code:

Code: Select all

# Single Color Grayscale Blob Tracking Example
#
# This example shows off single color grayscale tracking using the OpenMV Cam.

import sensor, image, time

# Color Tracking Thresholds (Grayscale Min, Grayscale Max)
# The below grayscale threshold is set to only find extremely bright white areas.
thresholds = (245, 255)

sensor.reset()
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.VGA)
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()

# Only blobs that with more pixels than "pixel_threshold" and more area than "area_threshold" are
# returned by "find_blobs" below. Change "pixels_threshold" and "area_threshold" if you change the
# camera resolution. "merge=True" merges all overlapping blobs in the image.

while(True):
    clock.tick()
    img = sensor.snapshot()
    for blob in img.find_blobs([thresholds], pixels_threshold=100, area_threshold=100, merge=True):
        img.draw_rectangle(blob.rect())
        img.draw_cross(blob.cx(), blob.cy())
    print(clock.fps())
Nyamekye,
SARAVANABAVAN
Posts: 32
Joined: Thu May 10, 2018 12:19 am
Location: Karaikal

Re: Creating threshold for color blob tracking.

Postby SARAVANABAVAN » Mon May 28, 2018 5:42 am

It worked ... Thank you so much...
Regards,
SARAVANABAVAN T :D

Return to “Project Discussion”

Who is online

Users browsing this forum: No registered users and 3 guests