A cutting-edge medical analysis platform combining advanced computer vision, real-time analytics, and clinical reporting for urinary flow assessment
- Overview
- Architecture
- Key Features
- Tech Stack
- Project Structure
- Getting Started
- Usage
- API Documentation
- Clinical Metrics
- How It Works
- Contributing
- License
The Uroflow Computer Vision Analysis System is a comprehensive medical platform that revolutionizes urinary flow assessment through advanced computer vision techniques. The system processes video recordings of urinary streams to extract clinical metrics such as Qmax (peak flow rate), flow time, voiding time, and hesitancy patterns.
This platform combines:
- 🎥 Advanced CV Engine: Multi-view stream segmentation with ROI locking and geometric filtering
- 🚀 Modern Web Frontend: Responsive React application with real-time visualization
- ⚡ Robust Backend API: FastAPI-powered REST API with authentication and database management
- 📊 Clinical Reporting: Automated generation of medical-grade reports with visual analytics
The system follows a modular three-tier architecture:
- User authentication and patient management
- Video upload and analysis request submission
- Real-time progress tracking
- Interactive report visualization
- Responsive UI with TailwindCSS
- RESTful API endpoints
- JWT-based authentication
- Database management (CockroachDB/PostgreSQL)
- Video processing orchestration
- Report generation and storage
- Email notifications
- Calibration: Auto-detects physical reference (26cm blue line)
- Preprocessing: Frame extraction and ROI detection
- Segmentation: Advanced stream isolation using:
- Background subtraction (MOG2)
- ROI locking and tracking
- Width-based gating (removes hands/body parts)
- Geometric filtering (aspect ratio analysis)
- Vertical dilation (connects stream fragments)
- Ensemble Analysis: Multi-view fusion with confidence weighting
- Flow Estimation: Velocity tracking and volume normalization
- Visualization: Annotated video generation
You can view our presentation here: PPT
- ROI Locking: Automatically locks onto the urine stream position and tracks it throughout the video
- Width-Based Gating: Removes thick objects (hands, body parts) while preserving the thin stream
- Geometric Filtering: Uses aspect ratio analysis to distinguish stream from background artifacts
- Vertical Dilation: Connects broken stream fragments for continuous detection
- Multi-View Support: Combines top and side camera views with confidence weighting
- Qmax: Peak flow rate measurement (ml/s)
- Average Flow Rate: Mean flow throughout voiding
- Flow Time: Duration of actual urine flow
- Voiding Time: Total time from start to finish
- Time to Qmax: Time taken to reach peak flow
- Hesitancy Detection: Identifies delayed stream initiation
- Volume Normalization: Adjusts flow curve to match manually measured voided volume
- JWT-based authentication with role-based access control
- Secure patient data management
- HIPAA-compliant data handling
- Cloudinary integration for secure media storage
- Email notifications for report delivery
- Clinical-grade dual-panel reports
- Interactive flow curve visualization
- Frame-by-frame analysis data (CSV export)
- Annotated video playback with stream overlay
- JSON-formatted metric summaries
| Technology | Purpose |
|---|---|
| React 19 | UI framework with modern hooks |
| Vite | Lightning-fast build tool and dev server |
| TailwindCSS 4 | Utility-first CSS framework |
| React Router | Client-side routing |
| Axios | HTTP client for API communication |
| Simplex Noise | Procedural background animations |
| Technology | Purpose |
|---|---|
| FastAPI | High-performance async web framework |
| SQLAlchemy | ORM for database operations |
| CockroachDB/PostgreSQL | Distributed SQL database |
| Pydantic | Data validation and settings management |
| Python-JOSE | JWT token handling |
| Passlib + Bcrypt | Password hashing |
| Cloudinary | Cloud-based media storage |
| Python-Multipart | File upload handling |
| Technology | Purpose |
|---|---|
| OpenCV | Core computer vision operations |
| NumPy | Numerical computations |
| SciPy | Signal processing and smoothing |
| Pandas | Data manipulation and CSV export |
| Matplotlib | Clinical report visualization |
| MediaPipe | Advanced pose detection (optional) |
clean-doc_ag/
├── Dockothon/
│ ├── arch.png # System architecture diagram
│ │
│ ├── frontend/ # React Web Application
│ │ ├── src/
│ │ │ ├── components/ # Reusable UI components
│ │ │ ├── pages/ # Route-based page components
│ │ │ ├── contexts/ # React context providers
│ │ │ ├── services/ # API service layer
│ │ │ ├── App.jsx # Main application component
│ │ │ └── main.jsx # Application entry point
│ │ ├── package.json
│ │ └── vite.config.js
│ │
│ ├── backend/ # FastAPI Backend
│ │ ├── routers/ # API route handlers
│ │ │ ├── auth_router.py # Authentication endpoints
│ │ │ ├── patient_router.py # Patient management
│ │ │ ├── entry_router.py # Patient entry creation
│ │ │ ├── analysis_router.py # Video analysis triggers
│ │ │ ├── report_router.py # Report generation
│ │ │ ├── doctor_router.py # Doctor management
│ │ │ └── chat_router.py # Chat functionality
│ │ ├── src/ # CV engine integration
│ │ ├── scripts/ # Utility scripts
│ │ ├── config/ # Configuration files
│ │ ├── main.py # FastAPI application
│ │ ├── models.py # SQLAlchemy models
│ │ ├── schemas.py # Pydantic schemas
│ │ ├── database.py # Database connection
│ │ ├── auth.py # Authentication logic
│ │ ├── dependencies.py # Dependency injection
│ │ ├── analysis_runner.py # CV analysis orchestration
│ │ ├── report_generator.py # Report creation
│ │ ├── cloudinary_service.py # Media upload service
│ │ ├── email_service.py # Email notifications
│ │ └── requirements.txt
│ │
│ └── opencv_model/ # Computer Vision Engine
│ ├── src/
│ │ ├── calibration.py # Physical reference detection
│ │ ├── segmentation.py # Stream segmentation (ROI + Width gating)
│ │ ├── tracking.py # Velocity tracking
│ │ ├── flow_estimation.py # Flow rate calculation
│ │ ├── volume.py # Volume normalization
│ │ ├── visualize.py # Video annotation
│ │ └── ensemble/ # Multi-view fusion
│ ├── scripts/
│ │ └── run_analysis.py # Main analysis script
│ ├── data/ # Input videos and calibration
│ ├── outputs/ # Analysis results
│ └── requirements.txt
│
└── README.md # This file
Ensure you have the following installed:
- Node.js (v18 or higher) - Download
- Python (v3.9 or higher) - Download
- PostgreSQL or CockroachDB - PostgreSQL | CockroachDB
- Git - Download
-
Navigate to the backend directory
cd Dockothon/backend -
Create and activate a virtual environment
# Windows python -m venv venv venv\Scripts\activate # macOS/Linux python3 -m venv venv source venv/bin/activate
-
Install dependencies
pip install -r requirements.txt
-
Configure environment variables
# Copy the example environment file cp .env.example .envEdit
.envand configure:# Database DATABASE_URL=postgresql://user:password@localhost:5432/uroflow_db # JWT Secret SECRET_KEY=your-secret-key-here ALGORITHM=HS256 ACCESS_TOKEN_EXPIRE_MINUTES=30 # Cloudinary (for media storage) CLOUDINARY_CLOUD_NAME=your-cloud-name CLOUDINARY_API_KEY=your-api-key CLOUDINARY_API_SECRET=your-api-secret # Email (optional) SMTP_HOST=smtp.gmail.com SMTP_PORT=587 SMTP_USER=your-email@gmail.com SMTP_PASSWORD=your-app-password
-
Initialize the database
python init_db.py
-
Run the backend server
uvicorn main:app --reload --host 0.0.0.0 --port 8000
The API will be available at
http://localhost:8000📚 API Documentation: Visit
http://localhost:8000/docsfor interactive Swagger UI
-
Navigate to the frontend directory
cd Dockothon/frontend -
Install dependencies
npm install
-
Configure API endpoint (if needed)
Create a
.envfile:VITE_API_BASE_URL=http://localhost:8000
-
Run the development server
npm run dev
The application will be available at
http://localhost:5173 -
Build for production (optional)
npm run build npm run preview
-
Navigate to the OpenCV model directory
cd Dockothon/opencv_model -
Create and activate a virtual environment
# Windows python -m venv venv venv\Scripts\activate # macOS/Linux python3 -m venv venv source venv/bin/activate
-
Install dependencies
pip install -r requirements.txt
-
Prepare calibration data
Place a calibration image (
top.png) with a 26cm blue reference line in thedata/directory. -
Run standalone analysis (optional)
python scripts/run_analysis.py \ --top-video data/top.mp4 \ --calibration-image data/top.png \ --output-dir outputs/ \ --volume 369
- Navigate to the frontend application
- Register as a new user (Doctor/Admin)
- Log in with your credentials
- Create patient profiles with demographic information
- View patient history and previous analyses
- Create a new patient entry
- Upload top-view and/or side-view videos
- Provide calibration image (if available)
- Enter manually measured voided volume
- Submit for analysis
- Monitor analysis progress in real-time
- View generated clinical reports
- Download annotated videos
- Export flow data as CSV
- Access JSON metrics
For best results, upload both top and side views:
python scripts/run_analysis.py \
--top-video data/top.mp4 \
--side-video data/side.mp4 \
--calibration-image data/top.png \
--output-dir outputs_ensemble/ \
--volume 369Outputs:
annotated_top.mp4/annotated_side.mp4: Visualization videos with stream overlayclinical_report.png: Clinical-grade dual-panel reportflow_timeseries.csv: Frame-by-frame flow dataqmax_report.json: Summary metrics in JSON format
| Method | Endpoint | Description |
|---|---|---|
| POST | /auth/register |
Register new user |
| POST | /auth/login |
User login (returns JWT) |
| GET | /auth/me |
Get current user info |
| Method | Endpoint | Description |
|---|---|---|
| POST | /patients/ |
Create new patient |
| GET | /patients/ |
List all patients |
| GET | /patients/{id} |
Get patient details |
| PUT | /patients/{id} |
Update patient info |
| DELETE | /patients/{id} |
Delete patient |
| Method | Endpoint | Description |
|---|---|---|
| POST | /entries/ |
Create patient entry with videos |
| GET | /entries/{id} |
Get entry details |
| POST | /analysis/run/{entry_id} |
Trigger CV analysis |
| GET | /reports/{entry_id} |
Get analysis report |
For complete API documentation, visit http://localhost:8000/docs after starting the backend.
The system calculates the following clinical parameters:
| Metric | Description | Unit |
|---|---|---|
| Qmax | Maximum flow rate | ml/s |
| Qavg | Average flow rate | ml/s |
| Flow Time | Duration of continuous flow | seconds |
| Voiding Time | Total time from start to end | seconds |
| Time to Qmax | Time to reach peak flow | seconds |
| Hesitancy | Delay before stream initiation | seconds |
| Voided Volume | Total volume (normalized) | ml |
- Smoothing: Savitzky-Golay filter / Rolling mean
- Clamping: 0-80 ml/s (physiological limits)
- Normalization: Scaled to match manual volume measurement
Frame Input
↓
Background Subtraction (MOG2)
↓
ROI Filtering (if locked)
↓
Width-Based Gating (remove thick objects)
↓
Morphological Cleanup
↓
Vertical Dilation (connect fragments)
↓
Geometric Filtering (aspect ratio)
↓
Stream Contour Output
| Parameter | Value | Purpose |
|---|---|---|
| MOG2 varThreshold | 10 | High sensitivity background subtraction |
| ROI Width | 120px | Narrow focus on stream region |
| Thick Object Kernel | 40×40px | Hand/body part removal |
| Vertical Dilation Kernel | 5×25px | Stream fragment connection |
| Aspect Ratio Threshold | 1.2 (locked) / 2.0 (unlocked) | Stream shape validation |
The system fuses top and side views using confidence-weighted averaging:
Confidence Score is determined by:
- Signal continuity (penalizing dropouts)
- Signal stability (penalizing high-frequency noise)
We welcome contributions! Please follow these steps:
- Fork the repository
- Create a feature branch
git checkout -b feature/amazing-feature
- Commit your changes
git commit -m "Add amazing feature" - Push to the branch
git push origin feature/amazing-feature
- Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- OpenCV Community for the powerful computer vision library
- FastAPI Team for the modern web framework
- React Team for the excellent UI library
- Medical Professionals who provided domain expertise
Built with ❤️ for better healthcare
