Blob.cx(), blob.cy() 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

Lenny

# 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.reset()
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.VGA)
sensor.set_windowing(320,320)
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
sensor.set_auto_exposure(True)
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=400, area_threshold=1000, merge=False):
        if blob.area()<7000:
            print(blob.area())
            img.draw_rectangle(blob.rect())
            img.draw_cross(blob.cx(), blob.cy())
    #print(clock.fps())

imgTest

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.

Lenny

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

Lenny.

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

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)

Lenny

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.