当前位置:网站首页>Preparation Notes: opencv learning: line detection
Preparation Notes: opencv learning: line detection
2022-07-20 16:06:00 【Raine_ Yang】
Line detection generally uses functions HoughLines or HoughLinesP, The second method is the probabilistic version Hoygh Transformation , This function is an optimized version , Faster calculation
import cv2
import numpy as np
cap = cv2.VideoCapture(0)
while True:
ret, frame = cap.read()
x, y = frame.shape[0:2]
small_frame = cv2.resize(frame, (int(y / 2), int(x / 2)))
gray = cv2.cvtColor(small_frame, cv2.COLOR_BGR2GRAY)
edges = cv2.Canny(gray, 50, 120)
minLineLength = 10
maxLineGap = 5
lines = cv2.HoughLinesP(edges, 1, np.pi / 180, 100, minLineLength, maxLineGap)
for x1, y1, x2, y2 in lines[0]:
cv2.line(small_frame, (x1, y1), (x2, y2), (0, 255, 0), 2)
cv2.imshow("lines", small_frame)
if cv2.waitKey(1) & 0xFF == ord("q"):
break
cap.release()
cv2.destroyAllWindows()
Program description :
1 x, y = frame.shape[0:2]
small_frame = cv2.resize(frame, (int(y / 2), int(x / 2)))
gray = cv2.cvtColor(small_frame, cv2.COLOR_BGR2GRAY)
Zoom the image to a quarter of the original and convert it into a grayscale image , To reduce the amount of calculation
2 edges = cv2.Canny(gray, 50, 120)
Use Canny Function to extract edges
3 lines = cv2.HoughLinesP(edges, 1, np.pi / 180, 100, minLineLength, maxLineGap)
Use HoughLineP Extracting lines
Parameter description :
Parameters 1: Binary image to be processed
Parameters 2:rho and theta, The general values 1 and np.pi / 180
Parameters 3: threshold , Below this threshold will be ignored
Parameters 4: Minimum line length , Less than this length will be ignored
Parameters 5: Maximum segment gap , Greater than this gap will be considered as two lines
边栏推荐
- Immediate assertion and concurrent assertion in SystemVerilog
- How to operate international crude oil futures to open an account safely?
- 【MATLAB项目实战】基于MATLAB的发票识别(含GUI界面)
- Almost died suddenly! An employee of an Internet company in Hangzhou was sent to ICU ward for myocarditis after staying up late and working overtime continuously. The company: she worked overtime volu
- 【redis入门系列】初识 redis以及redis的安装
- Go Printf 如何进行格式化输出,结构体格式化输出,一站式解决所有烦恼
- GC 机制简介
- 【C语言】动态内存管理、柔性数组
- 【SCADA案例】mySCADA助力Vib公司实现产线现代化升级
- vim中单词操作方法总结
猜你喜欢
golang 接口变量的赋值和方法的调用
吃透Chisel语言.19.Chisel组合电路(一)——Chisel组合电路与Chisel条件语句
Which is the best test management tool?
【深度】新派LaaS协议Elephant:重振DeFi赛道发展的关键
[depth] the new LAAS agreement elephant: the key to revitalizing the development of the defi track
juc包下常用工具类
运营商的时代之旅:种下5.5G的魔豆,攀上数字化的天空花园
"Still too young", the intern spent 2 minutes to solve the bug, and the old programmer's response was intriguing
【ARM】新唐NUC977移植WK2124驱动
【MATLAB项目实战】基于MATLAB的发票识别(含GUI界面)
随机推荐
Era journey of operators: plant 5.5G magic beans and climb the Digital Sky Garden
吃透Chisel语言.15.Chisel模块详解(二)——Chisel模块嵌套和ALU实现
塔望3W消费战略-消费本位研究法:焦点座谈会(Focus Group)
[ERROR] COLLATION ‘utf8_unicode_ci‘ is not valid for CHARACTER SET ‘latin1‘
数据科学与计算智能:内涵、范式与机遇
面试必问之项目的组成
Bleu score implementation
DS(StackAnQueueBasiApplication)
dns劫持是什麼意思?常見的劫持有哪些?
shell编程(十) : [shell基础] 控制脚本
【大型电商项目开发】缓存-分布式锁-缓存一致性解决-45
【小5聊】通过Task例子来简单理解下串行和并行如何节省执行时间
DS(LineLinkStorStruct)
Xcelium XRUN用户手册
How to operate international crude oil futures to open an account safely?
MySQL eight part essay, preparing for the golden nine silver ten
浮点数探秘
uni-app - Refused to display ‘xxx‘ in a frame because an ancestor violates the following Content Sec
备赛笔记:Opencv学习:直线检测
数据中台、商业智能BI业务访谈(一):行业和业务研究的准备