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())
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.
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.