, are not at the center blob area

Hi, I’m tried to identify the nuts position to rotate it in the desidered angle. I have an H7 cam, with the script I wrote the center of the blob is correct only if the camera is centered on the vertical of the blob to find.
Its the right behaviour?

Many Thanks in advance


# 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 = (65, 255)
#thresholds = (255, 88)

sensor.skip_frames(time = 2000)
sensor.set_auto_gain(True) # must be turned off for color tracking
sensor.set_auto_whitebal(True) # 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=400, area_threshold=1000, merge=False):
        if blob.area()<7000:


The centroid is calculated on pixels detected within the nut. You may wish to call find_circles() on the ROIs of the Nuts to refine the position.

I’ll try it, thanks for your reply.
My next problem will be how to identify the position of the nut border to understand his rotation angle.


You can determine the rotation angle by looking at the corners of the nut and seeing how much area is filled. E.g use find_blobs() again on the nut ROI looking for the background color and you should get some smaller blobs that represent the edges. You can then get the number of pixels in these areas. Once you have that info you can make an equation that computes the rotation angle.

Alternatively, use find-line segments in the ROI and do some magic too.

Good suggestions, i’ll try to extract top left and top right quadrant and to compute the blank area differences.
Many thanks


Hi I use this thread for the same project.
I would to know if is possible to rotate rectangle for find when the image area are specular.

To understand how many degree the bolt is rotated I count how many pixel are in the blue roi’s to comparing each other, I would rotate the rectangle that contain the nut until the 2 blue areas report the same pixel number, then translate this in degree or other units.

Do you think is possible?

Thanks in advance

(apologies for my english)


There’s a min_rect() attribute of the blob which returns the rectangle of it… also, there’s a centerline value too.

Please look into all the methods that blobs have. We compute a lot of stats.