如果直接在条件语句后面添加延时函数的话,发现坐标是会根据延时参数延迟相应时间,不过视图图像也会跟着卡顿延迟,问,有什么法子,可实现视图呈现实时动态,而坐标打印却是保持有时间间隔的呢?
@kidswong999
import sensor, image, time
# 颜色追踪的例子,一定要控制环境的光,保持光线是稳定的。
green_threshold = (57, 100, -128, -32, -128, 127)
#设置绿色的阈值,括号里面的数值分别是L A B 的最大值和最小值(minL, maxL, minA,
# maxA, minB, maxB),LAB的值在图像左侧三个坐标图中选取。如果是灰度图,则只需
#设置(min, max)两个数字即可。
sensor.reset() # 初始化摄像头
sensor.set_pixformat(sensor.RGB565) # 格式为 RGB565.
sensor.set_framesize(sensor.QQVGA) # 使用 QQVGA 速度快一些
sensor.skip_frames(10) # 跳过10帧,使新设置生效
sensor.set_auto_whitebal(False)
#关闭白平衡。白平衡是默认开启的,在颜色识别中,一定要关闭白平衡。
clock = time.clock() # 追踪帧率
while(True):
clock.tick() # Track elapsed milliseconds between snapshots().
img = sensor.snapshot().lens_corr(strength = 1.7, zoom = 1.0)
blobs = img.find_blobs([green_threshold])
if blobs:
#如果找到了目标颜色
for b in blobs:
#迭代找到的目标颜色区域
# Draw a rect around the blob.
img.draw_rectangle(b[0:4]) # rect
#用矩形标记出目标颜色区域
img.draw_cross(b[5], b[6]) # cx, cy
#在目标颜色区域的中心画十字形标记
# output_str="[%d,%d]" % (find_blobs.cx(),find_blobs.cy()) #方式1
# print(clock.fps()) # 注意: 你的OpenMV连到电脑后帧率大概为原来的一半
print("(x,y)=",(b[5],b[6]))
time.sleep(1500)判断一下间隔时间
import sensor, image, time
# 颜色追踪的例子,一定要控制环境的光,保持光线是稳定的。
green_threshold = (57, 100, -128, -32, -128, 127)
#设置绿色的阈值,括号里面的数值分别是L A B 的最大值和最小值(minL, maxL, minA,
# maxA, minB, maxB),LAB的值在图像左侧三个坐标图中选取。如果是灰度图,则只需
#设置(min, max)两个数字即可。
sensor.reset() # 初始化摄像头
sensor.set_pixformat(sensor.RGB565) # 格式为 RGB565.
sensor.set_framesize(sensor.QQVGA) # 使用 QQVGA 速度快一些
sensor.skip_frames(10) # 跳过10帧,使新设置生效
sensor.set_auto_whitebal(False)
#关闭白平衡。白平衡是默认开启的,在颜色识别中,一定要关闭白平衡。
clock = time.clock() # 追踪帧率
start = time.ticks_ms() # get value of millisecond counter 获取毫秒计数器的值
while(True):
clock.tick() # Track elapsed milliseconds between snapshots().
img = sensor.snapshot().lens_corr(strength = 1.7, zoom = 1.0)
blobs = img.find_blobs([green_threshold])
if blobs:
#如果找到了目标颜色
for b in blobs:
#迭代找到的目标颜色区域
# Draw a rect around the blob.
img.draw_rectangle(b[0:4]) # rect
#用矩形标记出目标颜色区域
img.draw_cross(b[5], b[6]) # cx, cy
#在目标颜色区域的中心画十字形标记
delta = time.ticks_diff(time.ticks_ms(), start)#计算间隔时间
if delta > 1500:
start = time.ticks_ms() # 更新时间
print("(x,y)=",(b[5],b[6]))
#串口操作在这里@kidswong999 小小智,运行了以上代码后,出现这个,是需要另外再定义过吗?

我改了一下函数,测试了一下是没问题的
import sensor, image, time
import pyb
# 颜色追踪的例子,一定要控制环境的光,保持光线是稳定的。
green_threshold = (57, 100, -128, -32, -128, 127)
#设置绿色的阈值,括号里面的数值分别是L A B 的最大值和最小值(minL, maxL, minA,
# maxA, minB, maxB),LAB的值在图像左侧三个坐标图中选取。如果是灰度图,则只需
#设置(min, max)两个数字即可。
sensor.reset() # 初始化摄像头
sensor.set_pixformat(sensor.RGB565) # 格式为 RGB565.
sensor.set_framesize(sensor.QQVGA) # 使用 QQVGA 速度快一些
sensor.skip_frames(10) # 跳过10帧,使新设置生效
sensor.set_auto_whitebal(False)
#关闭白平衡。白平衡是默认开启的,在颜色识别中,一定要关闭白平衡。
clock = time.clock() # 追踪帧率
start = pyb.millis() # get value of millisecond counter 获取毫秒计数器的值
while(True):
clock.tick() # Track elapsed milliseconds between snapshots().
img = sensor.snapshot().lens_corr(strength = 1.7, zoom = 1.0)
blobs = img.find_blobs([green_threshold])
if blobs:
#如果找到了目标颜色
for b in blobs:
print(pyb.millis())
#迭代找到的目标颜色区域
# Draw a rect around the blob.
img.draw_rectangle(b[0:4]) # rect
#用矩形标记出目标颜色区域
img.draw_cross(b[5], b[6]) # cx, cy
#在目标颜色区域的中心画十字形标记
delta = pyb.elapsed_millis(start)#计算间隔时间
if delta > 1500:
start = pyb.millis() # 更新时间
print("(x,y)=",(b[5],b[6]))
#串口操作在这里@kidswong999 谢谢小小智哈~