Here you go, you have to tune if for your application:
Code: Select all
# Counting vertical lines example script.
# Adjust the threshold value to max it so only really strong lines appear... A higher threshold for stronger lines.
# Adjust the theta_margin value to control the merging of lines with similar angles.
# Adjsut the rho_margin value to control the mergining of lines that are physically nearby.
# Note that you may detect two lines on either side of some object. To filter this out... make the rho margin higher.
import sensor, image
sensor.skip_frames(time = 2000)
# Undo negative rho...
t = line.theta() if (line.rho() >= 0) else (line.theta() + 180)
# If the line is vertical it should have a theta close to 0/360
return ((t < 10) or (t > 350)) # You'll want to play with these settings here...
img = sensor.snapshot()
lines = list(filter(line_filter, img.find_lines(x_stride=1, y_stride=1,
threshold = 1000, theta_margin = 20, rho_margin = 10))) # You'll want to play with these settings here...
for line in lines: img.draw_line(line.line(), color=127)
print("Lines Seen %d" % len(lines))