|
|
@ -59,7 +59,7 @@ denotes they are the parameters of possible lines in the image. (Image courtesy: |
|
|
|
|
|
|
|
|
|
|
|
![](images/houghlines2.jpg) |
|
|
|
![](images/houghlines2.jpg) |
|
|
|
|
|
|
|
|
|
|
|
Hough Tranform in OpenCV |
|
|
|
Hough Transform in OpenCV |
|
|
|
========================= |
|
|
|
========================= |
|
|
|
|
|
|
|
|
|
|
|
Everything explained above is encapsulated in the OpenCV function, \*\*cv2.HoughLines()\*\*. It simply returns an array of :math:(rho, |
|
|
|
Everything explained above is encapsulated in the OpenCV function, \*\*cv2.HoughLines()\*\*. It simply returns an array of :math:(rho, |
|
|
@ -78,7 +78,8 @@ gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) |
|
|
|
edges = cv2.Canny(gray,50,150,apertureSize = 3) |
|
|
|
edges = cv2.Canny(gray,50,150,apertureSize = 3) |
|
|
|
|
|
|
|
|
|
|
|
lines = cv2.HoughLines(edges,1,np.pi/180,200) |
|
|
|
lines = cv2.HoughLines(edges,1,np.pi/180,200) |
|
|
|
for rho,theta in lines[0]: |
|
|
|
for line in lines: |
|
|
|
|
|
|
|
rho,theta = line[0] |
|
|
|
a = np.cos(theta) |
|
|
|
a = np.cos(theta) |
|
|
|
b = np.sin(theta) |
|
|
|
b = np.sin(theta) |
|
|
|
x0 = a*rho |
|
|
|
x0 = a*rho |
|
|
@ -123,10 +124,9 @@ import numpy as np |
|
|
|
img = cv2.imread('dave.jpg') |
|
|
|
img = cv2.imread('dave.jpg') |
|
|
|
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) |
|
|
|
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) |
|
|
|
edges = cv2.Canny(gray,50,150,apertureSize = 3) |
|
|
|
edges = cv2.Canny(gray,50,150,apertureSize = 3) |
|
|
|
minLineLength = 100 |
|
|
|
lines = cv2.HoughLinesP(edges,1,np.pi/180,100,minLineLength=100,maxLineGap=10) |
|
|
|
maxLineGap = 10 |
|
|
|
for line in lines: |
|
|
|
lines = cv2.HoughLinesP(edges,1,np.pi/180,100,minLineLength,maxLineGap) |
|
|
|
x1,y1,x2,y2 = line[0] |
|
|
|
for x1,y1,x2,y2 in lines[0]: |
|
|
|
|
|
|
|
cv2.line(img,(x1,y1),(x2,y2),(0,255,0),2) |
|
|
|
cv2.line(img,(x1,y1),(x2,y2),(0,255,0),2) |
|
|
|
|
|
|
|
|
|
|
|
cv2.imwrite('houghlines5.jpg',img) |
|
|
|
cv2.imwrite('houghlines5.jpg',img) |
|
|
|