OpenCV

OpenCVTools enables agents to capture images and videos from webcam using OpenCV computer vision library.

Prerequisites

The following example requires the opencv-python and openai libraries.

uv pip install -U agno opencv-python openai
export OPENAI_API_KEY="your_openai_api_key_here"

Grant camera access to the terminal or IDE running the example. On macOS, use System Settings > Privacy & Security > Camera. On Windows, use Settings > Privacy & security > Camera and allow desktop apps. On Linux and in containers, make sure the process can access the camera device, such as /dev/video0.

Example

The following agent can capture images and videos from your webcam:

from agno.agent import Agent
from agno.tools.opencv import OpenCVTools

agent = Agent(
    instructions=[
        "You are a computer vision assistant that can capture images and videos",
        "Use the webcam to take photos or record videos as requested",
        "Provide clear feedback about capture operations",
        "Help with basic computer vision tasks",
    ],
    tools=[OpenCVTools()],
)

agent.print_response("Take a photo using the webcam", stream=True)

Toolkit Params

ParameterTypeDefaultDescription
show_previewboolFalseWhether to show camera preview window during capture.
enable_capture_imageboolTrueEnable image capture functionality.
enable_capture_videoboolTrueEnable video capture functionality.
allboolFalseEnable all functionality.

Toolkit Functions

FunctionDescription
capture_imageCapture a single image from the webcam.
capture_videoRecord a video from the webcam for a specified duration.

Developer Resources