Seher Elbasan
Seher Elbasan

Reputation: 11

How to do object detection with yolo in isaac sim script editor

I want to perform object detection with the Yolo model using the Isaac SIM script editor. I connected a conveyor and a line with packages on it and a camera. I am trying to do real time object detection from this camera. The yolov8n.pt model remains downloaded for a long time. and isaac sim says "not respnding". When I downloaded and run the yolo model beforehand, AttributeError: 'ViewportAPI' object has no attribute 'capture_next_frame' I'm getting an error like this.

I tried methods like "get_viewport_window" and similar. I keep getting similar omni.kit... errors.I am experiencing these problems in isaac sim 2023.1.1 version. I downloaded isaac sim 4.0.0 version but I kept getting the same errors.What could be the reason for this? I'm new to omniverse and I need your solutions. thank you in advance. I leave the code and the error I get below.

import omni.kit
import omni.ui
from omni.kit.viewport.window import ViewportWindow
import omni.usd
from pxr import UsdGeom, Gf
import cv2
import numpy as np
from ultralytics import YOLO

# YOLOv8 modelini yükleme
model = YOLO("C:/Users/ov-user/Desktop/yolov8n.pt")

# Viewport oluşturma
viewport_window = ViewportWindow('SimpleViewport', width=1280, height=720)
viewport_widget = viewport_window.viewport_api

# Viewport API'ye erişim
viewport_api = viewport_widget
viewport_api.resolution = (640, 480)
viewport_api.camera_path = '/World/Camera_box_count'

# Kamera yolunu ayarlama
stage = omni.usd.get_context().get_stage()
camera_prim = stage.GetPrimAtPath('/World/Camera_box_count')

# Sabit dönüşüm matrisi oluşturma
fixed_translate = Gf.Vec3d(100, 100, 100)  # Gerekli olduğu şekilde değerleri ayarlayın
fixed_rotate = Gf.Quatd(1, 0, 0, 0)  # Gerekli olduğu şekilde değerleri ayarlayın

# Dönüşüm işlemini uygulama
xform_api = UsdGeom.Xformable(camera_prim)
transform_ops = xform_api.GetOrderedXformOps()
transform_op = None
for op in transform_ops:
    if op.GetOpType() == UsdGeom.XformOp.TypeTransform:
        transform_op = op
        break

if transform_op:
    transform_op.Set(Gf.Matrix4d().SetTranslate(fixed_translate) * Gf.Matrix4d().SetRotate(fixed_rotate))
else:
    transform_op = xform_api.AddTransformOp()
    transform_op.Set(Gf.Matrix4d().SetTranslate(fixed_translate) * Gf.Matrix4d().SetRotate(fixed_rotate))

# Viewport'u güncelleme
viewport_api.camera_path = ''
viewport_api.camera_path = '/World/Camera_box_count'

# Real-time Object Detection
def detect_objects():
    while True:
        # Aktif viewport'tan görüntü alma
        camera_image = viewport_api.capture_next_frame()

        # Görüntüyü numpy dizisine dönüştürme
        image = np.array(camera_image, dtype=np.uint8)

        # YOLOv8 ile nesne tespiti
        results = model(image)

        # Tespit edilen nesneleri çizme
        for result in results:
            for bbox in result.boxes:
                x1, y1, x2, y2 = map(int, bbox.xyxy[0])
                cv2.rectangle(image, (x1, y1), (x2, y2), (0, 255, 0), 2)

        # Görüntüyü gösterme
        cv2.imshow("YOLOv8 Object Detection", image)

        # Çıkış için 'q' tuşuna basılmasını bekleme
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

    cv2.destroyAllWindows()

# Object Detection fonksiyonunu çağırma
detect_objects()

2024-07-31 13:30:35 [66,097ms] [Error] [carb.scripting-python.plugin] AttributeError: 'ViewportAPI' object has no attribute 'capture_next_frame'

At:
  c:/users/ov-user/appdata/local/temp/1/x5p4.0/script_1722432634.py(53): detect_objects
  c:/users/ov-user/appdata/local/temp/1/x5p4.0/script_1722432634.py(77): <module>

AttributeError: 'ViewportAPI' object has no attribute 'capture_next_frame'

At:
  c:/users/ov-user/appdata/local/temp/1/x5p4.0/script_1722432634.py(53): detect_objects
  c:/users/ov-user/appdata/local/temp/1/x5p4.0/script_1722432634.py(77): <module>
2024-07-31 13:30:35 [66,104ms] [Error] [omni.kit.app.plugin] [py stderr]: AttributeError: 'ViewportAPI' object has no attribute 'capture_next_frame'

At:
  c:/users/ov-user/appdata/local/temp/1/x5p4.0/script_1722432634.py(53): detect_objects
  c:/users/ov-user/appdata/local/temp/1/x5p4.0/script_1722432634.py(77): <module>

2024-07-31 13:30:47 [78,540ms] [Warning] [carb] Plugin interface for a client: omni.hydratexture.plugin was already released.```

Upvotes: 0

Views: 109

Answers (0)

Related Questions