Is there any way to use opencv to detect lines that are nearly horizontal? I've muddled my way through some of the concepts mentioned in
CodePudding user response:
You can find the angle by which the line is parallel to ground by using tan inverse.
for x1,y1,x2,y2 in lines[0]:
angle = math.degrees(math.atan((abs(y2-y1))/abs(x2-x1)))
cv2.line(img2,(x1,y1),(x2,y2),(255,0,0),1)
print(angle)
Then you can filter the lines as told by @Mario. Since above uses abs() to find difference, you will have to filter the angles only using a positive range.