Creating threshold for color blob tracking.

Using the 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?


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.

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?


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.

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?

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.

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?

:nerd: :ugeek:

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.

What is the procedure to track the white color alone in an image ?

Verbatim example code:

# 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.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.

    img = sensor.snapshot()
    for blob in img.find_blobs([thresholds], pixels_threshold=100, area_threshold=100, merge=True):

It worked … Thank you so much…

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.

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.

Hi, I am a newbie to openmv… I am trying to track red , yellow, green and blue colors along with barcodes. I am able to read barcodes with ease but I am having trouble in setting threshold for all the colors mentioned above. Can you suggest me a proper methodology to go about it.

Use the Tools->Machine Vision->Threshold Editor