【Openmv】多颜色识别常用初始化_自用

# 多颜色跟踪示例
#
# 这个例子显示了使用OpenMV的多色跟踪。

import sensor, image, time

# 颜色跟踪阈值(L Min, L Max, A Min, A Max, B Min, B Max)
# 下面的阈值跟踪一般红色/绿色的东西。你不妨调整他们...
thresholds = [(47, 68, 55, 103, 25, 63), # red_thresholds
              (60, 75, -80, -40, 30, 50), # green_thresholds
              (29, 49, -5, 25, -63, -35)] # blue_thresholds

sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)
sensor.set_auto_gain(False) # must be turned off for color tracking
sensor.set_auto_whitebal(False) # must be turned off for color tracking
sensor.set_vflip(True)
sensor.set_hmirror(True)
clock = time.clock()

# 只有比“pixel_threshold”多的像素和多于“area_threshold”的区域才被
# 下面的“find_blobs”返回。 如果更改相机分辨率,
# 请更改“pixels_threshold”和“area_threshold”。 “merge = True”合并图像中所有重叠的色块。

while(True):
    clock.tick()
    img = sensor.snapshot().lens_corr(1.8) 
    for blob in img.find_blobs(thresholds, pixels_threshold=200, area_threshold=200):
        img.draw_rectangle(blob.rect())
        img.draw_cross(blob.cx(), blob.cy())
    print(clock.fps())

测距



import sensor, image, time

yellow_threshold   = ( 56,   83,    5,   57,   63,   80)

sensor.reset()
sensor.set_pixformat(sensor.RGB565) 
sensor.set_framesize(sensor.QQVGA) 
sensor.skip_frames(10)
sensor.set_auto_whitebal(False)
sensor.set_vflip(True)
sensor.set_hmirror(True)
clock = time.clock() 

K=5000

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

    blobs = img.find_blobs([yellow_threshold])
    if len(blobs) == 1:     
        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
        print(length)


在这里插入图片描述
11点30分,2018年12月21日



import sensor, image
import time, math
from servo import Servos
from machine import I2C, Pin
i2c = I2C(sda=Pin('P5'), scl=Pin('P4'))
servo = Servos(i2c, address=0x40, freq=50, min_us=650, max_us=2800, degrees=180)

red_threshold     =   (47, 68, 55, 103, 25, 63)
green_threshold   =   (45, 70, -60, -40, 20, 60)
blue_threshold    =   (29, 49, -5, 25, -63, 
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值