A simple Flask app for video streaming and image capture using OpenCV.
- Live video streaming via
/video_feedendpoint - Image capture via
/captureendpoint (POST request) - Download latest captured image via
/imageendpoint - Health check endpoint at
/health - Graceful shutdown via
/shutdownendpoint - Automatic IP detection or manual host/port configuration
- Cross-platform compatibility (works with PyInstaller)
- Python 3.7+
- Virtual environment (recommended)
- Camera connected to your system
-
Clone this repository.
-
Create and activate a virtual environment:
python -m venv venv
source venv/bin/activate # Linux/MacOS
.\venv\Scripts\activate # Windows- Install the required dependencies:
pip install -r requirements.txtpython run.pypython run.py --host 0.0.0.0 --port 8080The server already uses Waitress (a production WSGI server) by default.
GET /video_feed- Live video stream (MJPEG)POST /capture- Capture and save an imageGET /image- Download the latest captured imageGET /health- Health check endpointPOST /shutdown- Gracefully shutdown the server
To create a standalone executable:
- Install PyInstaller:
pip install pyinstaller- Compile the application:
pyinstaller --onefile run.pyfor windows 11
python patch.py && pyinstaller --noconsole --onefile --manifest manifest.xml run.py - The executable will be in the
distfolder. Run it with:
./dist/run- The server automatically creates an
imagesdirectory to store captured images - Default port is 5000
- Host IP is auto-detected (can be overridden with
--hostargument)
- If the camera isn't working, verify it's properly connected
- Make sure no other application is using the camera
- Check firewall settings if accessing from another machine
- For port conflicts, try a different port with
--port