> ## Documentation Index
> Fetch the complete documentation index at: https://docs.vlm.run/llms.txt
> Use this file to discover all available pages before exploring further.

# Detection

> Detect and locate objects, faces or people in images with bounding boxes and confidence scores

Detect objects, people, or other entities in images with precise bounding boxes and confidence scores. Ideal for inventory management, quality control, security applications, and automated visual inspection.

<Frame caption="Object detections visualized.">
  <img className="block dark:hidden" src="https://mintcdn.com/autonomiai/7LCH2ZD074tEU8dT/agents/assets/donut-detection.jpg?fit=max&auto=format&n=7LCH2ZD074tEU8dT&q=85&s=3c724222af8111fde0f0dda95be5131e" alt="Object detection example showing detected objects with bounding boxes" style={{ width: '80%', border: '1px solid #ddd', borderRadius: '4px' }} width="715" height="479" data-path="agents/assets/donut-detection.jpg" />
</Frame>

<Frame caption="Example detections of objects, people and faces.">
  <div style={{ display: 'flex', gap: '20px', justifyContent: 'center' }}>
    <div style={{ flex: 1 }}>
      <h4 style={{ textAlign: 'center', marginBottom: '10px' }}>Persons</h4>

      <img src="https://mintcdn.com/autonomiai/7LCH2ZD074tEU8dT/agents/assets/person-detection.jpg?fit=max&auto=format&n=7LCH2ZD074tEU8dT&q=85&s=d4c5b7fae815e5b344440a9788a36c8d" alt="Persons detection example showing detected people with bounding boxes" style={{ width: '100%', border: '1px solid #ddd', borderRadius: '4px' }} width="2048" height="1609" data-path="agents/assets/person-detection.jpg" />
    </div>

    <div style={{ flex: 1 }}>
      <h4 style={{ textAlign: 'center', marginBottom: '10px' }}>Faces</h4>

      <img src="https://mintcdn.com/autonomiai/7LCH2ZD074tEU8dT/agents/assets/face-detection.jpg?fit=max&auto=format&n=7LCH2ZD074tEU8dT&q=85&s=0f945db5c133f04b8633a6f1c13c4aa1" alt="Faces detection example showing detected faces with bounding boxes" style={{ width: '100%', border: '1px solid #ddd', borderRadius: '4px' }} width="1008" height="671" data-path="agents/assets/face-detection.jpg" />
    </div>
  </div>
</Frame>

## Usage Example

<Tip>
  For best results, we recommend using the [Structured Outputs API](/agents/structured-responses) to get responses in a structured and validated data format.
</Tip>

<Info title="Face and Person Detection">
  The following examples can also be used for face or person detection. The response schema is identical to the object detection example.
</Info>

