コンテンツへスキップ

Ultralytics YOLOv8 🚀を使用したVisionEyeビューオブジェクトマッピング

VisionEye Object Mappingとは?

Ultralytics YOLOv8VisionEyeは、人間の目の観察精度をシミュレートすることで、コンピューターが対象物を識別し、ピンポイントで特定する機能を提供します。この機能により、人間の目が特定の視点から細部を観察するのと同じように、コンピューターが特定の物体を識別し、焦点を合わせることができる。

サンプル

ビジョンアイビュー 物体追跡機能付きVisionEyeビュー 距離計算付きVisionEyeビュー
VisionEyeによるオブジェクトマッピングUltralytics YOLOv8 VisionEyeを使用したオブジェクト・トラッキングによるビュー・オブジェクト・マッピングUltralytics YOLOv8 VisionEyeを使用した距離計算付きビューUltralytics YOLOv8
VisionEyeによるオブジェクトマッピングUltralytics YOLOv8 VisionEyeを使用したオブジェクト・トラッキングによるビュー・オブジェクト・マッピングUltralytics YOLOv8 VisionEyeを使用した距離計算付きビューUltralytics YOLOv8

VisionEyeによるオブジェクトマッピングYOLOv8

import cv2

from ultralytics import YOLO
from ultralytics.utils.plotting import Annotator, colors

model = YOLO("yolov8n.pt")
names = model.model.names
cap = cv2.VideoCapture("path/to/video/file.mp4")
w, h, fps = (int(cap.get(x)) for x in (cv2.CAP_PROP_FRAME_WIDTH, cv2.CAP_PROP_FRAME_HEIGHT, cv2.CAP_PROP_FPS))

out = cv2.VideoWriter("visioneye-pinpoint.avi", cv2.VideoWriter_fourcc(*"MJPG"), fps, (w, h))

center_point = (-10, h)

while True:
    ret, im0 = cap.read()
    if not ret:
        print("Video frame is empty or video processing has been successfully completed.")
        break

    results = model.predict(im0)
    boxes = results[0].boxes.xyxy.cpu()
    clss = results[0].boxes.cls.cpu().tolist()

    annotator = Annotator(im0, line_width=2)

    for box, cls in zip(boxes, clss):
        annotator.box_label(box, label=names[int(cls)], color=colors(int(cls)))
        annotator.visioneye(box, center_point)

    out.write(im0)
    cv2.imshow("visioneye-pinpoint", im0)

    if cv2.waitKey(1) & 0xFF == ord("q"):
        break

out.release()
cap.release()
cv2.destroyAllWindows()
import cv2

from ultralytics import YOLO
from ultralytics.utils.plotting import Annotator, colors

model = YOLO("yolov8n.pt")
cap = cv2.VideoCapture("path/to/video/file.mp4")
w, h, fps = (int(cap.get(x)) for x in (cv2.CAP_PROP_FRAME_WIDTH, cv2.CAP_PROP_FRAME_HEIGHT, cv2.CAP_PROP_FPS))

out = cv2.VideoWriter("visioneye-pinpoint.avi", cv2.VideoWriter_fourcc(*"MJPG"), fps, (w, h))

center_point = (-10, h)

while True:
    ret, im0 = cap.read()
    if not ret:
        print("Video frame is empty or video processing has been successfully completed.")
        break

    annotator = Annotator(im0, line_width=2)

    results = model.track(im0, persist=True)
    boxes = results[0].boxes.xyxy.cpu()

    if results[0].boxes.id is not None:
        track_ids = results[0].boxes.id.int().cpu().tolist()

        for box, track_id in zip(boxes, track_ids):
            annotator.box_label(box, label=str(track_id), color=colors(int(track_id)))
            annotator.visioneye(box, center_point)

    out.write(im0)
    cv2.imshow("visioneye-pinpoint", im0)

    if cv2.waitKey(1) & 0xFF == ord("q"):
        break

out.release()
cap.release()
cv2.destroyAllWindows()
import math

import cv2

from ultralytics import YOLO
from ultralytics.utils.plotting import Annotator

model = YOLO("yolov8s.pt")
cap = cv2.VideoCapture("Path/to/video/file.mp4")

w, h, fps = (int(cap.get(x)) for x in (cv2.CAP_PROP_FRAME_WIDTH, cv2.CAP_PROP_FRAME_HEIGHT, cv2.CAP_PROP_FPS))

out = cv2.VideoWriter("visioneye-distance-calculation.avi", cv2.VideoWriter_fourcc(*"MJPG"), fps, (w, h))

center_point = (0, h)
pixel_per_meter = 10

txt_color, txt_background, bbox_clr = ((0, 0, 0), (255, 255, 255), (255, 0, 255))

