Python3与OpenCV3.3 图像处理(十九)--直线检测
来源:互联网 发布:网络机柜出厂检验报告 编辑:程序博客网 时间:2024/06/11 00:30
这节课能容不多,基本上是遵循规律编写代码即可
import cv2 as cvimport numpy as npdef line_detection(img): """方法一""" gray=cv.cvtColor(img,cv.COLOR_RGB2GRAY) edges=cv.Canny(gray,50,150,apertureSize=3) lines=cv.HoughLines(edges,1,np.pi/180,200) #以下为标准做法 for line in lines: rho,theta=line[0] 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) cv.line(img,(x1,y1),(x2,y2),(0,0,255),2) cv.imshow("img lines",img)def line_detect_possible(img): """方法二""" gray = cv.cvtColor(img, cv.COLOR_RGB2GRAY) edges = cv.Canny(gray, 50, 150, apertureSize=3) #minLineLength:线段最大长度 #maxLineGap:点和线段之间允许的间隔大小 lines = cv.HoughLinesP(edges, 1, np.pi / 180, 200,minLineLength=50,maxLineGap=10) for line in lines: x1,y1,x2,y2=line[0] cv.line(img, (x1, y1), (x2, y2), (0, 0, 255), 2) cv.imshow("img lines", img)src=cv.imread('lines.jpg')cv.imshow('def',src)line_detect_possible(src)cv.waitKey(0)cv.destroyAllWindows()
阅读全文
0 0
- Python3与OpenCV3.3 图像处理(十九)--直线检测
- Python3与OpenCV3.3 图像处理(二十)--圆检测
- Python3与OpenCV3.3 图像处理(五)--图像运算
- Python3与OpenCV3.3 图像处理(十六)--图像金字塔
- Python3与OpenCV3.3 图像处理(十七)--图像梯度
- Python3与OpenCV3.3 图像处理(四)--色彩空间
- Python3与OpenCV3.3 图像处理(六)--ROI
- Python3与OpenCV3.3 图像处理(七)--洪填充
- Python3与OpenCV3.3 图像处理(八)--模糊
- Python3与OpenCV3.3 图像处理(十一)--图像直方图
- Python3与OpenCV3.3 图像处理(十二)--图像直方图应用
- Python3与OpenCV3.3 图像处理(十五)--图像二值化
- Python3与OpenCV3.3 图像处理(二)--图像基本操作
- Python3与OpenCV3.3 图像处理(十)--EPF
- Python3与OpenCV3.3 图像处理(十三)--反射投影
- Python3与OpenCV3.3 图像处理(十四)--模板匹配
- Python3与OpenCV3.3 图像处理(补)--第十五节补充
- Python3与OpenCV3.3 图像处理(一)--环境搭建与简单DEMO
- kindeditor文本编辑器配置和使用方法
- Java中8种基本数据类型及其默认值
- python基础第三天
- python练习1:素数
- 初识Docker
- Python3与OpenCV3.3 图像处理(十九)--直线检测
- 在Windows下配置php7 和Apache2.4
- 《内外兼修》读书心得
- IPSEC win10与xp通信实验
- java从入门到精通
- JavaDay06--Homework(方法重载和重写的区别,构造方法,继承类)
- 查找指定元素在数组中的个数
- Delphi XE8环境下使用windows下API函数创建一个空白窗口
- 20171219