• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

OpenMv测距测尺寸

武飞扬头像
IT阳晨。
帮助1

一、原理(以小球为例)

测距: 相同尺寸,距离越近,像素点越多,所以距离与直径像素点个数成反比:K = 距离*直径的像素

测尺寸: 相同距离,尺寸越大,直径像素点越多,所以物体尺寸与直径像素点个数成正比:实际大小 = K1*直径的像素

因此:

需要测距的时候,只需要用同一小球,先修改物体的颜色阈值,让OpenMv能够框出小球,再在一个已知距离点打印物体的像素点长度,就可以用K = 距离*直径的像素求出关系系数K,然后再通过公式打印出距离。

需要测量大小的时候,先测出小球的直径,然后在一固定位置(测量任何尺寸必须固定在同一位置)打印小球的直径像素点,再通过实际大小 = K1*直径的像素公式求出比例系数K1,然后通过公式打印出尺寸大小。

二、代码

# Hello World Example
#
# Welcome to the OpenMV IDE! Click on the green run arrow button below to run the script!


# Measure the distance
#
# This example shows off how to measure the distance through the size in imgage
# This example in particular looks for yellow pingpong ball.

import sensor, image, time

# For color tracking to work really well you should ideally be in a very, very,
# very, controlled enviroment where the lighting is constant...
yellow_threshold   = (12, 100, -69, 67, 119, 16)
# You may need to tweak the above settings for tracking green things...
# Select an area in the Framebuffer to copy the color settings.

sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.RGB565) # use RGB565.
sensor.set_framesize(sensor.QQVGA) # use QQVGA for speed.
sensor.skip_frames(10) # Let new settings take affect.
sensor.set_auto_whitebal(False) # turn this off.
clock = time.clock() # Tracks FPS.

#the value should be measured
#K = 距离*直径的像素
K=544
#实际大小 = K1*直径的像素
K1=0.038

while(True):
    clock.tick() # Track elapsed milliseconds between snapshots().
    img = sensor.snapshot() # Take a picture and return the image.

    blobs = img.find_blobs([yellow_threshold])
    if len(blobs) == 1:
        # Draw a rect around the blob.
        b = blobs[0]
        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
        size = K1*Lm
        h = K1*b[3]
        w = K1*b[2]
        #print(length)
        #print(Lm)
        #print(size)
        print("高:%s cm,宽:%s",h,w)

    #print(clock.fps()) # Note: Your OpenMV Cam runs about half as fast while
    # connected to your computer. The FPS should increase once disconnected.
学新通

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgfkhfa
系列文章
更多 icon
同类精品
更多 icon
继续加载