Check out the video:
Is there any way to improve how well this locks to the sheet?
The ROI on the left side looks for the “T” intersection of the table lines. My code looks for line segments and throws out all but the horizontal and vertical lines that are greater than a certain length. But you can see for whatever reason, sometimes it detects a line at the bottom of the ROI for no reason. The horizontal works quite well.
Here’s the code for that ROI. The resultant X/Y drives where the 7 checkbox ROIs are.
for r in img.find_line_segments(SEARCHBOX, merge_distance=5, max_theta_difference=20): #print(x,": ",abs(r.x2() - r.x1()),abs(r.y2() - r.y1()),"Diff") # see if we have a verticle line if abs(r.y2() - r.y1()) > abs(r.x2() - r.x1()) : # only verticle y_diff = abs(r.y2() - r.y1()) if (y_diff > 15) and y_diff > longest_y : #make sure it's not just a dot offset_x = round(abs(r.x2() + r.x1()) / 2 ) # get the average x position x_line = r if abs(r.y2() - r.y1()) < abs(r.x2() - r.x1()) : # only horizontal x_diff = abs(r.x2() - r.x1()) #print(x_diff) if (x_diff > 20) and x_diff > longest_x : #make sure it's not just a dot offset_y = round((r.y2() + r.y1()) / 2 ) - 460 # get the average x position y_line = r #print(offset_y) x=x+1 if x_line != 0 : img.draw_line(x_line.x1(),x_line.y1(),x_line.x2(),x_line.y2(),color = (255),thickness=1) if y_line != 0 : img.draw_line(y_line.x1(),y_line.y1(),y_line.x2(),y_line.y2(),color = (255),thickness=1)
I tried using find_rects() dirrectly on the checkboxes and was not successful. And it sucks up a lot of buffer memory with an ROI that big. Any help would be great.