while True:
    ret, im0 = cap.read()
    if not ret:
        print("Video frame is empty or video processing has been successfully completed.")
        break

    annotator = Annotator(im0, line_width=2)

    results = model.track(im0, persist=True)
    boxes = results[0].boxes.xyxy.cpu()

    if results[0].boxes.id is not None:
        track_ids = results[0].boxes.id.int().cpu().tolist()

        for box, track_id in zip(boxes, track_ids):
            annotator.box_label(box, label=str(track_id), color=bbox_clr)
            annotator.visioneye(box, center_point)

            x1, y1 = int((box[0] + box[2]) // 2), int((box[1] + box[3]) // 2)  # Bounding box centroid

            distance = (math.sqrt((x1 - center_point[0]) ** 2 + (y1 - center_point[1]) ** 2)) / pixel_per_meter

            text_size, _ = cv2.getTextSize(f"Distance: {distance:.2f} m", cv2.FONT_HERSHEY_SIMPLEX, 1.2, 3)
            cv2.rectangle(im0, (x1, y1 - text_size[1] - 10), (x1 + text_size[0] + 10, y1), txt_background, -1)
            cv2.putText(im0, f"Distance: {distance:.2f} m", (x1, y1 - 5), cv2.FONT_HERSHEY_SIMPLEX, 1.2, txt_color, 3)

    out.write(im0)
    cv2.imshow("visioneye-distance-calculation", im0)

    if cv2.waitKey(1) & 0xFF == ord("q"):
        break

out.release()
cap.release()
cv2.destroyAllWindows()

visioneye 論争

名称 タイプ デフォルト 説明
color tuple (235, 219, 11) 線とオブジェクトの重心の色
pin_color tuple (255, 0, 255) ビジョンアイ・ピンポイントカラー

お問い合わせは、Ultralytics Issue Sectionまたは下記のディスカッション・セクションまでお気軽にお寄せください。

よくあるご質問

VisionEye Object Mapping をUltralytics YOLOv8 で使い始めるには?

VisionEye Object Mapping をUltralytics YOLOv8 で使い始めるには、まず、Ultralytics YOLO パッケージを pip 経由でインストールする必要があります。次に、ドキュメントに記載されているサンプルコードを使用して、VisionEyeによるオブジェクト検出を設定します。以下は、簡単な例です:

import cv2

from ultralytics import YOLO

model = YOLO("yolov8n.pt")
cap = cv2.VideoCapture("path/to/video/file.mp4")

while True:
    ret, frame = cap.read()
    if not ret:
        break

    results = model.predict(frame)
    for result in results:
        # Perform custom logic with result
        pass

    cv2.imshow("visioneye", frame)
    if cv2.waitKey(1) & 0xFF == ord("q"):
        break

cap.release()
cv2.destroyAllWindows()

Ultralytics YOLOv8 を使用した VisionEye の物体追跡機能の主な特徴は何ですか?

VisionEye's object tracking withUltralytics YOLOv8 ビデオフレーム内の物体の動きを追うことができます。主な機能は以下の通り:

  1. リアルタイム物体追跡:オブジェクトの動きに追従します。
  2. オブジェクトの識別:YOLOv8 の強力な検出アルゴリズムを利用。
  3. 距離計算:オブジェクトと指定したポイント間の距離を計算します。
  4. 注釈と視覚化:追跡されたオブジェクトの視覚的マーカーを提供します。

以下は、VisionEyeによるトラッキングを実演する簡単なコード・スニペットです:

import cv2

from ultralytics import YOLO

model = YOLO("yolov8n.pt")
cap = cv2.VideoCapture("path/to/video/file.mp4")

while True:
    ret, frame = cap.read()
    if not ret:
        break

    results = model.track(frame, persist=True)
    for result in results:
        # Annotate and visualize tracking
        pass

    cv2.imshow("visioneye-tracking", frame)
    if cv2.waitKey(1) & 0xFF == ord("q"):
        break

cap.release()
cv2.destroyAllWindows()

包括的なガイドについては、VisionEye Object Mapping with Object Trackingをご覧ください。

VisionEyeのYOLOv8 モデルで距離を計算するには?

VisionEye およびUltralytics YOLOv8 による距離計算では、フレーム内の指定点から検出された物体の距離を決定する。これは、自律走行や監視などのアプリケーションで有用な空間解析機能を強化します。

簡単な例を挙げよう:

import math

import cv2

from ultralytics import YOLO

model = YOLO("yolov8s.pt")
cap = cv2.VideoCapture("path/to/video/file.mp4")
center_point = (0, 480)  # Example center point
pixel_per_meter = 10

while True:
    ret, frame = cap.read()
    if not ret:
        break

    results = model.track(frame, persist=True)
    for result in results:
        # Calculate distance logic
        distances = [
            (math.sqrt((box[0] - center_point[0]) ** 2 + (box[1] - center_point[1]) ** 2)) / pixel_per_meter
            for box in results
        ]

    cv2.imshow("visioneye-distance", frame)
    if cv2.waitKey(1) & 0xFF == ord("q"):
        break

cap.release()
cv2.destroyAllWindows()

詳細な手順については、距離計算機能付きVisionEyeを参照してください。

オブジェクトのマッピングとトラッキングにUltralytics YOLOv8 を使う理由は?

Ultralytics YOLOv8 は、そのスピード、正確さ、統合のしやすさで定評があり、オブジェクトのマッピングとトラッキングに最適です。主な利点は以下の通りです:

  1. 最先端の性能:リアルタイムで高精度の物体検出を実現。
  2. 柔軟性:検出、追跡、距離計算など様々なタスクをサポート。
  3. コミュニティとサポート:豊富なドキュメントと活発なGitHubコミュニティによるトラブルシューティングと機能拡張。
  4. 使いやすさ:直感的なAPIは複雑なタスクを簡素化し、迅速な展開と反復を可能にします。

アプリケーションや特典の詳細については、Ultralytics YOLOv8 。

VisionEyeを他の機械学習ツール(Comet 、ClearML )と統合する方法は?

Ultralytics YOLOv8 は、Comet やClearML のような様々な機械学習ツールとシームレスに統合することができ、実験の追跡、共同作業、再現性を高めることができます。 YOLOv5 とComet使用方法、および YOLOv8 とClearML統合 方法については、詳細なガイドに従ってください。

さらに詳しい説明と統合例については、Ultralytics 統合ガイドをご覧ください。



作成日:2023-12-18 更新日:2024-07-05
著者:glenn-jocher(13),IvorZhu331(1),RizwanMunawar(1)

コメント