#aaa是cv.read图片.
img = aaaa.copy()
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
ret, binary = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
#cv2.imwrite("13里面二值化的图片.png", binary)
# binary = cv2.morphologyEx(binary, cv2.MORPH_CLOSE, kernel, anchor=(2, 0), iterations=2) # 二值化.
cv2.imwrite('debug1.png',binary)
# 可以看到处理后基本的文字方向.
#进行直线检测.
edges = cv2.Canny(binary, 50, 100, apertureSize=3)
# 霍夫曼直线检测
#cv2.imwrite('13里面的canny边缘化图片.png',edges )
edges=255-binary #========我这里不适用canny来边缘检测,直接255减去他, 感觉精度更高.
gao=edges.shape[0]
chang=edges.shape[1]
cv2.imwrite('debug2.png',edges)
lines = cv2.HoughLinesP(edges, 0.1, 0.1*np.pi / 180, 1, minLineLength=(gao+chang)/100, maxLineGap=3)
#########0.01*pi是调优过的参数!!!!!!!!,我们只要比较长的线. 这些线更有标志性.