<CodeGroup>
  ```python Python theme={"theme":{"light":"github-light","dark":"dark-plus"}}
  from vlmrun.client import VLMRun

  # Initialize the VLMRun client
  client = VLMRun(api_key="<VLMRUN_API_KEY>")

  # Execute object detection
  response = client.agent.completions.create(
      model="vlmrun-orion-1:auto",
      messages=[
          {"role": "user", "content": [
              {"type": "text", "text": "Detect all objects in this image"},
              {"type": "image_url", "image_url": {"url": "https://storage.googleapis.com/vlm-data-public-prod/hub/examples/image.object-detection/donuts.png", "detail": "auto"}}
          ]},
      ],
  )

  print(response.choices[0].message.content)
  ```

  ```python Python - Structured Outputs theme={"theme":{"light":"github-light","dark":"dark-plus"}}
  from vlmrun.client import VLMRun
  from pydantic import BaseModel, Field

  # Define the response schema
  class Detection(BaseModel):
    label: str = Field(..., description="Name of the detected object")
    xywh: tuple[float, float, float, float] = Field(..., description="Bounding box (x, y, width, height)")

  class Detections(BaseModel):
    detections: list[Detection] = Field(..., description="List of detections")

  # Initialize the VLMRun client
  client = VLMRun(api_key="<VLMRUN_API_KEY>")

  # Execute object detection with structured output
  response = client.agent.completions.create(
      model="vlmrun-orion-1:auto",
      messages=[
          {"role": "user", "content": [
              {"type": "text", "text": "Detect all objects in this image"},
              {"type": "image_url", "image_url": {"url": "https://storage.googleapis.com/vlm-data-public-prod/hub/examples/image.object-detection/donuts.png", "detail": "auto"}}
          ]},
      ],
      response_format={"type": "json_schema", "schema": Detections.model_json_schema()},
  )

  # Validate the response
  result = Detections.model_validate_json(response.choices[0].message.content)
  # >>> Detections(detections=[Detection(label="donut", xywh=(...)), ...])
  ```

  ```typescript Node.js theme={"theme":{"light":"github-light","dark":"dark-plus"}}
  import { VlmRun } from "vlmrun";

  const client = new VlmRun({
    apiKey: "<VLMRUN_API_KEY>",
    baseURL: "https://api.vlm.run/v1"
  });

  const response = await client.agent.completions.create({
    model: "vlmrun-orion-1:auto",
    messages: [
      {
        role: "user",
        content: [
          { type: "text", text: "Detect all objects in this image" },
          { type: "image_url", image_url: { url: "https://storage.googleapis.com/vlm-data-public-prod/hub/examples/image.object-detection/donuts.png", detail: "auto" } }
        ]
      }
    ]
  });

  console.log(response.choices[0].message.content);
  ```

  ```typescript Node.js - Structured Outputs [expandable] theme={"theme":{"light":"github-light","dark":"dark-plus"}}
  import { VlmRun } from "vlmrun";
  import { z } from "zod";
  import { zodToJsonSchema } from "zod-to-json-schema";

  // Define the response schema with Zod
  const DetectionsSchema = z.object({
    detections: z.array(z.object({
      label: z.string().describe("Name of the detected object"),
      xywh: z.array(z.number()).describe("Bounding box (x, y, width, height)")
    })).describe("List of detections")
  });

  // Initialize the VLMRun client
  const client = new VlmRun({
    apiKey: "<VLMRUN_API_KEY>",
    baseURL: "https://api.vlm.run/v1"
  });

  // Execute object detection with structured output
  const response = await client.agent.completions.create({
    model: "vlmrun-orion-1:auto",
    messages: [
      {
        role: "user",
        content: [
          { type: "text", text: "Detect all objects in this image" },
          { type: "image_url", image_url: { url: "https://storage.googleapis.com/vlm-data-public-prod/hub/examples/image.object-detection/donuts.png", detail: "auto" } }
        ]
      }
    ],
    response_format: {
      type: "json_schema",
      schema: zodToJsonSchema(DetectionsSchema)
    }
  });

  const result = DetectionsSchema.parse(JSON.parse(response.choices[0].message.content));
  ```
</CodeGroup>

## FAQ

<AccordionGroup>
  <Accordion title="What objects are supported?" icon="person">
    Orion supports open-world (aka open-set) detection. This means it is not limited to a predefined list of categories; it can detect, locate, and ground virtually any object described in natural language, including rare items, specific parts of objects, and complex visual relations.
  </Accordion>

  <Accordion title="What format do the bounding boxes come in?" icon="crop">
    The bounding boxes come in the format of normalized `xywh`, where `x` and `y` are the top-left corner of the bounding box, and `w` and `h` are the width and height of the bounding box. All values are between 0 and 1, and normalized by the image size. `x` and `w` are normalized by the image width, and `y` and `h` are normalized by the image height.
  </Accordion>

  <Accordion title="What is the confidence score?" icon="percent">
    The confidence score is a value between 0 and 1 that indicates the confidence of the detection.
  </Accordion>
</AccordionGroup>
