# 設置顏色閾值,這里以紅色物體為例
# (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()) |