【openMV】openMV之测距

import sensor, image, time

target_threshold   = (0, 59, -11, 30, -27, 18)#色域值为手动测量得

sensor.reset() 
sensor.set_pixformat(sensor.RGB565) 
sensor.set_framesize(sensor.QQVGA) 
sensor.skip_frames(10) 
sensor.set_auto_whitebal(False) #关闭白平衡
clock = time.clock()

K=566.25#基准设置为5000后让目标距离摄像头10cm后,((k/打印出的数字)*10)替换设定值。

while(True):
    clock.tick() 
    img = sensor.snapshot() 

    blobs = img.find_blobs([target_threshold])
    if len(blobs) == 1:     #当返回色块列表长度为1时
        b = blobs[0]        #将返回数据赋值给b
        img.draw_rectangle(b[0:4]) # rect
        img.draw_cross(b[5], b[6]) # cx, cy
        ########高度计算###########
        Lm = (b[2]+b[3])/2
        length = K/Lm
        ########高度计算###########
        print(length)       #打印高度

串口输出:12.58333

实测距离:12.3

发布了88 篇原创文章 · 获赞 39 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/weixin_43444989/article/details/96477249