I need to detect whether a blob is on the left side or right side of the camera. Is it possible to get this information? If yes how?
Yes, find_blobs() returns a list of blobs. Each blob encodes their x/y centroid. You can then check that against a threshold for the left or right side of the image.
Thank you for your response. After running a few tests this is what i came up with to determine if the black colored rectangular blob is on the left, right or in front of the camera. Could you please confirm if this logic is correct?
for blob in img.find_blobs(thresholds, pixels_threshold=200, area_threshold=200):
# These values depend on the blob not being circular - otherwise they will be shaky.
#if blob.elongation() > 0.5:
img.draw_edges(blob.min_corners(), color=(255, 0, 0))
img.draw_line(blob.major_axis_line(), color=(0, 255, 0))
img.draw_line(blob.minor_axis_line(), color=(0, 0, 255))
# These values are stable all the time.
img.draw_rectangle(blob.rect())
img.draw_cross(blob.cx(), blob.cy())
# Note - the blob rotation is unique to 0-180 only.
img.draw_keypoints(
[(blob.cx(), blob.cy(), int(math.degrees(blob.rotation())))], size=20
)
d = {}
(d["x"], d["y"], d["w"], d["h"]) = blob.rect()
if(d["x"]==0):
d["object_name"]="left_black_border"
elif(d["x"]>200):
d["object_name"]="right_black_border"
elif(d["x"]>100 and d["x"]<200):
d["object_name"]="front_black_border"
else:
d["object_name"]="unknown_black_border"
Might want to change your code to this.
x, y, w, h = blob.rect()
if(x==0):
d["object_name"]="left_black_border"
elif(x>200):
d["object_name"]="right_black_border"
elif(x>100 and x<200):
d["object_name"]="front_black_border"
else:
d["object_name"]="unknown_black_border"
I wouldn’t compare to zero either but use a threshold for the left_black_border. Values are almost never exactly zero. E.g. f(x<=100)
. Also, change the elif(x>200)
to elif(x>=200)
.