# How to draw a vertical line on a line in opencv python

hi guys
i have a simply question
i have a line from point x1 to point x2
(cv2.line(image, x1,x2.(1,1,1))
how can i draw a vertical line (90" degree) on this line ? and is there a way that red line show with dash lines ? and red line only show top of black line (not bottom of that (like attached image)) thanks

Getting the coordinates of the red line is a basic geometry problem, just do your homework. There are lots of resources on the internet.

Concerning the dashed line, there is no function for that in OpenCV.

you can find a sample c++ code in this page Detach blobs with a contact point - OpenCV Q&A Forum

1 Like

thanks
i found solution ``````    wndname = "Line Drawing Demo"
width, height = 500, 500
image = np.zeros((height, width, 3), dtype = np.uint8)
cv.line(image, [100,100], [200,200], (255,255,255), 1)
aX=100
aY=100
bX=200
bY=200
length=5
cv.line(image,(aX,aY), (bX,bY), (250,0,0),2)
vX = bX-aX
vY = bY-aY
mag = math.sqrt(vX + vY)
vX = vX / mag
vY = vY / mag
temp = vX
vX = 0-vY
vY = temp
cX = bX + vX * length
cY = bY + vY * length
dX = bX - vX * length
dY = bY - vY * length

cv.line(image,(bX,bY), (int(dX),int(dY)), (0,0,255),2)
cv.imshow(wndname, image)
cv.waitKey(0)
cv.destroyAllWindows()
``````