AI-powered pet detection and filtering API with YOLO
- Real-time Pet Detection: YOLO-powered detection of cats, dogs, horses, and more
- Pet Eye Detection: Custom-trained YOLO model for precise eye landmark detection
- Image Filters: Vintage, sepia, blur, sharpen, brightness adjustments
- Smart Overlays: Sunglasses, hats, bow ties positioned using facial landmarks
- Async Processing: Non-blocking task queue for heavy operations
- Cloudflare Tunnel Ready: Optimized for Raspberry Pi deployment
- CORS Enabled: Ready for web frontend integration
pip install flask flask-cors opencv-python pillow ultralytics mediapipe numpy torchgit clone https://github.com/maheaven293/pet-detection-api.git
cd pet-detection-api
python pet detection & filter appFROM python:3.9-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
EXPOSE 5000
CMD ["python", "pet detection & filter app.py"]POST /detect_objects
Content-Type: application/json
{
"image": "data:image/jpeg;base64,..."
}Response:
{
"boxes": [
{
"bbox": [x1, y1, x2, y2],
"class_name": "cat",
"confidence": 0.95
}
],
"pet_type": "cat",
"count": 1
}POST /auto_capture
Content-Type: application/json
{
"image": "data:image/jpeg;base64,..."
}Returns task ID for async processing.
POST /apply_filter
Content-Type: application/json
{
"image": "data:image/jpeg;base64,...",
"pet_type": "cat",
"filter_name": "vintage"
}Available filters: vintage, blur, sharpen, sepia, bright, dark
POST /apply_overlay
Content-Type: application/json
{
"image": "data:image/jpeg;base64,...",
"overlay_type": "sunglasses"
}Available overlays: sunglasses, party_hat, bow_tie
POST /detect_landmarks
Content-Type: application/json
{
"image": "data:image/jpeg;base64,..."
}GET /get_task_status/{task_id}PORT=5000
FLASK_DEBUG=falseyolov8n.pt- Main YOLO modelbest_pet_eye_yolo.pt- Custom pet eye detection model
/static
/captured_pets # Auto-captured pet images
/filtered_images # Processed results
/overlay_assets # PNG overlays (sunglasses.png, etc.)
- Raspberry Pi Ready: Reduced image sizes (416px max)
- Memory Efficient: Automatic cleanup of old tasks
- CPU Optimized: Lower confidence thresholds for faster processing
- Threading: Non-blocking async operations
const detectPets = async (imageData) => {
const response = await fetch('http://localhost:5000/detect_objects', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ image: imageData })
});
return await response.json();
};const usePetDetection = () => {
const [pets, setPets] = useState([]);
const detectPets = useCallback(async (imageData) => {
const result = await fetch('/detect_objects', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ image: imageData })
}).then(r => r.json());
setPets(result.boxes || []);
return result;
}, []);
return { pets, detectPets };
};python pet detection & filter app.pycloudflared tunnel --url http://localhost:5000{
"scripts": {
"start": "python app.py"
}
}# Install dependencies
sudo apt update
sudo apt install python3-opencv
# Clone and run
git clone https://github.com/maheaven293/pet-detection-api.git
cd pet-detection-api
pip3 install -r requirements.txt
python3 app.pyTo replace the pet eye detection model:
- Train YOLO model on pet eye dataset
- Export to
best_pet_eye_yolo.pt - Adjust confidence thresholds in
detect_pet_eyes_yolo()
All endpoints return consistent error format:
{
"error": "Description of what went wrong",
"status": "error"
}- Task cleanup every 5 minutes
- 1-hour task expiration
- CORS configured for production
- File size limits (16MB max)
MIT License - Feel free to use in commercial projects.