Note; It's a Free Hand Curve line but not a straight or Polylines so it can be more complex.
I want to calculate the angle (in degree) of Free curve line on every bending position, and want to display where the curve is greater than 45, and less than 45 degree.
It's calculating the angle between two consecutive curve using
np.arccos()
method.
....
largest_contour = max(filter_coontour, key=cv2.contourArea)
# Simplify the curve using the Ramer-Douglas-Peucker algorithm
epsilon = 0.001 * cv2.arcLength(largest_contour, True)
simplified_curve = cv2.approxPolyDP(largest_contour, epsilon, True)
# Get the coordinates of the points along the simplified curve
curve_points = simplified_curve.reshape(-1, 2)
for i in range(1, len(curve_points)):
vector = curve_points[i] - curve_points[i - 1]
if prev_vector is not None:
dot = np.dot(vector, prev_vector)
norm = np.linalg.norm(vector) * np.linalg.norm(prev_vector)
angle = np.arccos(dot / norm) * 180 / np.pi
print("angle", angle)
....
Above are my Code, but it's not giving me the accurate angle value. please see the attached image