examples/client.py
Python Script for Real-Time Video Processing and Streaming
Dependencies:
- OpenCV: Used for video capturing and image processing.
- Base64: Used for encoding binary data into ASCII characters.
- SocketIO: Used for real-time communication between the client and the server.
- NumPy: Used for handling large, multi-dimensional arrays and matrices.
- Time: Used for time-related tasks, such as waiting for the server to start.
Workflow:
- Server Initialization Wait:
- Waits 5 seconds for the server to be fully operational before attempting to connect.
- SocketIO Client Setup:
- Establishes a connection to the server running on 42069.
- Processing Frame Callback:
- Listens for “gray-response” events from the server
- Upon receiving data, decodes and converts it into a NumPy array for further processing.
- Video Capture:
- Starts capturing video from the default webcam (device index 0).
- Continuously reads frames from the webcam in a loop.
- Frame Encoding and Sending:
- Encodes the captured video frame into JPG format.
- Encodes this JPG image into a base64 string and sends it to the server for grayscale processing
- FPS Calculation:
- Calculates the Frames Per Second (FPS) of the video stream.
- Frame Display:
- Checks if a processed frame is available
- Resizes the original and processed frames to have the same height.
- Concatenates these frames side-by-side and displays them in a single window.
- Cleanup:
- Releases the webcam.
- Closes all OpenCV windows.
- Disconnects the SocketIO client.