xr-ai-accelerator

IXrAiObjectDetector

The IXrAiObjectDetector interface defines the contract for AI models that detect and locate objects within images. This interface returns bounding box information for detected objects.

Interface Declaration

public interface IXrAiObjectDetector

Methods

Execute

Analyzes an image and detects objects, returning their locations and classifications.

public Task<XrAiResult<XrAiBoundingBox[]>> Execute(Texture2D texture, Dictionary<string, string> options = null)

Parameters:

Returns:

Usage Example

// Load the model
IXrAiObjectDetector objectDetector = XrAiFactory.LoadObjectDetector("Yolo", new Dictionary<string, string>
{
    { "confidence", "0.5" },
    { "threshold", "0.4" }
}, assets);

// Execute object detection
var result = await objectDetector.Execute(inputTexture, new Dictionary<string, string>
{
    { "maxDetections", "10" }
});

// Handle the result
if (result.IsSuccess)
{
    XrAiBoundingBox[] detections = result.Data;
    
    foreach (var detection in detections)
    {
        Debug.Log($"Detected {detection.ClassName} at ({detection.CenterX}, {detection.CenterY}) " +
                  $"with size {detection.Width}x{detection.Height}");
    }
    
    // Draw bounding boxes on UI
    XrAiObjectDetectorHelper.DrawBoxes(parentTransform, detections, scale, dimensions);
}
else
{
    Debug.LogError($"Object detection failed: {result.ErrorMessage}");
}

Supported Providers

Google

Cloud-based object detection service.

Required Options:

Optional Parameters:

YOLO (Local)

Local inference using Sentis and YOLO models.

Required:

Optional Parameters:

Roboflow

Cloud-based object detection with custom models.

Required Options:

Optional Parameters:

RoboflowLocal

Local inference using Roboflow-trained models.

Required Options:

Optional Parameters:

Bounding Box Format

The XrAiBoundingBox structure contains:

Coordinates are typically normalized (0.0 to 1.0) relative to the image dimensions.

Visualization

Use the XrAiObjectDetectorHelper class to visualize detection results:

// Clear previous boxes
XrAiObjectDetectorHelper.ClearBoxes(parentTransform);

// Draw new detection boxes
XrAiObjectDetectorHelper.DrawBoxes(
    parentTransform, 
    detections, 
    new Vector2(imageWidth, imageHeight), // scale
    new Vector2(displayWidth, displayHeight) // dimensions
);

Implementation Notes

Common Options