代码拉取完成,页面将自动刷新
/*********************************
* 闯右转红灯类
* @ZZH
* date:2019/9/23
* *******************************/
#include "red_right.h"
red_right::red_right()
{
}
//右转ROI区域储存函数
std::vector<cv::Rect> red_right::red_right_ROI(cv::Rect roi_1st, cv::Rect roi_2nd)
{
std::vector<cv::Rect>ROI_AREA;
ROI_AREA.push_back(roi_1st);
ROI_AREA.push_back(roi_2nd);
return ROI_AREA;
}
//判断闯右转红灯函数
std::vector<float> red_right::rules(std::vector<cv::Rect> roi, std::vector<std::vector<float> > car, const cv::Mat &img)
{
extern cv::Mat right_license;
extern cv::Mat no;
//判断车辆是否先后进入了两个ROI区域,可判定违章
for (int i=0;i<(int)car.size();i+=1){
for (int j=0;j<(int)car[i].size();j+=2){
if (pre.roi_judge(car[i][j],car[i][j+1],roi[0])){
if (first_time){
//闯入第一个ROI后先存入时图像break1,等待闯入第二个ROI
img.copyTo(break1);
cv::rectangle(break1, cv::Rect(car[i][j]-220,car[i][j+1]-220,440,440),cv::Scalar(0,0,255),3,8,0);
car_br = pre.slice(break1,cv::Rect(car[i][j]-210,car[i][j+1]-210,420,420));
first_time = false;
}
for (int z=j;z!=(int)car[i].size();z+=2){
if (pre.roi_judge(car[i][z],car[i][z+1],roi[1])){
target.push_back(i);
target.push_back(j);
target.push_back(z);
if (second_time){
//闯入第二个ROI后储存临时图像break2
img.copyTo(break2);
cv::rectangle(break2, cv::Rect(car[i][z]-220,car[i][z+1]-220,440,440),cv::Scalar(0,0,255),3,8,0);
cv::resize(break1,break1,cv::Size(1080,720));
cv::resize(break2,break2,cv::Size(1080,720));
//违章证据保存
x = snprintf(pic_name,sizeof(pic_name),"break_right_car%d_first_evid.jpg",num);
cv::imwrite(pic_name,break1);
y = snprintf(pic_name,sizeof(pic_name),"break_right_car%d_second_evid.jpg",num);
cv::imwrite(pic_name,break2);
//违章车辆保存
z = snprintf(pic_name,sizeof(pic_name),"right_car%d.jpg",num);
cv::imwrite(pic_name,car_br);
car_br_e=cv::imread(pic_name);
car_license= car_lic.detection(car_br_e);
//违章车牌保存
e = snprintf(pic_name,sizeof(pic_name),"right_car%d_license.jpg",num);
cv::imwrite(pic_name,car_license);
right_license = cv::imread(pic_name);
if(right_license.empty())
{
right_license = no;
}
cv::resize(right_license,right_license,cv::Size(52,16));
cv::cvtColor(right_license,right_license,COLOR_BGR2RGB);
second_time = false;
num+=1;
}
return target;
}
}
}
}
}
//次数核查
//std::cout<<"_right_"<<std::endl;
return target;
}
//资源释放函数
void red_right::red_right_release()
{
target.clear();
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。