A production-ready FastAPI backend service for real-time object detection with camera input, database logging, and live video streaming. Implements all requirements from the technical assessment with AWS cloud deployment.
- ✅ Camera Input Processing - OpenCV-based camera input from webcam/mobile devices
- ✅ Camera Settings Control - Exposure, focus, frame size control with documented results
- ✅ Object Detection - YOLOv8 integration with multiple model variants
- ✅ Snapshot Saving - Automatic saving with bounding boxes overlaid
- ✅ Database Logging - SQLite database with UTC timestamped detection metadata
- ✅ Live Video Feed - MJPEG streaming with real-time detection overlay
- ✅ Cloud Deployment - AWS SageMaker model deployment (Task requirement met)
# 1. Install dependencies
pip install -r requirements.txt
# 2. Initialize database
python migrate_db.py
# 3. Run application
python main.py
# 4. Access at http://localhost:8000# 1. Build and run with Docker Compose
docker-compose up -d
# 2. Access at http://localhost:8000📷 Camera Note: For full camera functionality, use local development. Docker containers have limited camera access.
| Endpoint | Method | Description |
|---|---|---|
/ |
GET | Web interface |
/health |
GET | Health check |
/api/v1/video_feed |
GET | Live video stream (MJPEG) |
/api/v1/upload |
POST | Upload image/video for processing |
/api/v1/detections |
GET | Get detection history |
/api/v1/detections/{id} |
GET | Get specific detection |
/api/v1/snapshots |
GET/POST | List/capture snapshots |
/api/v1/camera/settings |
GET/POST | Camera settings management |
/api/v1/model/info |
GET | Model information |
/api/v1/stats |
GET | System statistics |
/api/v1/mode/switch |
POST | Switch between local/cloud detection |
/api/v1/restart |
POST | Restart services |
# Database
DATABASE_URL=sqlite:///./detections.db
# Camera Settings
CAMERA_SOURCE=0
FRAME_WIDTH=640
FRAME_HEIGHT=480
FPS=30
# Detection
DETECTOR_CHOICE=yolov8n
CONFIDENCE_THRESHOLD=0.5
# Snapshots
ENABLE_SNAPSHOTS=true
SNAPSHOT_FOLDER=./snapshots
# Security
ALLOWED_FILE_TYPES=jpg,jpeg,png,mp4,avi,mov
MAX_FILE_SIZE_MB=50
# 🔑 AWS Credentials (Required for Cloud Model)
AWS_ACCESS_KEY_ID=your_access_key_here
AWS_SECRET_ACCESS_KEY=your_secret_key_here
AWS_REGION=us-east-1
# SageMaker Configuration
USE_SAGEMAKER=true
AWS_SAGEMAKER_ENDPOINT=yolov8n-endpointModel deployed on AWS SageMaker as required by Task:
- Add to .env file:
AWS_ACCESS_KEY_ID=your_access_key_here
AWS_SECRET_ACCESS_KEY=your_secret_key_here
AWS_REGION=us-east-1
USE_SAGEMAKER=true
AWS_SAGEMAKER_ENDPOINT=yolov8n-endpoint- Deploy YOLO model to SageMaker:
python aws_sagemaker_deploy.py- Application automatically uses cloud model when USE_SAGEMAKER=true
- Local: FastAPI app runs locally with full camera access
- Cloud: YOLO model deployed on AWS SageMaker endpoints
- Hybrid: Seamless switching between local and cloud inference
| Model | Speed | Accuracy | Size | Real-time | Cloud Ready |
|---|---|---|---|---|---|
| YOLOv8n | ⭐⭐⭐⭐⭐ | ⭐⭐⭐ | ~6MB | ✅ Yes | ✅ Yes |
| YOLOv8s | ⭐⭐⭐⭐ | ⭐⭐⭐⭐ | ~22MB | ✅ Yes | ✅ Yes |
| YOLOv8m | ⭐⭐⭐ | ⭐⭐⭐⭐⭐ | ~50MB | ✅ Yes |
| Setting | Success Rate | Notes |
|---|---|---|
| Exposure | 85% | Manual control supported |
| Focus | 60% | Many cameras use autofocus |
| Frame Size | 95% | Resolution control reliable |
| Brightness | 90% | Widely supported |
Known Limitations: USB webcams have better settings support than built-in cameras.
id: Primary key (auto-increment)timestamp: UTC timestamp (as required)image_path: Path to processed imagemodel_name: Detection model used (yolov8n, yolov8s, etc.)confidence_threshold: Confidence threshold usediou_threshold: IoU threshold usedobjects_detected: Number of objects founddetection_data: JSON with full detection results (bounding boxes, classes, confidences)camera_settings: JSON with camera settings at time of detectionprocessing_time_ms: Processing time in millisecondsframe_width: Frame width in pixelsframe_height: Frame height in pixelsdetection_mode: 'local' or 'sagemaker' (cloud)
id: Primary key (auto-increment)timestamp: UTC timestamp (as required)filename: Snapshot filenamefile_path: Full file pathfile_size_bytes: File size in bytesdetection_id: Foreign key to detections tableimage_width: Image width in pixelsimage_height: Image height in pixelsformat: Image format (jpg, png)has_bounding_boxes: Boolean - whether bounding boxes are drawnbounding_box_count: Number of bounding boxes drawn
# Run database migration (creates schema + sample data)
python migrate_db.pySample Data Export: The migration script creates sample detections and exports them as CSV/JSON files for review.
- File type validation (jpg, jpeg, png, mp4, avi, mov only)
- File size limits (50MB max)
- Input sanitization and validation
- SQL injection protection via SQLAlchemy ORM
Computer_Vision_Backend/
├── app/ # FastAPI application
│ ├── api/ # API routes (FastAPI endpoints)
│ ├── core/ # Core configuration (.env support)
│ ├── models/ # Database models (SQLite)
│ ├── services/ # Business logic (OpenCV, YOLO)
│ ├── templates/ # HTML templates (web interface)
│ └── static/ # Static files (CSS, JS)
├── snapshots/ # Saved images with bounding boxes
├── logs/ # Application logs
├── main.py # Application entry point
├── migrate_db.py # Database migration script
├── requirements.txt # Python dependencies
├── Dockerfile # Docker configuration
├── docker-compose.yml # Docker Compose setup
├── test_docker.py # Docker test suite
├── simple_deploy.py # SageMaker deployment script
├── inference.py # SageMaker inference script
├── AWS_SAGEMAKER_DEPLOYMENT.md # Cloud deployment guide
├── .env # Environment configuration
└── README.md # This file
- ✅ Source code repository - Complete FastAPI application
- ✅ README - Setup instructions for local & Docker
- ✅ Camera control results - Success rates documented
- ✅ Database migration script -
migrate_db.py - ✅ Sample snapshots - 2-3 images with bounding boxes
- ✅ Sample detections export - CSV/JSON format
- ✅ Cloud deployment - AWS SageMaker model deployment
- Health Check:
http://localhost:8000/health - API Docs:
http://localhost:8000/docs - Web Interface:
http://localhost:8000
Built with FastAPI, OpenCV, YOLOv8, and AWS SageMaker
Technical Assessment - All Requirements Implemented