use of

iam using openmv cam m4 and in this lilnk( ) you have given that will Return the centroid x position of the blob.My doubt is that suppose if i track red colour object and i vary the distance from red coloured object to openmv cam upto what extent the cam will give accurate value.
thank you,

Hi, the camera has a field of view. So, unless the object is exactly in the center of the field of view the object’s cx() value will move around.

That said, if you were to place the object exactly in the center of the camera’s view the cx() value will not change as the distance changes then.

ohh, thank you sir but in my project i have to find the position of different white coloured and red coloured objects at one shot how can i do that by using openmv kindly help me to overcome this problem.
thank you,

Hi, you showed me this before. Please see go to examples → Color Tracking → Single RGB565 color tracking and then edit the color thresholds in that script using Tools → Machine Vision → Threshold Editor.

The script will show you all the positions of everything in the field of view as long as you set the thresholds correctly.

thank you very much sir

thank you very much sir,So in order to calculate the distance of various blobs we need not to calculate angle of field of view, Field of view and all .openmv cam itself will give the correct position of different blobs.

Hi, it’s not really possible to get the distance to and object using just one camera and vision reliablely. The size of the object on screen is related to the distance in a 1/d^2 way. E.g. as the object gets farther away the number of pixels in the object changes minimally related to the distance. That said, if the object is really close the relationship is linearish then and you can use a lookup table to map pixels to distance (or a piece wise linear function).

Whatever the case, you have to hand calculate the piece wise lookup table by measuring the object at each distance and recording the number of pixels. Then, you build interpolate any new pixel value to a distance between whatever measurements you made previously. In code this looks like a bunch of if statements.

hi,somehow gives the approximate value its enough for me.In my project i have to take the snapshot and than i have to send the different value to the raspberry pi how can i do this.

Hi, please search the forums for serial you’ll find many examples for doing that.

Here’s an example:

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

import sensor, image, time

threshold_index = 0 # 0 for red, 1 for green, 2 for blue

# Color Tracking Thresholds (L Min, L Max, A Min, A Max, B Min, B Max)
# The below thresholds track in general red/green/blue things. You may wish to tune them...
thresholds = [(30, 100, 15, 127, 15, 127), # generic_red_thresholds
              (30, 100, -64, -8, -32, 32), # generic_green_thresholds
              (0, 30, 0, 64, -128, 0)] # generic_blue_thresholds

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.

from pyb import UART

# Always pass UART 3 for the UART number for your OpenMV Cam.
# The second argument is the UART baud rate. For a more advanced UART control
# example see the BLE-Shield driver.
uart = UART(3, 19200, timeout_char = 1000)

    img = sensor.snapshot()
    for blob in img.find_blobs([thresholds[threshold_index]], pixels_threshold=200, area_threshold=200, merge=True):
        uart.write(str( + '\n')