Spiegazione della routine Tracciamento a 10 colori->singolo_colore_scala di grigi_blob_tracciamento tracciamento blocco colore in scala di grigi a colore singolo
Tutorial video 4 - Riconoscimento del colore: https://singtown.com/learn/49993/
# 单色灰度色块跟踪示例
#
# 这个例子展示了使用OpenMV Cam的单色灰度跟踪。
import sensor, image, time, math
# Color Tracking Thresholds (Grayscale Min, Grayscale Max)
# 下面的灰度阈值设置为只能找到非常明亮的白色区域。
thresholds = (245, 255)
sensor.reset()
#初始化摄像头,reset()是sensor模块里面的函数
sensor.set_pixformat(sensor.GRAYSCALE)
#设置图像色彩格式,有RGB565色彩图和GRAYSCALE灰度图两种
sensor.set_framesize(sensor.VGA)
#设置图像像素大小
sensor.skip_frames(time = 2000)
sensor.set_auto_gain(False) # 颜色跟踪必须关闭自动增益
sensor.set_auto_whitebal(False) # 颜色跟踪必须关闭白平衡
clock = time.clock()
# 只有比“pixel_threshold”多的像素和多于“area_threshold”的区域才被
# 下面的“find_blobs”返回。 如果更改相机分辨率,
# 请更改“pixels_threshold”和“area_threshold”。 “merge = True”合并图像中所有重叠的色块。
while(True):
clock.tick()
img = sensor.snapshot()
for blob in img.find_blobs([thresholds], pixels_threshold=100, area_threshold=100, merge=True):
# These values depend on the blob not being circular - otherwise they will be shaky.
if blob.elongation() > 0.5:
img.draw_edges(blob.min_corners(), color=0)
img.draw_line(blob.major_axis_line(), color=0)
img.draw_line(blob.minor_axis_line(), color=0)
# 这些值始终是稳定的。
img.draw_rectangle(blob.rect(), color=127)
img.draw_cross(blob.cx(), blob.cy(), color=127)
# 注意 - 色块的rotation旋转是0-180内的唯一。
img.draw_keypoints([(blob.cx(), blob.cy(), int(math.degrees(blob.rotation())))], size=40, color=127)
print(clock.fps())
Spiegazione ufficiale della funzione del documento cinese di Singtown Technology OpenMV: