1 Star 0 Fork 0

NJUPT-B523/Intelligent Traffic Violation Detection

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
illegal_process_l.cpp 5.11 KB
一键复制 编辑 原始数据 按行查看 历史
江斌 提交于 2021-08-22 15:41 . YDS 2019
/*********************************
* 左线程预处理类
* @ZZH
* date:2019/9/23
* *******************************/
#include "illegal_process_l.h"
illegal_process_l::illegal_process_l()
{
}
//目标中心点坐标函数
float illegal_process_l::distance(float x0, float y0, float x1, float y1)
{
d = sqrt(pow(x1-x0,2)+pow(y1-y0,2));
return d;
}
//目标中心点距离函数
std::vector<float> illegal_process_l::cpoint_cal(std::vector<float> dect)
{
extern Rect l_rect;
std::vector<float>cpoint;
for (int i=0;i<(int)dect.size();i++){ //把框中的坐标转换并计算中心点,并把他们分别放入对应的容器
float sign = dect[i], bias = dect[i+1]; //读取对应的坐标(x,y)
if (sign == 7 && bias<2000){
float x = l_rect.x+(l_rect.width/300.0)*(dect[i+1]+dect[i+3])/2.0;
float y = l_rect.y+(l_rect.height/300.0)*(dect[i+2]+dect[i+4])/2.0;
cpoint.push_back(x);
cpoint.push_back(y);
}
}
return cpoint;
}
//车辆分类函数
std::vector<float> illegal_process_l::classific_car(std::vector<float> car, float x_fir, float y_fir, float x_sec, float y_sec)
{
count = true;
float x_last=0.0,y_last=0.0,distance_fir=0.0,distance_sec=0.0;
if (car.empty()){
car.push_back(x_fir);
car.push_back(y_fir);
car.push_back(x_sec);
car.push_back(y_sec);
count = false;
}else{
x_last = car[(int)car.size()-2];
y_last = car[(int)car.size()-1];
distance_fir = distance(x_last,y_last,x_fir,y_fir);
distance_sec = distance(x_last,y_last,x_sec,y_sec);
if ((distance_fir<20) && (distance_sec<50)){
car.push_back(x_sec);
car.push_back(y_sec);
count = false;
}
}
return car;
}
//切片函数,负责提取图像的主要处理区域
cv::Mat illegal_process_l::slice(const cv::Mat &image, const cv::Rect &rect)
{
cv::Mat cut,result;
cut = image(rect);
cut.copyTo(result);
return result;
}
//ROI区域判定函数
bool illegal_process_l::roi_judge(int x,int y,cv::Rect roi)
{
int roi_x0 = roi.x, roi_y0 = roi.y;
int roi_x1 = roi.x+roi.width, roi_y1 = roi.y+roi.height;
if (x >= roi_x0 && x<= roi_x1 && y >= roi_y0 && y <= roi_y1){
return true;
}else{
return false;
}
}
//轨迹跟踪函数
std::vector<std::vector<float> > illegal_process_l::obj_process(std::vector<float> dect_fir,std::vector<float> dect_sec)
{
float dis=0;
std::vector<float>cpoint_fir;
std::vector<float>cpoint_sec;
cpoint_fir = cpoint_cal(dect_fir); //计算中心点
cpoint_sec = cpoint_cal(dect_sec);
for (int m=0;m!=(int)cpoint_fir.size();m+=2){ //算出点之间的距离,并储存满足阈值的点的序号至connect中
for (int n=0;n!=(int)cpoint_sec.size();n+=2){
dis = distance(cpoint_fir[m],cpoint_fir[m+1],cpoint_sec[n],cpoint_sec[n+1]);
if (dis>5 && dis<150){
car1 = classific_car(car1,cpoint_fir[m],cpoint_fir[m+1],cpoint_sec[n],cpoint_sec[n+1]);
if (count == true)
car2 = classific_car(car2,cpoint_fir[m],cpoint_fir[m+1],cpoint_sec[n],cpoint_sec[n+1]);
if (count == true)
car3 = classific_car(car3,cpoint_fir[m],cpoint_fir[m+1],cpoint_sec[n],cpoint_sec[n+1]);
if (count == true)
car4 = classific_car(car4,cpoint_fir[m],cpoint_fir[m+1],cpoint_sec[n],cpoint_sec[n+1]);
if (count == true)
car5 = classific_car(car5,cpoint_fir[m],cpoint_fir[m+1],cpoint_sec[n],cpoint_sec[n+1]);
if (count == true)
car6 = classific_car(car6,cpoint_fir[m],cpoint_fir[m+1],cpoint_sec[n],cpoint_sec[n+1]);
if (count == true)
car7 = classific_car(car7,cpoint_fir[m],cpoint_fir[m+1],cpoint_sec[n],cpoint_sec[n+1]);
if (count == true)
car8 = classific_car(car8,cpoint_fir[m],cpoint_fir[m+1],cpoint_sec[n],cpoint_sec[n+1]);
if (count == true)
car9 = classific_car(car9,cpoint_fir[m],cpoint_fir[m+1],cpoint_sec[n],cpoint_sec[n+1]);
}
}
}
classify[0] = car1;
classify[1] = car2;
classify[2] = car3;
classify[3] = car4;
classify[4] = car5;
classify[5] = car6;
classify[6] = car7;
classify[7] = car8;
classify[8] = car9;
cpoint_fir.clear();
cpoint_sec.clear();
return classify;
}
//违章处理函数
void illegal_process_l::punish(std::vector<float> tar_car)
{
if (!tar_car.empty()){
for (int i=0;i<(int)tar_car.size();i+=3){
std::cout<<"车辆:"<<tar_car[i]<<" 第一区域取证: 第"<<1+tar_car[i+1]/2<<"帧,"
<<" 第二区域取证: 第"<<1+tar_car[i+2]/2<<"帧, "<<"确实闯红灯"<<std::endl;
}
}
}
//资源释放函数
void illegal_process_l::pub_release()
{
car1.clear();
car2.clear();
car3.clear();
car4.clear();
car5.clear();
car6.clear();
car7.clear();
car8.clear();
car9.clear();
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/njupt-b523/intelligent-traffic-violation-detection.git
git@gitee.com:njupt-b523/intelligent-traffic-violation-detection.git
njupt-b523
intelligent-traffic-violation-detection
Intelligent Traffic Violation Detection
master

搜索帮助