Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have two perpendicualr lines how to draw the Angle between them

What I have tried:

mport numpy as np
import cv2

btn_down = False

def get_points(im):
# Set up data to send to mouse handler
data = {}
data['im'] = im.copy()
data['lines'] = []

# Set the callback function for any mouse event
cv2.imshow("Image", im)
cv2.setMouseCallback("Image", mouse_handler, data)
cv2.waitKey(0)

# Convert array to np.array in shape n,2,2
points = np.uint16(data['lines'])

return points, data['im']

def mouse_handler(event, x, y, flags, data):
global btn_down

if event == cv2.EVENT_LBUTTONUP and btn_down:
#if you release the button, finish the line
btn_down = False
data['lines'][0].append((x, y)) #append the seconf point
cv2.circle(data['im'], (x, y), 3, (0, 0, 255),5)
cv2.line(data['im'], data['lines'][0][0], data['lines'][0][1], (0,0,255), 2)
cv2.imshow("Image", data['im'])

elif event == cv2.EVENT_MOUSEMOVE and btn_down:
#thi is just for a ine visualization
image = data['im'].copy()
cv2.line(image, data['lines'][0][0], (x, y), (0,0,0), 1)
cv2.imshow("Image", image)

elif event == cv2.EVENT_LBUTTONDOWN and len(data['lines']) < 10:
btn_down = True
data['lines'].insert(0,[(x, y)]) #prepend the point
cv2.circle(data['im'], (x, y), 3, (0, 0, 255), 5, 16)
cv2.imshow("Image", data['im'])


# Running the code
img = cv2.imread("98.jpg", 1)
pts, final_image = get_points(img)
cv2.imshow('Image', final_image)
print (pts)
cv2.waitKey(0)
Posted
Updated 18-Nov-20 6:28am

1 solution

I put my line vertical or horizontal then rotate it about some point to make and get an angle. Easier than doing geometry.

c++ - Rotate a point around a point with OpenCV - Stack Overflow[^]

(Yeah, I know it's C++; it's the "concept". That's for all the nattering nabobs of negativism)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900