OpenMV识别颜色源码

# 导入文件
import sensor, image, time, pyb
from pyb import UART,Pin,Timer
import json

# 初始化摄像头
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time=2000)  # 等待摄像头稳定
sensor.set_auto_gain(False)    # 关闭自动增益。在颜色识别中,需要关闭自动增益
sensor.set_auto_whitebal(False)
clock = time.clock()

tim = Timer(4, freq=1000) # Frequency in Hz
led_dac = tim.channel(1, Timer.PWM, pin=Pin("P7"), pulse_width_percent=50)
led_dac.pulse_width_percent(100)
# 定义颜色阈值
red_threshold = (33, 100, 17, 127, -25, 52)    # 红色阈值
green_threshold = (54, 20, -47, -18, -15, 41)  # 绿色阈值
yellow_threshold = (40, 100, -56, 81, 25, 127) # 黄色阈值

# 初始化串口
uart = pyb.UART(3, 115200)  # 使用UART3,波特率115200
# 定义帧头和帧尾
FRAME_HEADER = 0xAA
FRAME_TAIL = 0x55

# 上一次发送的颜色
last_detected_color = None

def find_max_blob(blobs):
    max_blob = None

    max_size = 0
    for blob in blobs:
        if blob.pixels() > max_size:
            max_size = blob.pixels()
     
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小邓分享官

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值