资源简介
此部分的代码是飞控循迹的openmv代码。openmv代码能够识别直线,直角,T路口,十字路口

代码片段和文件信息
class GeometryFeature:
def __init__(self img):
self.img = img
@staticmethod
def trans_line_format(line):
‘‘‘
将原来由两点坐标确定的直线,转换为 y = ax + b 的格式
‘‘‘
x1 = line.x1()
y1 = line.y1()
x2 = line.x2()
y2 = line.y2()
if x1 == x2:
# 避免完全垂直,x坐标相等的情况
x1 += 0.1
# 计算斜率 a
a = (y2 - y1) / (x2 - x1)
# 计算常数项 b
# y = a*x + b -> b = y - a*x
b = y1 - a * x1
return ab
@staticmethod
def calculate_angle(line1 line2):
‘‘‘
利用四边形的角公式, 计算出直线夹角
‘‘‘
angle = (180 - abs(line1.theta() - line2.theta()))
if angle > 90:
angle = 180 - angle
return angle
@staticmethod
def find_verticle_lines(lines angle_threshold=(70 90)):
‘‘‘
寻找相互垂直的两条线
‘‘‘
return GeometryFeature.find_interserct_lines(lines angle_threshold=angle_threshold)
@staticmethod
def find_interserct_lines(lines angle_threshold=(1090) window_size=None):
‘‘‘
根据夹角阈值寻找两个相互交叉的直线, 且交点需要存在于画面中
‘‘‘
line_num = len(lines)
for i in range(line_num -1):
for j in range(i line_num):
# 判断两个直线之间的夹角是否为直角
angle = GeometryFeature.calculate_angle(lines[i] lines[j])
# 判断角度是否在阈值范围内
if not(angle >= angle_threshold[0] and angle <= angle_threshold[1]):
continue
# 判断交点是否在画面内
if window_size is not None:
# 获取串口的尺寸 宽度跟高度
win_width win_height = window_size
# 获取直线交点
intersect_pt = GeometryFeature.calculate_intersection(lines[i] lines[j])
if intersect_pt is None:
# 没有交点
continue
x y = intersect_pt
if not(x >= 0 and x < win_width and y >= 0 and y < win_height):
# 交点如果没有在画面中
continue
return (lines[i] lines[j])
return None
@staticmethod
def calculate_intersection(line1 line2):
‘‘‘
计算两条线的交点
‘‘‘
a1 = line1.y2() - line1.y1()
b1 = line1.x1() - line1.x2()
c1 = line1.x2()*line1.y1() - line1.x1()*line1.y2()
a2 = line2.y2() - line2.y1()
b2 = line2.x1() - line2.x2()
c2 = line2.x2() * line2.y1() - line2.x1()*line2.y2()
if (a1 * b2 - a2 * b1) != 0 and (a2 * b1 - a1 * b2) != 0:
cross_x = int((b1*c2-b2*c1)/(a1*b2-a2*b1))
cross_y = int((c1*a2-c2*a1)/(a1*b2-a2*b1))
return (cross_x cross_y)
return None
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 3118 2019-07-28 11:33 Openmv\GeometryFeature.py
文件 5414 2019-07-28 11:33 Openmv\main.py
目录 0 2019-07-28 11:33 Openmv
----------- --------- ---------- ----- ----
8532 3
- 上一篇:矩阵键盘+lcd12864液晶显示
- 下一篇:寻迹小车驱动和主控电路图
相关资源
- openMV串口通讯_(2).zip
- OPENMV舵机云台颜色追踪学习资料.zip
- 全国大学生电子设计竞赛_板球控制系
- 基于OPENMV的颜色追踪 与ST32一次性传
- openMVG例程
- openmv pcb原理图 5积分
- 详细的openmv教程
- amg8833+openmv热成像人脸跟随测温云台
- openmv-boards-master(1).zip
- openmv3 m7 pcb工程 ad18
- OpenMv教程由入门到精通
- openMVS+openMVG+VS2015 配置全过程方法介绍
- openmv后视镜.zip
- openmv-boards-master.zip
- 基于STM32F407的OPENMV设计资料
- openmv+stm32+as608
- 基于OpenMV与STM32的寻球小车.7z
- OpenMV固件资料
- Openmv与STM32通信.zip
- 匿名openmv与拓空者pro代码
- 匿名拓空者Pro_TI版资料包-20190728.rar
- 可见光室内定位装置设计
- J3D多目三维重建系统V1.9
- openmv_windows驱动.zip
- OpenMV4 电路原理图.pdf
- openmv_windows驱动.rar
- openmv巡线小车优化程序
- 基于openmv和舵机机械臂的物料颜色识
- OPENMV中文参考资料
- 板球系统.txt
评论
共有 条评论