finnal
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
本程序用于设备激活
|
||||
当检测配置文件发现设备未激活时,则系统阻塞
|
||||
进行激活,并保存密文
|
||||
当检测到设备已被激活后,启动验证程序,并退出本程序
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
@@ -1794,17 +1794,11 @@ def main():
|
||||
if not math.isnan(distance_meters):
|
||||
distances.append(distance_meters)
|
||||
|
||||
# ⭐ Send distance via WebSocket (只在危险区域内才发送)
|
||||
# ⭐ Send distance via WebSocket (最近距离)
|
||||
if len(distances) > 0:
|
||||
valid_dists = [d for d in distances if np.isfinite(d)]
|
||||
if valid_dists:
|
||||
min_distance = min(valid_dists)
|
||||
# 只有当最近距离小于MAX_DISTANCE(危险区域)时才发送
|
||||
if min_distance < MAX_DISTANCE:
|
||||
uploader.send_distance(min_distance)
|
||||
print(f"[WebSocket] ⚠️ 发送报警:最近距离 {min_distance:.2f}m < {MAX_DISTANCE:.2f}m")
|
||||
else:
|
||||
print(f"[WebSocket] ✅ 安全距离:最近距离 {min_distance:.2f}m >= {MAX_DISTANCE:.2f}m,不发送")
|
||||
uploader.send_distance(min(valid_dists))
|
||||
|
||||
# ⭐ 绘制警告覆盖层
|
||||
draw_warning_overlay(frame, distances)
|
||||
|
||||
BIN
VideoProsessing/bin/video
Executable file
BIN
VideoProsessing/bin/video
Executable file
Binary file not shown.
104
VideoProsessing/src/main.cpp
Normal file
104
VideoProsessing/src/main.cpp
Normal file
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
本程序用于视频分流
|
||||
1.推流摄像头画面至RTSP服务器,交由YOLO模型进行处理
|
||||
2.接收YOLO传来的坐标,深度,警报等级等等数据
|
||||
3.根据获取到的数据绘制边框和相应数据
|
||||
4.将绘制完毕的视频流继续推流至RTSP服务器用于输出
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <opencv4/opencv2/opencv.hpp>
|
||||
#include <mqtt/async_client.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
using namespace chrono_literals;
|
||||
|
||||
int main()
|
||||
{
|
||||
VideoCapture cap(0);
|
||||
// 直接传 MJPEG(本身就是全 I 帧)
|
||||
FILE *pipe = popen(
|
||||
"ffmpeg "
|
||||
"-f rawvideo -pixel_format bgr24 -video_size 640x480 -framerate 30 "
|
||||
"-i - "
|
||||
"-c:v h264_rkmpp "
|
||||
"-rc_mode 2 " // CQP 模式
|
||||
"-qp_init 30 "
|
||||
"-profile baseline "
|
||||
"-g 1 " // 全 I 帧
|
||||
"-bf 0 "
|
||||
"-coder cavlc "
|
||||
"-8x8dct false "
|
||||
"-fflags nobuffer "
|
||||
"-flags low_delay "
|
||||
"-max_delay 0 "
|
||||
"-f rtsp -muxdelay 0.001 -rtsp_transport udp "
|
||||
"rtsp://192.168.12.1:8554/rtsp/test", "w");
|
||||
|
||||
if (pipe) {
|
||||
setvbuf(pipe, NULL, _IONBF, 0); // 添加无缓冲模式
|
||||
}
|
||||
if (!pipe)
|
||||
{
|
||||
cerr << "popen faild\n";
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (cap.isOpened() == false)
|
||||
{
|
||||
cerr << "摄像头打开失败,请重试" << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// 降低分辨率,固定MJPG编码
|
||||
cap.set(CAP_PROP_FOURCC, VideoWriter::fourcc('M', 'J', 'P', 'G'));
|
||||
cap.set(CAP_PROP_FRAME_WIDTH, 640);
|
||||
cap.set(CAP_PROP_FRAME_HEIGHT, 480);
|
||||
cap.set(CAP_PROP_FPS, 30);
|
||||
|
||||
cap.set(CAP_PROP_BUFFERSIZE, 1);
|
||||
|
||||
int64 count = 0;
|
||||
auto t0 = chrono::steady_clock::now();
|
||||
|
||||
Mat frame;
|
||||
while (true)
|
||||
{
|
||||
cap.read(frame);
|
||||
if (frame.empty())
|
||||
{
|
||||
cerr << "读取帧失败" << endl;
|
||||
break;
|
||||
}
|
||||
|
||||
putText(frame, "press 'q' to quit", Point(0, 20), FONT_HERSHEY_SIMPLEX, 1.0, Scalar(0, 255, 0), 2, LINE_8);
|
||||
|
||||
++count;
|
||||
auto now = chrono::steady_clock::now();
|
||||
string fps;
|
||||
if (chrono::duration_cast<chrono::milliseconds>(now - t0).count() / 1000.0 > 1.0)
|
||||
{
|
||||
fps = "FPS:" + to_string(count);
|
||||
setWindowTitle("测试画面", fps);
|
||||
count = 0;
|
||||
t0 = now;
|
||||
}
|
||||
|
||||
fwrite(frame.data, 1, frame.total() * frame.elemSize(), pipe);
|
||||
fflush(pipe); // 立即刷新
|
||||
// imshow("测试画面", frame);
|
||||
|
||||
// 按下 'q' 键退出
|
||||
if (cv::waitKey(1) == 'q')
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 释放资源
|
||||
pclose(pipe);
|
||||
cap.release();
|
||||
destroyAllWindows();
|
||||
return 0;
|
||||
}
|
||||
11
VideoProsessing/src/makefile
Normal file
11
VideoProsessing/src/makefile
Normal file
@@ -0,0 +1,11 @@
|
||||
all: video
|
||||
|
||||
PKG_CFLAGS := $(shell pkg-config --cflags opencv4)
|
||||
PKG_LIBS := $(shell pkg-config --libs opencv4)
|
||||
|
||||
video: main.cpp
|
||||
g++ -g -o video main.cpp $(PKG_CFLAGS) $(PKG_LIBS) -lpaho-mqttpp3 -lpaho-mqtt3a -lpthread
|
||||
mv video ../bin/
|
||||
|
||||
clean:
|
||||
rm -rf ../bin/video
|
||||
@@ -378,10 +378,11 @@ void VideoStream()
|
||||
// 静音ffmpeg的统计输出,保留错误;避免污染日志
|
||||
// string commnd = "ffmpeg -nostats -hide_banner -loglevel error -f v4l2 -i /dev/video0 -c:v h264_rkmpp -rtsp_transport tcp -f rtsp rtsp://192.168.12.1:8554/stream 2>/dev/null";
|
||||
string commnd =
|
||||
"VIDEO_SIZE=$(xdpyinfo | awk '/dimensions:/ {print $2}'); "
|
||||
"DISPLAY_VAL=${DISPLAY:-:0.0}; "
|
||||
"export DISPLAY=${DISPLAY:-:0}; "
|
||||
"VIDEO_SIZE=$(DISPLAY=$DISPLAY xdpyinfo 2>/dev/null | awk '/dimensions:/ {print $2}'); "
|
||||
"if [ -z \"$VIDEO_SIZE\" ]; then VIDEO_SIZE=1920x1080; fi; "
|
||||
"ffmpeg -nostats -hide_banner -loglevel error "
|
||||
"-f x11grab -framerate 15 -video_size \"$VIDEO_SIZE\" -i \"$DISPLAY_VAL\" "
|
||||
"-f x11grab -framerate 15 -video_size \"$VIDEO_SIZE\" -i \"$DISPLAY\" "
|
||||
"-c:v h264_rkmpp -b:v 2000k -f rtsp rtsp://192.168.12.1:8554/stream 2>/dev/null";
|
||||
video_proc = bp::child("/bin/bash", bp::args = {"-c", commnd});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user