码迷,mamicode.com
首页 > 其他好文 > 详细

opencv 检测图像线条 霍夫线检测

时间:2020-03-21 17:48:42      阅读:94      评论:0      收藏:0      [点我收藏+]

标签:window   span   inline   line   gap   package   https   图像   nts   

 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()

 


 

技术图片
原图 ↑
 
技术图片
Canny_Result.jpg ↑
 
技术图片
HoughLines_Result.jpg ↑

opencv 检测图像线条 霍夫线检测

标签:window   span   inline   line   gap   package   https   图像   nts   

原文地址:https://www.cnblogs.com/wojianxin/p/12540251.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!