This project provides a browser-based interface for live streaming and controlling a Basler industrial camera using Python and Flask. It is designed for lab automation, diagnostics imaging, and remote camera monitoring, with real-time camera control and basic image statistics.
• Live grayscale video streaming in the browser
• Adjustable exposure and gain
• Real-time image statistics (max and mean pixel intensity)
• Threshold-based visual trigger mode
• User login and session control
• Real-time updates using WebSockets
• Raspberry Pi compatible (USB3 cameras recommended)
The complete source code is available on GitHub:
https://github.com/chetanyajain-lbl/wirelesscamera
To download the code:
git clone https://github.com/chetanyajain-lbl/wirelesscamera
cd wirelesscamera
The system uses a Flask web server to communicate with a Basler camera via the pypylon SDK. Images are streamed to the browser as MJPEG, allowing real-time viewing without additional plugins.
Main components:
• Flask – Web server and routing
• pypylon – Basler camera interface
• OpenCV – JPEG image encoding
• NumPy – Image analysis
• Socket.IO – Real-time UI updates
Camera access is protected using thread locks to ensure safe operation.
The camera is initialized at startup and set to continuous acquisition mode
Frames are captured and converted to grayscale images
Image statistics (max and mean intensity) are calculated
Optional trigger logic modifies the displayed image
Frames are encoded as JPEG and streamed to the browser
The frame rate is limited to approximately 10 frames per second.
When the count trigger is enabled, the system continuously monitors the mean pixel intensity of each frame.
If the mean intensity falls below a user-defined threshold:
• The displayed image turns white
• This visually indicates a low-signal or blocked condition
Valid threshold range: 0 to 255
Open a web browser (Chrome recommended)
Navigate to:
http://:5000
Log in using the configured username and password
Exposure (milliseconds)
Controls how long the sensor collects light. Increasing exposure increases brightness. Exposure values are automatically rounded to valid camera steps.
Gain
Amplifies the image signal. Higher gain increases noise. Use gain only after adjusting exposure.
Trigger Mode
OFF: Continuous live streaming
ON: External hardware trigger required
Count Trigger
Enables threshold-based visual indication when image intensity drops below the threshold.
Max Count
The brightest pixel value in the current frame (0–255)
Mean Count
The average pixel intensity of the frame
If the stream is not active, values display as “N/A”.
Create a file named config.yaml in the project directory.
Example:
username: operator
password: securepassword
• Raspberry Pi 4 (4GB or 8GB RAM)
• Basler USB3 camera
• Active cooling (fan or heatsink)
• High-quality USB 3.0 cable
USB3 cameras are strongly recommended. GigE cameras are not recommended on Raspberry Pi without additional networking hardware.
Raspberry Pi OS (64-bit, Lite version recommended)
sudo apt update && sudo apt upgrade -y
sudo apt install python3 python3-pip python3-venv libopencv-dev libyaml-dev git
Download the ARM64 pylon SDK from the Basler website
Install the package
Verify installation by running:
pylon-version
python3 -m venv venv
source venv/bin/activate
pip install flask flask-session flask-socketio eventlet pypylon numpy pyyaml opencv-python-headless
sudo usermod -aG video $USER
reboot
source venv/bin/activate
python app.py
Access the web interface at:
http://:5000
For lab deployments, the application can be configured to start automatically using a systemd service.
This ensures the camera interface is available after power cycling.
• One camera per Raspberry Pi is recommended
• Frame rate is limited by CPU performance
• Avoid unplugging the camera while the application is running
• Stable lighting improves trigger reliability
• Lab automation dashboards
• Diagnostics and imaging experiments
• Remote camera monitoring
• Vision-based fault detection