opencv 检测图像线条 霍夫线检测
Posted wojianxin
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了opencv 检测图像线条 霍夫线检测相关的知识,希望对你有一定的参考价值。
1 # Writer : wojianxinygcl@163.com 2 3 # Data : 2020.3.21 4 5 import cv2 as cv 6 7 import numpy as np 8 9 img = cv.imread(‘../paojie.jpg‘) 10 11 gray = cv.cvtColor(img,cv.COLOR_BGR2GRAY) 12 13 # 50,150 为二值化时的阈值 apertureSize为Sobel滤波器的大小 14 15 edges = cv.Canny(gray,50,150,apertureSize = 3) 16 17 cv.imshow(‘Canny Result‘,edges) 18 19 cv.imwrite(‘Canny_Result.jpg‘,edges) 20 21 # 高效的霍夫线检测算法 22 23 # edges : 二值图像 24 25 # 1 : ρ 26 27 # pi/180: θ 28 29 # 100 : Accumulator threshold parameter. Only those lines are returned that get enough votes ( >threshold ). 30 31 # minLineLength : Minimum length of line. Line segments shorter than this are rejected. 32 33 # maxLineGap : Maximum allowed gap between line segments to treat them as a single line. 34 35 lines = cv.HoughLinesP(edges,1,np.pi/180,100,minLineLength=100,maxLineGap=10) 36 37 for line in lines: 38 39 x1,y1,x2,y2 = line[0] 40 41 cv.line(img,(x1,y1),(x2,y2),(0,255,0),2) 42 43 cv.imshow(‘HoughLines Result‘,img) 44 45 cv.imwrite(‘HoughLines_Result.jpg‘,img) 46 47 cv.waitKey(0) 48 49 cv.destroyAllWindows()
以上是关于opencv 检测图像线条 霍夫线检测的主要内容,如果未能解决你的问题,请参考以下文章
即使图像在 Python 中的 OpenCV 中包含多行,霍夫线变换也只能识别一行