An open API service indexing awesome lists of open source software.

https://github.com/umercodez/websocketcam

Access Android camera via WebSocket client API and run AI / computer vision tasks with ease on live camera stream
https://github.com/umercodez/websocketcam

ai-image-detection android-camera camera camera-streamer computer-vision computer-vision-opencv computer-vision-tools image-processing live-camera live-image-recognition object-detection pose-detection websocket

Last synced: 6 days ago
JSON representation

Access Android camera via WebSocket client API and run AI / computer vision tasks with ease on live camera stream

Awesome Lists containing this project

README

          

# Websocket CAM

![GitHub License](https://img.shields.io/github/license/UmerCodez/LittleRelay?style=for-the-badge) ![Android Badge](https://img.shields.io/badge/Android-7.0+-34A853?logo=android&logoColor=fff&style=for-the-badge) ![Jetpack Compose Badge](https://img.shields.io/badge/Jetpack%20Compose-4285F4?logo=jetpackcompose&logoColor=fff&style=for-the-badge) ![Material 3](https://img.shields.io/badge/Material%203-ebe89d?style=for-the-badge&logo=materialdesign&logoColor=white) ![GitHub Release](https://img.shields.io/github/v/release/UmerCodez/WebsocketCAM?include_prereleases&style=for-the-badge)

[](https://github.com/UmerCodez/WebsocketCAM/releases) [](https://f-droid.org/packages/app.umerfarooq.websocketcam/) [](https://github.com/ImranR98/Obtainium)

### Access Android camera using a WebSocket client API to perform real-time AI and computer vision tasks on a live video stream.

The app broadcasts live camera frames as **JPEG** images over WebSocket connections, where each **JPEG** image is received as a **byte array** through the WebSocket’s `onMessage` callback. The app supports multiple client connections, enabling each client to independently perform AI or computer vision processing in parallel.

### Features
- Supports multiple websocket client connections
- Change camera settings without restarting the Websocket Server
- Access the live feed directly from a browser over the local network via browser's websocket client API (not browser's address bar)
- No ads, no tracking and no data collection

## Displaying live camera stream using Python
A simple Python example using OpenCV and WebSocket libraries to connect to the WebSocket CAM app and display the live camera stream.

```bash
pip install opencv-python numpy websocket-client
```

```python
import cv2
import numpy as np
import websocket

SERVER_URL = "ws://192.168.18.50:8080"

def on_message(ws, message):
# Convert received bytes into numpy array
np_arr = np.frombuffer(message, np.uint8)

# Decode JPEG
frame = cv2.imdecode(np_arr, cv2.IMREAD_COLOR)

if frame is not None:
cv2.imshow("Camera Stream", frame)
if cv2.waitKey(1) & 0xFF == 27: # ESC key to exit
ws.close()
cv2.destroyAllWindows()
else:
print("Failed to decode frame")

def on_error(ws, error):
print("WebSocket error:", error)

def on_close(ws, close_status_code, close_msg):
print("Connection closed:", close_status_code, close_msg)
cv2.destroyAllWindows()

def on_open(ws):
print("Connected to Websocket CAM, open camera to see live stream")

if __name__ == "__main__":
websocket.enableTrace(False)
ws = websocket.WebSocketApp(
SERVER_URL,
on_open=on_open,
on_message=on_message,
on_error=on_error,
on_close=on_close,
)

try:
ws.run_forever()
except KeyboardInterrupt:
print("\n Stopped by user")
ws.close()
cv2.destroyAllWindows()
```

Start the WebSocket server in the app, then run the this Python script in **multiple terminals** to view **multiple live streams** simultaneously

## Demo (Youtube)
See the demo on Youtube 👇

[![IMAGE ALT TEXT HERE](https://img.youtube.com/vi/OIhSXAkaWBA/0.jpg)](https://www.youtube.com/watch?v=OIhSXAkaWBA)

### Examples
Working examples of this app are availbe here [WebsocketCAM examples](https://github.com/UmerCodez/WebsocketCAM-examples)

![Alt Text](https://github.com/UmerCodez/WebsocketCAM-examples/blob/main/assets/hand-keypoint-detection.gif) ![Alt Text](https://github.com/UmerCodez/WebsocketCAM-examples/blob/main/assets/Object-Detection.gif) ![Alt Text](https://github.com/UmerCodez/WebsocketCAM-examples/blob/main/assets/pose-detection.gif) ![Alt Text](https://github.com/UmerCodez/WebsocketCAM-examples/blob/main/assets/finger-drawing.gif)