资源简介
OpenMV识别交通灯例程,仅需根据环境修改交通灯红、绿、黄颜色阈值即可,思路清晰,识别率高。
代码片段和文件信息
# Untitled - By: CZK - 周五 5月 10 2019
import sensor imagetimelcd pyb
from pyb import UARTTimerLED
#
red_threshold_01 = (60 88 23 63 6 -25)
green_threshold_01 = (85 98 -90 1 4 -63)
yellow_threshold_01 = (64 99 -23 18 14 66)
#
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)#320*240
sensor.set_framesize(sensor.VGA)
sensor.set_windowing((240 240))
#sensor.snapshot().save(“/snapshot-%d.jpg“ % pyb.rng()) # Save Pic.
sensor.skip_frames()
sensor.set_auto_whitebal(False) #关闭白平衡
sensor.set_auto_gain(False) #关闭自动增益
clock = time.clock()
lcd.init() #Initialize the lcd screen.
uart = UART(31152008None1) #创建串口对象
data = []
LED_Red = LED(1)
LED_Green = LED(2)
LED_Blue = LED(3)
BLUE_LED_PIN = 3
def expand_roi(roi):
# set for QQVGA 160*120
extra = 5
win_size = (640 480)
(x y width height) = roi
new_roi = [x-extra y-extra width+2*extra height+2*extra]
if new_roi[0] < 0:
new_roi[0] = 0
if new_roi[1] < 0:
new_roi[1] = 0
if new_roi[2] > win_size[0]:
new_roi[2] = win_size[0]
if new_roi[3] > win_size[1]:
new_roi[3] = win_size[1]
return tuple(new_roi)
sensor.skip_frames(time = 2000) # Give the user time to get ready.
tim = Timer(4freq=1) # create a timer object using timer 4
#tim.callback(tick)
tim.deinit()
while(True):
img = sensor.snapshot()
clock.tick() # Track elapsed milliseconds between snapshots().
blobs_red = img.find_blobs([red_threshold_01] area_threshold=150)
blobs_green = img.find_blobs([green_threshold_01] area_threshold=150)
blobs_yellow = img.find_blobs([yellow_threshold_01] area_threshold=150)
if blobs_yellow:
#如果找到了目标颜色
#print(blobs)
#print(“黄灯“)
numjtdy = numjtdy+1
for blob in blobs_yellow:
#迭代找到的目标颜色区域
is_circle = False
max_circle = None
max_radius = -1
new_roi = expand_roi(blob.rect())
for c in img.find_circles(threshold = 2000 x_margin = 20 y_margin = 20 r_margin = 10 roi=new_roi):
is_circle = True
# img.draw_circle(c.x() c.y() c.r() color = (255 255 255))
if c.r() > max_radius:
max_radius = c.r()
max_circle = c
if is_circle:
# 如果有对应颜色的圆形 标记外框
# Draw a rect around the blob.
img.draw_rectangle(new_roi) # rect
img.draw_rectangle(blob.rect()) # rect
#用矩形标记出目标颜色区域
img.draw_cross(blob[5] blob[6]) # cx cy
相关资源
- openmv颜色识别代码
- python使用dlib对人脸识别的范例程序
- python操作海康威视相机------例程由海
- python趣味编程100例99个
- openmv 识别3个颜色 工程训练大赛
- 基于决策树的天气大数据回归例程
- OpenMV4四代原理图与PCB.zip
- 小车基于openmv摄像头的红灯识别
- openmv定点代码
- 2020电赛G题openmv程序
- Openmv主控物料分拣小车拣乒乓球小车
- Openmv主控物料分拣小车拣乒乓球小车
- BP神经网络_Python实习_包含鸢尾花分类
- 官方OpenMV4.zip
- openmv智能小车寻线代码
- OpenMV形状识别And颜色识别.py
- 颜色识别+串口通信——华北五省ope
- openmv识别红绿蓝物块颜色,并输出物
- 工训物流小车颜色及二维码识别
- OPENMV用作光流模组程序
- Python logging 日志例程
- openmv识别红色,串口通信,可用于信
- python语言程序设计基础第2版例程
- 基于OpenMV与STM32的寻球小车.rar
- openmv目标检测代码
-
xm
l_cascade.py opencv_traincascade.exe ope - OpenMV视觉识别 舵机云台颜色跟踪
- openmv识别物块颜色,并输出物块距离
- openmv识别特定颜色且打印坐标到串口
- MicroPython for Esp8266 驱动MPU6050例程
评论
共有 条评论