树莓派Linux使用OpenCV进行摄像头视频流直播 Linux WiFI图传 Node Addon C++、C++、OpenCV、H264、WebSocket

树莓派Linux使用OpenCV进行摄像头视频流直播

开源地址 https://github.com/gaowanlu/openlive

先看效果

树莓派Linux使用OpenCV进行摄像头视频流直播 Linux WiFI图传 Node Addon C++、C++、OpenCV、H264、WebSocket_第1张图片

原理

因为C++使用网络传输不太方便、完全可以使用Node.js的功能,并使用node-addon-api使得JavaScript程序调用C++模块,C++开启两个线程一个是OpenCV读取摄像头帧数据、另一个为进行H264视频裸流编码,node服务端进行Loop不断得将从C++获得的H264裸流帧数据,利用SocketIO emit给所有WebSocket已经连接的用户

怎样部署

暂时只支持Linux平台,在虚拟机环境下与实际效果帧率示有偏差的哦(建议用实体主机进行测试),虚拟机一般太卡了,如果使用WSL2的话可以下载一个MJPEG Streamer进行jpeg推流,在项目中更改opencv相机打开参数从0改为http地址

请见github的readme的文档,如有问题可以提出issue,欢迎有兴趣的伙伴进行改进贡献提交PR

openlive (network image transmission)

The OpenCV camera video stream used is pushed to the browser solution based on Base64 encoding in H264 format and transmitted using websocket. Use POSIX multithreading and C/C++plugins with Node API.

Can be used on Linux development boards such as Raspberry Pi and Linux system personal computers

scheme


/**************************************************************************/
*     C++ module             <---->  Node SocketIO <---->  Browser(Player) *
* capture thread         <----------                       /|\              *
*    Take Frame(Loop)      start()                          |               *
*   |                                                       |               *
*   | Image(get_mat())                                      |               *
*   |                                                       |               *
*  \|/                                                      |               *
* encode_thread(Loop)                                       |               *
*   |-Convert to YUV color                      (H264Stream)|               *
*   | space                                                 |               *
*   |                                                       |               *
*   |-H264 encoder encodi-                                  |               *
*   | ng                                                    |               *
*   |                                                       |               *
*   |-Add H264 stream                                       |               *
*   | data to buffer                                        |               *
*   | queue                                                 |               *
*      |                              (Loop)                |               *
*      |------------------------->   io.emit()  ------------|               *
*           getFrame(Blocking)                                              *
*                                                                           *
/**************************************************************************/

environmental preparation

libx264(https://www.videolan.org/developers/x264.html)
opencv(https://github.com/opencv/opencv)

sudo apt install libx264-dev
sudo apt install -g node-gyp
sudo apt install libopencv-dev pkg-config
npm install

compile to run

node-gyp configure
npm run build
node index

Browser Access http://IP:8887

你可能感兴趣的:(c++,linux,OpenCV与视觉,opencv,c++,H264,树莓派图传,Linux网络图传)