automatic_grayscale_color_tracking.py

# この作品はMITライセンスの下で提供されています。
# Copyright (c) 2013-2023 OpenMV LLC. 全著作権所有。
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# 自動グレースケールカラートラッキングの例
#
# この例では、OpenMV Camを使った単一色の自動グレースケールカラートラッキングを示します。

import csi
import time

print("Letting auto algorithms run. Don't put anything in front of the camera!")

csi0 = csi.CSI()
csi0.reset()
csi0.pixformat(csi.GRAYSCALE)
csi0.framesize(csi.QVGA)
csi0.snapshot(time=2000)
csi0.auto_gain(False)  # カラートラッキングでは無効にする必要があります
csi0.auto_whitebal(False)  # カラートラッキングでは無効にする必要があります
clock = time.clock()

# 画像中央にあるものの色しきい値を取得します。
r = [(320 // 2) - (50 // 2), (240 // 2) - (50 // 2), 50, 50]  # QVGAの中央50x50。

print(
    "Auto algorithms done. Hold the object you want to track in front of the camera in the box."
)
print(
    "MAKE SURE THE COLOR OF THE OBJECT YOU WANT TO TRACK IS FULLY ENCLOSED BY THE BOX!"
)
for i in range(60):
    img = csi0.snapshot()
    img.draw_rectangle(r)

print("Learning thresholds...")
threshold = [128, 128]  # 中間のグレースケール値。
for i in range(60):
    img = csi0.snapshot()
    hist = img.get_histogram(roi=r)
    lo = hist.get_percentile(
        0.01
    )  # ヒストグラムの1%地点のCDFを取得します(必要に応じて調整してください)!
    hi = hist.get_percentile(
        0.99
    )  # ヒストグラムの99%地点のCDFを取得します(必要に応じて調整してください)!
    # パーセンタイル値の平均を取ります。
    threshold[0] = (threshold[0] + lo.value) // 2
    threshold[1] = (threshold[1] + hi.value) // 2
    for blob in img.find_blobs(
        [threshold], pixels_threshold=100, area_threshold=100, merge=True, margin=10
    ):
        img.draw_detection(blob)
        img.draw_rectangle(r)

print("Thresholds learned...")
print("Tracking colors...")

while True:
    clock.tick()
    img = csi0.snapshot()
    for blob in img.find_blobs(
        [threshold], pixels_threshold=100, area_threshold=100, merge=True, margin=10
    ):
        img.draw_detection(blob)
    print(clock.fps())

results matching ""

    No results matching ""