logo

求助,先识别矩形后在矩形范围内识别蓝色

2018-09-15 22:15
K
cmlv

import sensor,time,pyb,math#引用模块sensor(摄像头传感器),time(追踪经过时间),pyb(与电路板相关的功能),math(数学函数库)。

from pyb import Pin, Timer, LED, UART#从模块pyb中引入LED,定时器,UART,Pin类

#黑色点阈值

blue_threshold = [(25, 85, -87, 92, -88, -14)]#对于灰度图像,每个元组需要包含两个值 - 最小灰度值和最大灰度值。

#xy平面误差数据

err_x = 0

err_y = 0

sensor.reset()#初始化摄像头传感器。

sensor.set_pixformat(sensor.RGB565)#设置灰度信息RGB565像素模式。每像素为16位、2字节。5位用于红色,6位用于绿色,5位用于蓝色。,

sensor.set_framesize(sensor.QQVGA)#设置图像大小,80x60 分辨率的相机传感器。

sensor.skip_frames(20)#相机自检几张图片,使用 20个快照,让相机图像在改变相机设置后稳定下来。 20 作为普通参数传输, 例如: skip_frames(10) 跳过 10 帧。您应在改变相机设置后调用该函数。

sensor.set_auto_whitebal(False)#关闭白平衡

clock = time.clock()#打开时钟,时钟对象

while(True):

clock.tick()#开始追踪运行时间。返回以毫秒计的通电后的运行时间

img = sensor.snapshot()#使用相机拍摄一张照片,并返回 image 对象。

rects =img.find_rects(threshold=10000)

print (len(rects))

for j in range(len(rects)):

print (rects[j].rect())#寻找blob

blobs = img.find_blobs(thresholds=blue_threshold,roi=rects[j].rect())#返回一个包括每个色块的色块对象的列表。

for i in range(len(blobs)):

img.draw_cross(blobs[j].cx(),blobs[j].cy())#调试使用在图像上绘制一个十字。 您可以单独传递x,y或作为元组(x,y)传递。,

img.draw_rectangle(blobs[j].rect())#在图像上绘制一个矩形。 您可以单独传递x,y,w,h或作为元组(x,y,w,h)传递。

err_x = int(60 - blobs[i].cy())#cy返回色块(int)的中心y位置。

err_y = int(blobs[i].cx() - 80)#cx返回色块(int)的中心x位置。

blobs = img.find_blobs(thresholds=blue_threshold,roi=rects[j].rect()),这句为何有错,TypeError: function missing 1 required positional arguments

2018-09-18 19:11
X
Yuan

blobs = img.find_blobs(blue_threshold,roi=rects[j].rect())

去掉thresholds=