识别色块并发送色块的中心坐标,但之后发现这个坐标与色块在实际所处平面当中的位置参数仍存在误差,譬如我现在使用的标定棋谱每格子长为35mm,当我置于如图所示时,坐标应为(70,70),但实际测得(52,52),所以我在b[5],b[6]前乘了比例系数——>1.35*b[5],1.35*b[6]
【问题:除此以外还有什么方法可直接把IDE视图和打印出的来参数与实际尺寸无限趋近于相等吗?】@kidswong999 @yuan
import sensor, image, time
import pyb
from pyb import UART
# 颜色追踪的例子,一定要控制环境的光,保持光线是稳定的。
green_threshold = (18, 100, -128, -20, -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)
uart = UART(3, 19200)
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 > 2000:
start = pyb.millis() # 更新时间
# output_str=(b[5],b[6])
output_str="@%d.%d#" % (1.35*b[5],1.35*b[6])
print(output_str)
uart.write(output_str)OpenMV只知道的单位是像素,而不是长度。
如果OpenMV与平面的距离变了,你的那个比例系数就变了。
所以只能自己根据情况计算一下比例系数。
@kidswong999 好的明白了,蟹蟹小小智~