https://github.com/iammi/handcap-edge
Embeded competition ---- Edge
https://github.com/iammi/handcap-edge
cpp embedded-systems
Last synced: 12 months ago
JSON representation
Embeded competition ---- Edge
- Host: GitHub
- URL: https://github.com/iammi/handcap-edge
- Owner: IamMI
- Created: 2025-07-09T13:59:41.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2025-07-09T14:01:52.000Z (12 months ago)
- Last Synced: 2025-07-09T15:20:26.087Z (12 months ago)
- Topics: cpp, embedded-systems
- Language: C++
- Homepage:
- Size: 12.6 MB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ๐น Embedded YOLO-Based RTMP Streaming System
This project is a lightweight real-time video stream detection and streaming system deployed on the Loongson embedded development board, featuring:
- Capturing camera frames using V4L2 (MJPEG format)
- Decoding to BGR images using OpenCV
- Detecting human presence using YOLOv5
- Triggering detection every few frames and sending alerts via HTTP POST upon detection
- Encoding and streaming frames to RTMP server via FFmpeg
## ๐งฉ System Architecture
```text
[Camera (/dev/video0)] --> [V4L2 + OpenCV decoding] --> [YOLOv5 detection thread]
| |
|-----> RTMP stream via FFmpeg ----------------|
|-----> Alert system (curl POST JSON to server)|
```
## ๐ Features
- ๐ฅ **MJPEG camera** frame capture
- ๐ค Lightweight **YOLOv5-based** human detection
- ๐ Send alert events to remote server using **curl**
- ๐ก Real-time streaming (RTMP via **FFmpeg** subprocess)
- ๐งต **Multithreaded** architecture with **condition variable** synchronization
- ๐ฅ๏ธ Compatible with embedded Linux (e.g., **Loongson** platform)
## ๐ฆ Build Dependencies
- C++17 or later
- OpenCV
- FFmpeg (must be available via CLI)
- libcurl
- V4L2 (included in Linux kernel)
## ๐ง Usage
1. Prepare the camera device
Make sure the device `/dev/video0` is accessible and supports MJPEG format.
> If the device `/dev/video0` is not recognized after connecting the camera, it may be due to missing drivers in your board's Linux system. In that case, a kernel replacement might be necessary.
2. Create your own server like aliyun, expose its IP and some ports and rewrite
```C++
const std::string RTMP_LIVE = "rtmp://Your server IP:Port1/stream1";
```
and
```C++
const std::string alertUrl = "http://Your server IP:Port2/alert";
```
3. Compile the program (*adjust paths as needed*)
```bash ๅคๅถ ็ผ่พ
g++ -std=c++17 camera.cpp yolo.cpp \
-I/home/loongson/ncnn/build/install/include/ncnn \
-L/home/loongson/ncnn/build/install/lib \
-L/usr/lib/loongarch64-linux-gnu \
-lncnn -lopencv_core \
-lopencv_highgui -lopencv_videoio \
-lopencv_imgproc -lopencv_imgcodecs \
-lavcodec -lavformat -lavutil -lswscale -fopenmp \
-march=loongarch64 \
-lcurl -o camera
```
4. Run the program
```bash ๅคๅถ ็ผ่พ
./camera
```
## โ ๏ธ Alert Mechanism
When a person is detected (every 60 frames), the system sends an alert via the following HTTP interface:
```http ๅคๅถ ็ผ่พ
POST http://Your server IP:Port/alert
Content-Type: application/json
{
"event": "person_detected",
"camera": "main_camera"
}
```
## ๐ Project Structure (Partial)
```
.
โโโ camera.cpp # Main program: video capture, multithreading, RTMP streaming
โโโ yolo.hpp # YOLO model interface definitions
โโโ yolo.cpp # YOLO model loading and inference implementation
โโโ build/ # Build output directory (optional)
```
## ๐ TODO
- [ ] Support multiple camera switching
- [ ] Add image compression and encoding optimization
- [ ] Accelerate YOLO inference with CUDA / NPU