根据距离标框完成
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
本程序用于视频分流
|
||||
1.推流摄像头画面,使用UDP原生协议进行推流,交由YOLO模型进行处理
|
||||
2.接收YOLO传来的坐标,深度,警报等级等等数据
|
||||
2.接收YOLO传来的坐标和度数据
|
||||
3.根据获取到的数据绘制边框和相应数据
|
||||
4.将绘制完毕的视频流继续推流至RTSP服务器用于输出
|
||||
*/
|
||||
@@ -16,7 +16,10 @@
|
||||
#include <condition_variable>
|
||||
#include <atomic>
|
||||
|
||||
#include "Netra.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace QCL;
|
||||
using namespace cv;
|
||||
using namespace chrono_literals;
|
||||
|
||||
@@ -26,6 +29,7 @@ Mat handleFrame; // 存放处理后的帧
|
||||
const string mqtt_url = "tcp://192.168.12.1:1883";
|
||||
const string clientId = "video_subData";
|
||||
const string Topic = "/video/PersonData";
|
||||
const string filePath = "../../InitAuth/conf/.env"; // 配置保存路径
|
||||
const int Qos = 0;
|
||||
mqtt::async_client client(mqtt_url, clientId);
|
||||
|
||||
@@ -36,6 +40,14 @@ struct Dection
|
||||
double distance;
|
||||
};
|
||||
|
||||
// 保存报警距离
|
||||
struct dangerDistance
|
||||
{
|
||||
int danger;
|
||||
int warn;
|
||||
int safe;
|
||||
} dis;
|
||||
|
||||
mutex detMutex; // 保护latestDection的互斥锁
|
||||
vector<Dection> latestDection; // 保存最新接收到的检测结果
|
||||
|
||||
@@ -60,6 +72,8 @@ void mainLoop(VideoCapture &cap, FILE *pipe);
|
||||
void getMsgCallback(mqtt::const_message_ptr msg);
|
||||
// 绘制矩形方框和深度信息
|
||||
void drawRect(int x, int y, int w, int h, double distance);
|
||||
// 获取报警距离
|
||||
bool GetDistance();
|
||||
|
||||
int main()
|
||||
{
|
||||
@@ -88,11 +102,53 @@ int main()
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 获取报警距离
|
||||
bool GetDistance()
|
||||
{
|
||||
// 获取距离信息
|
||||
ReadFile rf(filePath);
|
||||
if (rf.Open() == false)
|
||||
{
|
||||
cerr << "文件打开失败" << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
auto lines = rf.ReadLines();
|
||||
string str;
|
||||
for (auto &line : lines)
|
||||
{
|
||||
if (line.find("NEAR_THRESHOLD=") != string::npos)
|
||||
dis.danger = stoi(line.substr(sizeof("NEAR_THRESHOLD=") - 1));
|
||||
else if (line.find("MID_THRESHOLD=") != string::npos)
|
||||
dis.warn = stoi(line.substr(sizeof("MID_THRESHOLD=") - 1));
|
||||
else if (line.find("MAX_DISTANCE=") != string::npos)
|
||||
dis.safe = stoi(line.substr(sizeof("MAX_DISTANCE=") - 1));
|
||||
}
|
||||
|
||||
rf.Close();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// 绘制矩形方框和深度信息
|
||||
void drawRect(int x, int y, int w, int h, double distance)
|
||||
{
|
||||
Rect r(x, y, w, h);
|
||||
rectangle(handleFrame, r, Scalar(0, 255, 0), 2);
|
||||
Scalar sca;
|
||||
if (GetDistance() == false)
|
||||
{
|
||||
sca = Scalar(0, 0, 0);
|
||||
}
|
||||
|
||||
if (distance <= dis.danger)
|
||||
sca = Scalar(0, 0, 255);
|
||||
else if (distance <= dis.warn)
|
||||
sca = Scalar(0, 255, 255);
|
||||
else
|
||||
sca = Scalar(0, 255, 0);
|
||||
|
||||
rectangle(handleFrame, r, sca, 2);
|
||||
putText(handleFrame,to_string(distance),Point(x,y),FONT_HERSHEY_SIMPLEX,0.35,Scalar(0,0,0));
|
||||
}
|
||||
|
||||
// mqtt初始化
|
||||
|
||||
@@ -3,8 +3,11 @@ all: video
|
||||
PKG_CFLAGS := $(shell pkg-config --cflags opencv4)
|
||||
PKG_LIBS := $(shell pkg-config --libs opencv4)
|
||||
|
||||
Lib=/home/orangepi/RKApp/VideoProsessing/NetraLib/src/Netra.cpp
|
||||
Dir=/home/orangepi/RKApp/VideoProsessing/NetraLib/include
|
||||
|
||||
video: main.cpp
|
||||
g++ -g -o video main.cpp $(PKG_CFLAGS) $(PKG_LIBS) -lpaho-mqttpp3 -lpaho-mqtt3a -lpthread
|
||||
g++ -g -o video main.cpp $(Lib) -I$(Dir) $(PKG_CFLAGS) $(PKG_LIBS) -lpaho-mqttpp3 -lpaho-mqtt3a -lpthread
|
||||
mv video ../bin/
|
||||
|
||||
clean:
|
||||
|
||||
Reference in New Issue
Block a user