opencv的HoughLinesP函数是统计概率霍夫线变换函数,该函数能输出检测到的直线的端点 ,其函数原型为:HoughLinesP(image, rho, theta, threshold[, lines[, minLineLength[, maxLineGap]]]) -> lines
image参数表示边缘检测的输出图像,该图像为单通道8位二进制图像。
rho参数表示参数极径 以像素值为单位的分辨率,这里一般使用 1 像素。
theta参数表示参数极角 以弧度为单位的分辨率,这里使用 1度。
threshold参数表示检测一条直线所需最少的曲线交点。
lines参数表示储存着检测到的直线的参数对 的容器,也就是线段两个端点的坐标。
minLineLength参数表示能组成一条直线的最少点的数量,点数量不足的直线将被抛弃。
maxLineGap参数表示能被认为在一条直线上的亮点的最大距离。
lines = cv2.HoughLinesP(edges,1,np.pi/360,10,minLineLength=30,maxLineGap=5)
10和maxLineGap控制斜线检测的程度
lines = cv2.HoughLinesP(edges,1,np.pi/360,30,minLineLength=30,maxLineGap=5)
lines = cv2.HoughLinesP(edges,1,np.pi/360,30,minLineLength=30,maxLineGap=50)
lines = cv2.HoughLinesP(edges,0.01,np.pi/360,30,minLineLength=30,maxLineGap=50)
lines = cv2.HoughLinesP(edges,1,np.pi/3600,30,minLineLength=30,maxLineGap=50)
lines = cv2.HoughLinesP(edges,1,np.pi/360,10,minLineLength=30,maxLineGap=50)