Detection API Example
This example demonstrates the imgx detection API with various AI vision providers.
Features Demonstrated
- Basic Label Detection - Simple object detection with default settings
- AWS Multi-Feature - Labels, text (OCR), and face detection together
- AWS Image Properties - Image quality metrics and dominant colors
- Custom Prompts - Natural language queries with Gemini/OpenAI
- Provider Comparison - Test all providers and compare results
- JSON Output - Structured data output format
Usage
# Run the example with an image
go run main.go <image-path>
# Examples
go run main.go ../../testdata/flower.jpg
go run main.go ~/Pictures/photo.jpg
Setup
The example works with three AI vision providers. Configure at least one to see results:
Google Gemini (Recommended for quick testing)
export GEMINI_API_KEY="your-api-key"
Get your API key from: https://aistudio.google.com/
AWS Rekognition
# Option 1: AWS CLI configuration
aws configure
# Option 2: Environment variables
export AWS_ACCESS_KEY_ID="your-key"
export AWS_SECRET_ACCESS_KEY="your-secret"
export AWS_REGION="us-east-1"
OpenAI Vision
export OPENAI_API_KEY="sk-..."
Get your API key from: https://platform.openai.com/
What It Does
The example loads the specified image and runs 6 different detection scenarios:
- Detects objects/labels using Gemini with default settings
- Uses AWS to detect labels, text, and faces with higher confidence threshold
- Analyzes image quality (brightness, sharpness, contrast) and colors using AWS
- Sends a custom prompt to Gemini for detailed description
- Compares all three providers side-by-side
- Demonstrates JSON output format
Each example gracefully handles missing credentials and provides setup instructions.
Expected Output
Loaded: testdata/flower.jpg (350x525)
================================================================================
Example 1: Basic Label Detection with Gemini
--------------------------------------------------------------------------------
✓ Detection successful
Provider: gemini
Labels found: 10
Top 5 labels:
1. Flower (95.2% confidence)
2. Plant (92.8% confidence)
3. Petal (89.3% confidence)
...
Documentation
For complete API documentation, see: