import sensor, image, time
# 颜色追踪的例子,一定要控制环境的光,保持光线是稳定的。
light_blue_threshold = (63, 90, -20, -5, -15, 10)
object_num = 0
point_cx_sum = 0
point_cy_sum = 0
i = 0
point_cx = [0 for x in range(100)]
point_cy = [0 for x in range(100)]
sensor.reset() # 初始化摄像头
sensor.set_pixformat(sensor.RGB565) # 格式为 RGB565.
sensor.set_framesize(sensor.VGA)
sensor.set_windowing((400,320)) # 由于像素过多必须设置ROI
sensor.skip_frames(time = 2000) # 跳过2000s,使新设置生效,并自动调节白平衡
sensor.set_auto_gain(False) # 关闭自动自动增益。默认开启的,在颜色识别中,一定要关闭白平衡。
sensor.set_auto_whitebal(False)#关闭白平衡。白平衡是默认开启的,在颜色识别中,一定要关闭白平衡。
clock = time.clock() # 追踪帧率
while(True):
clock.tick() # Track elapsed milliseconds between snapshots().
img1 = sensor.snapshot() # 从感光芯片获得一张图像
i = i + 1
blobs1 = img1.find_blobs([light_blue_threshold],x_stride=50,y_stride=50,merge=True,pixels_threshold=10000)
if blobs1:
#如果找到了目标颜色
for b1 in blobs1:
#迭代找到的目标颜色区域
object_num = object_num + 1
point_cx[object_num-1] += b1[5]
point_cy[object_num-1] += b1[6]
if i%3!=0:
object_num = 0
if i%3==0: # 三张图取平均
i=0
for j in range(object_num):
point_cx[j] = int(point_cx[j]/3)
point_cy[j] = int(point_cy[j]/3)
img1.draw_cross(point_cx[j], point_cy[j],size=10,color=(0,0,0))
point_cx[j] = 0
point_cy[j] = 0
object_num = 0
【openmv】microPython实现多个口罩识别追踪检测
最新推荐文章于 2024-07-24 11:54:20 发布