OpenMv测距测尺寸
一、原理(以小球为例)
测距: 相同尺寸,距离越近,像素点越多,所以距离与直径像素点个数成反比: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
系列文章
更多
同类精品
更多
-
photoshop保存的图片太大微信发不了怎么办
PHP中文网 06-15 -
Android 11 保存文件到外部存储,并分享文件
Luke 10-12 -
《学习通》视频自动暂停处理方法
HelloWorld317 07-05 -
word里面弄一个表格后上面的标题会跑到下面怎么办
PHP中文网 06-20 -
photoshop扩展功能面板显示灰色怎么办
PHP中文网 06-14 -
微信公众号没有声音提示怎么办
PHP中文网 03-31 -
excel下划线不显示怎么办
PHP中文网 06-23 -
excel打印预览压线压字怎么办
PHP中文网 06-22 -
怎样阻止微信小程序自动打开
PHP中文网 06-13 -
TikTok加速器哪个好免费的TK加速器推荐
TK小达人 10-01