Page 1 of 1

Creating threshold for color blob tracking.

Posted: Wed May 25, 2016 7:48 pm
by layne_ok
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!

Re: Creating threshold for color blob tracking.

Posted: Wed May 25, 2016 8:18 pm
by kwagyeman
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.

Re: Creating threshold for color blob tracking.

Posted: Sun Oct 30, 2016 9:04 am
by LuisK
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

Re: Creating threshold for color blob tracking.

Posted: Sun Oct 30, 2016 10:55 am
by kwagyeman
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.

Re: Creating threshold for color blob tracking.

Posted: Fri Oct 13, 2017 7:44 pm
by rommel
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?

Re: Creating threshold for color blob tracking.

Posted: Sat Oct 14, 2017 12:01 am
by kwagyeman
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.

Re: Creating threshold for color blob tracking.

Posted: Fri Dec 08, 2017 2:08 pm
by rommel
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:

Re: Creating threshold for color blob tracking.

Posted: Sat Dec 09, 2017 2:34 pm
by kwagyeman
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.

Re: Creating threshold for color blob tracking.

Posted: Thu May 24, 2018 6:47 am
by SARAVANABAVAN
What is the procedure to track the white color alone in an image ?

Re: Creating threshold for color blob tracking.

Posted: Fri May 25, 2018 11:46 pm
by kwagyeman
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())

Re: Creating threshold for color blob tracking.

Posted: Mon May 28, 2018 5:42 am
by SARAVANABAVAN
It worked ... Thank you so much...
Regards,
SARAVANABAVAN T :D

Re: Creating threshold for color blob tracking.

Posted: Sun May 19, 2019 4:21 pm
by mureytasroc
kwagyeman wrote:
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.
Has support for the more robust blob tracking been added? I'm looking to track an orange ball on a green background but need it to work in a wide range of ambient lighting conditions. Also, I need it to work when the ball is moving quickly. Is there any way to improve the color blob tracking example code so that these requirements are met?

Right now the example code doesn't seem to fulfill either of these requirements.

Re: Creating threshold for color blob tracking.

Posted: Mon May 20, 2019 1:17 am
by kwagyeman
Hi, are you using the H7? And have you controlled the camera exposure? Are you using histogram equalization? Have you set the color thresholds adequately?

The find_blobs() method is very robust but you have to put quite a lot more effort in than using the example code to get excellent results.

I need more information if you'd like help.