-1

i have searched about line detection algorithm in opencv

and i found here good answer

but i cant understand this mathematical operations

lefty = int((-x*vy/vx) + y)
righty = int(((gray.shape[1]-x)*vy/vx)+y)

can anyone explain it to me please

i tried to understand anything ,

[vx,vy,x,y] = cv2.fitLine(cnt,cv2.cv.CV_DIST_L2,0,0.01,0.01)

and i have found that x,y is the center of the contour, but what is vx , vy ???.

Thanks :)

Salo7ty
  • 475
  • 5
  • 18

1 Answers1

2

Copying from Opencv documentation:

where (vx, vy) is a normalized vector collinear to the line.

If you want to find the angle of the line you simply call:

#find angle in degrees
angle = math.atan(vy / vx) * 180 / math.pi 
Baraa
  • 1,476
  • 1
  • 16
  • 19
  • thanks very much but i have another one question if you know it, what is this params after cv.CV_DIST_L2 mean ?? – Salo7ty Mar 31 '20 at 08:49
  • DistType is: is the distance used for line fitting, CV_DIST_L2, is the standard unweighted least-squares fit. It's also written there in the documentation link that I have shared. Also, please refer to this answer it has a good explanation https://stackoverflow.com/a/15184899/4734439 – Baraa Mar 31 '20 at 08:53