https://github.com/filthyrake/telescope_cam_detection
Real-time wildlife detection and telescope collision prevention system using RT-DETR + iNaturalist on NVIDIA A30
https://github.com/filthyrake/telescope_cam_detection
astronomy computer-vision deep-learning fastapi nvidia-gpu object-detection python pytorch real-time-detection rt-detr rtsp telescope websocket wildlife-monitoring
Last synced: 2 months ago
JSON representation
Real-time wildlife detection and telescope collision prevention system using RT-DETR + iNaturalist on NVIDIA A30
- Host: GitHub
- URL: https://github.com/filthyrake/telescope_cam_detection
- Owner: filthyrake
- License: other
- Created: 2025-10-05T20:59:52.000Z (9 months ago)
- Default Branch: master
- Last Pushed: 2025-11-04T15:35:25.000Z (8 months ago)
- Last Synced: 2025-11-04T16:04:54.957Z (8 months ago)
- Topics: astronomy, computer-vision, deep-learning, fastapi, nvidia-gpu, object-detection, python, pytorch, real-time-detection, rt-detr, rtsp, telescope, websocket, wildlife-monitoring
- Language: Python
- Homepage:
- Size: 666 KB
- Stars: 1
- Watchers: 0
- Forks: 2
- Open Issues: 55
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Security: SECURITY.md
Awesome Lists containing this project
README
# Telescope Detection System
[](https://opensource.org/licenses/MIT)
[](https://www.python.org/downloads/)
[](https://pytorch.org/)
[](https://developer.nvidia.com/cuda-toolkit)
Real-time object detection system for monitoring astronomical telescopes and desert wildlife using Reolink cameras and NVIDIA GPUs.
## Features
- **Ultra-fast detection**: 11-21ms inference with YOLOX
- **Object tracking**: Track animals across frames with unique IDs, dwell time, and movement analytics
- **Multi-camera support**: Monitor multiple angles simultaneously with fault-tolerant startup
- **GPU OOM graceful degradation**: Automatic memory management prevents crashes with progressive quality reduction
- **Performance optimizations**: Empty frame filtering (30-50% throughput gain) + sparse detection (3x GPU load reduction)
- **Clips directory authentication**: Optional Bearer token authentication for saved wildlife clips
- **Motion filtering**: Background subtraction to eliminate false positives from static objects
- **Time-of-day filtering**: Species activity patterns reduce false positives (e.g., birds at night → likely bugs/bats)
- **Automatic reconnection**: Cameras reconnect automatically if connection is lost
- **80 COCO classes**: Wildlife-relevant categories (person, bird, cat, dog, etc.)
- **Per-class filtering**: Customizable confidence thresholds and size constraints per detection class
- **Optional species classification**: iNaturalist Stage 2 (10,000 species) with geographic filtering + time-aware re-ranking
- **Web interface**: Live video streams with real-time detection overlays and GPU memory monitoring
- **Automatic snapshots**: Save interesting detections to disk with configurable cooldown
- **MIT License**: Fully open source
## Quick Start
### 1. Install Dependencies
```bash
source venv/bin/activate
pip install -r requirements.txt
```
### 2. Configure Cameras
Copy the credentials template and add your camera passwords:
```bash
cp camera_credentials.example.yaml camera_credentials.yaml
nano camera_credentials.yaml # Add your passwords
```
Edit `config/config.yaml` to set camera IPs and detection preferences.
### 3. Run the System
```bash
python main.py
```
Access the web interface at **http://localhost:8000**
### 4. Run as a Service (Recommended)
For production use with auto-start on boot:
```bash
sudo ./service.sh install
sudo ./service.sh start
./service.sh logs -f # Watch logs
```
See [SERVICE_SETUP.md](docs/setup/SERVICE_SETUP.md) for complete service documentation.
## Documentation
### Setup & Configuration
- **[Configuration Reference](docs/setup/CONFIG_REFERENCE.md)** - All config options explained
- **[Service Setup](docs/setup/SERVICE_SETUP.md)** - Running as systemd service
- **[Camera Credentials](camera_credentials.example.yaml)** - Secure credential storage
### Features & Usage
- **[Snapshot Feature](docs/features/SNAPSHOT_FEATURE.md)** - Automatic image/video saving
- **[Species Classification (Stage 2)](docs/features/STAGE2_SETUP.md)** - Fine-grained species ID
- **[GPU OOM Graceful Degradation](docs/features/OOM_GRACEFUL_DEGRADATION.md)** - Memory management and crash prevention
- **[API Reference](docs/api/API_REFERENCE.md)** - WebSocket and HTTP endpoints
### Performance & Troubleshooting
- **[Performance Guide](docs/PERFORMANCE.md)** - Benchmarks and optimization
- **[Troubleshooting](docs/TROUBLESHOOTING.md)** - Common issues and solutions
- **[Architecture](docs/architecture/ARCHITECTURE.md)** - System design and components
### Training & Development
- **[Training Guide](docs/training/TRAINING_GUIDE.md)** - Train custom models
- **[Annotation Guide](docs/training/ANNOTATION_GUIDE.md)** - Label your own dataset
## Testing
```bash
# Test camera connection
python tests/test_camera_connection.py
# Benchmark GPU inference
python tests/test_inference.py
# Measure end-to-end latency
python tests/test_latency.py
```
## Project Structure
```
telescope_cam_detection/
├── config/ # Configuration files
├── src/ # Core application modules
├── web/ # Web interface (HTML/JS)
├── docs/ # Complete documentation
├── tests/ # Test scripts
├── models/ # Model weights
├── training/ # Training infrastructure
├── clips/ # Saved detection snapshots
└── main.py # Application entry point
```
## System Requirements
- **OS**: Ubuntu 22.04+ (or similar Linux)
- **GPU**: NVIDIA GPU with CUDA support (A30 recommended)
- **Python**: 3.11+
- **RAM**: 8GB+ recommended
- **Network**: Local network access to Reolink cameras
## Performance
With NVIDIA A30:
- **Inference**: 11-21ms per frame
- **FPS**: 25-30 sustained
- **Latency**: 25-35ms end-to-end
- **Memory**: ~2GB VRAM per camera
See [Performance Guide](docs/PERFORMANCE.md) for optimization strategies and benchmarks.
## Development Roadmap
- ✅ **Phase 1**: Core detection system (complete)
- ✅ **Phase 2**: Species classification (complete)
- 🔨 **Phase 3**: Custom telescope training (in progress)
- 📋 **Phase 4**: Collision detection and alerts (planned)
## Troubleshooting
Having issues? Check the [Troubleshooting Guide](docs/TROUBLESHOOTING.md) for common problems and solutions.
Quick fixes:
- **Camera not connecting?** Run `python tests/test_camera_connection.py`
- **GPU not working?** Check with `nvidia-smi` and verify CUDA is available
- **High latency?** See [Performance Guide](docs/PERFORMANCE.md) for optimization tips
## API
### WebSocket
Connect to `ws://localhost:8000/ws/detections` for real-time detection events.
### HTTP
- `GET /` - Web interface
- `GET /health` - Health check
- `GET /stats` - Performance metrics
- `GET /video/feed` - MJPEG video stream
See [API Reference](docs/api/API_REFERENCE.md) for complete documentation.
## Credits
Built with these excellent open-source projects:
- **[YOLOX](https://github.com/Megvii-BaseDetection/YOLOX)** (Apache 2.0) - Object detection
- **[iNaturalist/EVA02](https://github.com/huggingface/pytorch-image-models)** (Apache 2.0) - Species classification
- **[PyTorch](https://pytorch.org/)** (BSD-3) - Deep learning framework
- **[OpenCV](https://opencv.org/)** (Apache 2.0) - Computer vision
- **[FastAPI](https://fastapi.tiangolo.com/)** (MIT) - Web framework
## License
MIT License - see [LICENSE](LICENSE) for details. All dependencies use permissive licenses (Apache 2.0, BSD, MIT).
## Support
- 📖 **Documentation**: See `docs/` directory
- 🐛 **Issues**: [GitHub Issues](https://github.com/filthyrake/telescope_cam_detection/issues)
- 📊 **Logs**: `./service.sh logs` or check `logs/` directory