GitHub - GongRzhe/opencv-mcp-server: OpenCV MCP Server provides OpenCV's image and video processing capabilities through the Model Context Protocol (MCP). Access powerful computer vision tools for tasks ranging from basic image manipulation to advanced object detection and tracking. (original) (raw)

logo

πŸš€ OpenCV MCP Server

MCP server providing powerful OpenCV computer vision capabilities for AI assistants.

πŸ” Introduction

OpenCV MCP Server is a Python package that provides OpenCV's image and video processing capabilities through the Model Context Protocol (MCP). This allows AI assistants and language models to access powerful computer vision tools for tasks ranging from basic image manipulation to advanced object detection and tracking.

With OpenCV MCP Server, AI systems can:

✨ Features

πŸ“Š Demo Examples

Edge Detection

Edge Detection

Face Detection

Face Detection

Statistical Analysis

Statistical Information

Video Processing

Video Processing

Original Video Sample

Original Video Demo

Contour Detection Processing

Contour Detection Example of contour detection processing applied to the original video above

πŸ“¦ Installation

pip install opencv-mcp-server

For development:

Clone the repository

git clone https://github.com/yourusername/opencv-mcp-server.git cd opencv-mcp-server

Create a virtual environment

python -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate

Install dependencies

pip install -e .

πŸ”§ Usage

Use in Claude Desktop

Add to your Claude Desktop configuration:

{ "tools": { "opencv": { "command": "uvx", "args": [ "opencv-mcp-server" ] } } }

Basic Python Usage

from opencv_mcp_server import opencv_client

Initialize client

client = opencv_client.OpenCVClient()

Use tools

result = client.resize_image( image_path="input.jpg", width=800, height=600 )

Advanced Object Detection Example

Since all required models are already configured in the OPENCV_DNN_MODELS_DIR, you can use object detection without specifying model paths:

Detect objects using pre-configured YOLO model

result = detect_objects_tool( image_path="street.jpg", confidence_threshold=0.5, nms_threshold=0.4 )

Configuration

The server can be configured using environment variables:

🧠 Model Files Setup

The computer vision and object detection tools require pre-trained models to function properly. These models should be placed in the directory specified by the OPENCV_DNN_MODELS_DIR environment variable (default: "./models").

Required Models

The following models have been pre-configured:

Model Usage

For those who need to download these models, see the "Installation" section or visit:

🧰 Available Tools

The OpenCV MCP Server provides a wide range of computer vision tools organized into four categories:

πŸ“Έ Image Basics

These tools provide fundamental image manipulation capabilities:

πŸ–ΌοΈ Image Processing

These tools provide advanced image processing and transformation capabilities:

🧠 Computer Vision

These tools provide high-level computer vision capabilities:

🎬 Video Processing

These tools provide video analysis and processing capabilities:

πŸ“ Advanced Usage Examples

πŸ“Έ Basic Image Processing

Resize an image

result = resize_image_tool( image_path="input.jpg", width=800, height=600 )

Access the resized image path

resized_image_path = result["output_path"]

Apply a Gaussian blur filter

result = apply_filter_tool( image_path="input.jpg", filter_type="gaussian", kernel_size=5, sigma=1.5 )

🧠 Object Detection

Detect objects in an image using YOLO

result = detect_objects_tool( image_path="scene.jpg", confidence_threshold=0.5, nms_threshold=0.4 )

Access detected objects

objects = result["objects"] for obj in objects: print(f"Detected {obj['class_name']} with confidence {obj['confidence']}")

🎬 Video Analysis

Extract frames from a video

result = extract_video_frames_tool( video_path="input.mp4", start_frame=0, step=10, max_frames=10 )

Access extracted frames

frames = result["frames"]

Detect objects in a video

result = detect_video_objects_tool( video_path="input.mp4", confidence_threshold=0.5, frame_step=5 )

πŸ”„ Chaining Operations

Tools can be chained together by using the output_path from one tool as the input to another:

First resize an image

result1 = resize_image_tool( image_path="input.jpg", width=800, height=600 )

Then apply edge detection to the resized image

result2 = detect_edges_tool( image_path=result1["output_path"], method="canny", threshold1=100, threshold2=200 )

Finally detect contours in the edge-detected image

result3 = detect_contours_tool( image_path=result2["output_path"], mode="external", method="simple" )

πŸ” Real-world Applications

OpenCV MCP Server can be used for a wide range of applications:

πŸ—ΊοΈ Roadmap

Future enhancements planned for OpenCV MCP Server:

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the project
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“œ License

MIT License - See the LICENSE file for details.

πŸ“ž Contact

For questions or feedback, please open an issue on the GitHub repository.


Built with ❀️ using OpenCV and Python.