资源简介
工程训练大赛openmv二维码、色环、色块识别 可通过串口与单片机通信实现openmv的任务切换
代码片段和文件信息
# Untitled - By: zxs - 周日 9月 2 2018
import sensor image time lcd jsonmathujson
from pyb import LED
from pyb import UART
led=LED(4)
obj = [[120][1012][2210][9911]]
threshold_index = 0 # 0 for red 1 for green 2 for blue
# Color Tracking Thresholds (L Min L Max A Min A Max B Min B Max)
# The below thresholds track in general red/green/blue things. You may wish to tune them...
#(31 61 28 56 -4 42)
#(24 66 15 74 -63 71)
#(32 65 -32 -6 -3 21)
#(51 71 -21 -4 -35 -19)
thresholds = [(19 73 36 65 3 42) # generic_red_thresholds
(26 76 -50 -18 -12 33) # generic_green_thresholds
(24 77 -31 13 -50 -17)] # generic_blue_thresholds
objthresholds = [(47 80 20 46 -10 24) # generic_red_thresholds
(65 82 -13 -9 -4 8) # generic_green_thresholds
(58 72 1 5 -19 -9)] # generic_blue_thresholds
#(47 82 -26 -5 -7 7)
#(66 75 -20 -7 -3 1)
#(50 65 -1 13 -18 -1)
#(50 72 2 19 -30 -5)
graythreshold=[(100255)]
K=5000
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA) # Special 128x160 framesize for LCD Shield.
sensor.skip_frames(time = 2000)
#sensor.set_auto_gain(False) # must turn this off to prevent image washout...
uart = UART(3 115200)
uart.init(115200 bits=8 parity=None stop=1)
# 比较两个色块大小的函数
def compareBlob(blob1 blob2):
# 这里我们选择了pixels作为指标比对二者的代码
# 你也可以换用其它指标 例如 blob.area()
tmp = blob1.pixels() - blob2.pixels()
if tmp == 0:
return 0;
elif tmp > 0:
return 1;
else:
return -1;
#串口字符串指令切换功能:
# {“RGB_blocks“:“find_R“} 查找红色色块
# {“RGB_blocks“:“find_G“} 查找绿色色块
# {“RGB_blocks“:“find_B“} 查找蓝色色块
# {“RGB_blocks“:“find_RGB_blocks“} 查找最近色块颜色
# {“Code_block“:“find_Code“} 查找二维码
# {“RGB_circles“:“find_R“} 查找红色色环
# {“RGB_circles“:“find_G“} 查找绿色色环
# {“RGB_circles“:“find_B“} 查找蓝色色环
# {“circle“:“RGB“} 查找当前色环颜色
# {“LED“:“ON“} 打开LED
# {“LED“:“OFF“} 关闭LED
lcd.init() # Initialize the lcd screen.
A=5
B=0
while(True):
exsit=0;
data=[]
img = sensor.snapshot()
img.lens_corr(1.0) # strength of 1.8 is good for the 2.8mm lens.
if(uart.any()):
time.sleep(200)
d=uart.read()
da=str(d“utf-8“)
jsobj=ujson.loads(da)
for key in jsobj.keys():
print(‘key:%s value:%s‘%(keyjsobj.get(key)))
if(jsobj.get(“RGB_blocks“)==“find_R“):
A=1
else:
if(jsobj.get(“RGB_blocks“)==“find_G“):
A=2
else:
if(jsobj.get(“RGB_blocks“)==“find_B“):
A=3
else:
if(jsobj.get(“RGB_blocks“)==“find_RGB_blocks“):
A=4
else:
if(jsobj.get(“Code_block“)==“find_Code“):
- 上一篇:豆瓣电影排行爬虫
- 下一篇:西电数据挖掘作业——医院数据处理
相关资源
- 二级考试python试题12套(包括选择题和
- pywin32_python3.6_64位
- python+ selenium教程
- PycURL(Windows7/Win32)Python2.7安装包 P
- 英文原版-Scientific Computing with Python
- 7.图像风格迁移 基于深度学习 pyt
- 基于Python的学生管理系统
- A Byte of Python(简明Python教程)(第
- Python实例174946
- Python 人脸识别
- Python 人事管理系统
- 基于python-flask的个人博客系统
- 计算机视觉应用开发流程
- python 调用sftp断点续传文件
- python socket游戏
- 基于Python爬虫爬取天气预报信息
- python函数编程和讲解
- Python开发的个人博客
- 基于python的三层神经网络模型搭建
- python实现自动操作windows应用
- python人脸识别(opencv)
- python 绘图(方形、线条、圆形)
- python疫情卡UN管控
- python 连连看小游戏源码
- 基于PyQt5的视频播放器设计
- 一个简单的python爬虫
- csv文件行列转换python实现代码
- Python操作Mysql教程手册
- Python Machine Learning Case Studies
- python获取硬件信息
评论
共有 条评论