Skip to content

Latest commit

 

History

History

README.md

Camera Integration Examples

This directory contains examples demonstrating how to integrate camera feeds with PraisonAI multimodal agents for real-time visual analysis.

📋 Overview

PraisonAI supports visual input through the images parameter in Tasks. While there's no built-in camera capture, you can integrate camera feeds by capturing frames/videos and passing them to vision agents.

🛠️ Setup

Requirements

pip install praisonaiagents opencv-python

Environment Variables

export OPENAI_API_KEY=your_openai_api_key

📁 Examples

1. camera-basic.py - Basic Camera Capture

  • Purpose: Capture a single frame and analyze it
  • Use Case: Quick analysis, testing camera setup
  • Features:
    • Single frame capture
    • Basic object and scene analysis
    • Automatic cleanup

Usage:

python camera-basic.py

2. camera-continuous.py - Continuous Monitoring

  • Purpose: Continuous camera monitoring with periodic analysis
  • Use Case: Security monitoring, surveillance systems
  • Features:
    • Configurable analysis intervals
    • Real-time monitoring
    • Security-focused analysis
    • Graceful shutdown with Ctrl+C

Usage:

python camera-continuous.py

3. camera-multi-agent.py - Multi-Agent Analysis

  • Purpose: Multiple specialized agents analyzing the same camera feed
  • Use Case: Comprehensive analysis from different perspectives
  • Features:
    • Security analysis agent
    • Object detection agent
    • Scene analysis agent
    • Parallel processing

Usage:

python camera-multi-agent.py

4. camera-video-analysis.py - Video Recording & Analysis

  • Purpose: Record video segments and analyze temporal events
  • Use Case: Activity analysis, event detection
  • Features:
    • Video recording with configurable duration
    • Temporal event analysis
    • Timeline extraction
    • Automatic cleanup

Usage:

python camera-video-analysis.py

🎯 Supported Input Types

  • Local Images: "camera_shot.jpg", "webcam_capture.png"
  • Local Videos: "security_feed.mp4", "recording.avi"
  • Image URLs: "https://example.com/live_feed.jpg"
  • Multiple Sources: ["cam1.jpg", "cam2.jpg", "video.mp4"]

🔧 Configuration Options

Camera Settings

camera_id = 0  # Default camera (change to 1, 2, etc. for other cameras)

Analysis Intervals

analysis_interval = 10  # Seconds between analyses for continuous monitoring

Recording Duration

recording_duration = 15  # Seconds for video recording

💡 Integration Patterns

1. Real-time Processing

# Capture frames periodically and process them as separate tasks
def capture_and_analyze():
    cap = cv2.VideoCapture(0)
    ret, frame = cap.read()
    if ret:
        cv2.imwrite("temp_capture.jpg", frame)
        # Process with PraisonAI agent
    cap.release()

2. Batch Analysis

# Process multiple camera angles simultaneously
task = Task(
    description="Analyze multiple camera feeds",
    agent=vision_agent,
    images=["cam1.jpg", "cam2.jpg", "cam3.jpg"]
)

3. Video Analysis

# Save video segments and analyze them
task = Task(
    description="Analyze this video for activities",
    agent=vision_agent,
    images=["security_footage.mp4"]  # Video files work too
)

🔒 Security Considerations

  • Camera Permissions: Ensure your application has camera access
  • Privacy: Be mindful of privacy when recording/analyzing
  • Storage: Clean up temporary files to avoid storage issues
  • Access Control: Implement proper access controls for camera systems

🐛 Troubleshooting

Camera Not Found

# Check available cameras
for i in range(4):  # Check first 4 camera indices
    cap = cv2.VideoCapture(i)
    if cap.isOpened():
        print(f"Camera {i} is available")
        cap.release()

Permission Issues

  • On Linux: Add user to video group
  • On macOS: Grant camera permissions in System Preferences
  • On Windows: Check camera privacy settings

Performance Optimization

  • Reduce frame size for faster processing
  • Adjust analysis intervals based on requirements
  • Use parallel processing for multiple agents

📚 Related Documentation

🤝 Contributing

Feel free to contribute additional camera integration examples or improvements to existing ones!