# 设置颜色阈值,这里以红色物体为例
# (L Min, L Max, A Min, A Max, B Min, B Max)
# 调整L值范围以减少白色背景的影响
red_threshold = (30, 100, 15, 127, 15, 127) # 较暗的红色物体
# red_threshold = (20, 100, 15, 127, 15, 127) # 较亮的红色物体
while(True):
clock.tick()
img = sensor.snapshot()
# 使用颜色阈值查找色块
blobs = img.find_blobs([red_threshold], pixels_threshold=200, area_threshold=200)
# 在找到的色块周围绘制矩形
for blob in blobs:
img.draw_rectangle(blob.rect())
img.draw_cross(blob.cx(), blob.cy())
print(clock.fps()) |