def get_chessboard_lines(binary_img):
edges = cv2.Canny(binary_img,50,120)
cv2.imshow('image',edges)
k = cv2.waitKey(0) & 0xFF
if k == 27:
cv2.destroyAllWindows()
lines_data = cv2.HoughLines(edges,1,np.pi/180,110)
parallel_lines = []
vertical_lines = []
for rho,theta in lines_data[0]:
#print 'rho: '+str(rho)+'theta: '+str(theta)
if 2>theta > 1:
vertical_lines.append([theta,rho])
elif theta < 1 :
parallel_lines.append([theta,rho])
elif theta>3:
parallel_lines.append([theta,rho])
a = np.cos(theta)
b = np.sin(theta)
x0 = a*rho
y0 = b*rho
x1 = int(x0 + 1000*(-b))
y1 = int(y0 + 1000*(a))
x2 = int(x0 - 1000*(-b))
y2 = int(y0 - 1000*(a))
cv2.line(edges,(x1,y1),(x2,y2),(255,0,0),2)
cv2.imshow('image',edges)
k = cv2.waitKey(0) & 0xFF
if k == 27:
cv2.destroyAllWindows()
vertical_lines=sorted(vertical_lines,key=lambda x: abs(x[1]))
parallel_lines=sorted(parallel_lines,key=lambda x: abs(x[1]))
return vertical_lines,parallel_lines
评论列表
文章目录