机器视觉-角点检测算法

基于OpenMV硬件平台

识别原理:

1.寻找直线

2.计算相交直线的交点坐标

3.判断直线是否垂直

实验效果:


实验代码:

import sensor, image, time
 
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QQVGA)
clock = time.clock()
 
while(True):
    clock.tick()
    img = sensor.snapshot()
    lines = img.find_lines(threshold = 1000, theta_margin = 25, rho_margin = 25)
    for i in range(0,len(lines)-1):
        for j in range(i+1,len(lines)):
            ax1 = lines[i].x1()
            ay1 = lines[i].y1()
            ax2 = lines[i].x2()
            ay2 = lines[i].y2()
            if(ax1 == ax2):
                ax1 = ax1 + 0.01
            k0 = (ay2 - ay1)/(ax2 - ax1)      # 第一条直线斜率
            b0 = ay1 - k0*ax1                 # 第一条直线截距
            bx1 = lines[j].x1()
            by1 = lines[j].y1()
            bx2 = lines[j].x2()
            by2 = lines[j].y2()
            if(bx1 == bx2):
                bx1 = bx1 + 0.01
            k1 = (by2 - by1)/(bx2 - bx1)      # 第二条直线斜率
            b1 = by1 - k1*bx1                 # 第二条直线截距
            if(k0 == k1):
                k0 = k0 + 0.1
            # 计算角点坐标
            intersectionx = (b1-b0)/(k0-k1)
            intersectiony = k0*intersectionx + b0
            img.draw_cross(int(intersectionx), int(intersectiony),color = (0, 255, 0))
            # 判断是否垂直
            kk = float(k0) * float(k1)
            if(kk > -1.3 and kk < -0.7 ):
                img.draw_circle(int(intersectionx), int(intersectiony),10,color = (255, 0, 0))
    for l in lines:
        img.draw_line(l.line(), color = (255, 0, 255))
    print("FPS %f" % clock.fps())
 

  • 1
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值