From fa8183035cd924444e5c5fcfba9f11f3e6b4cb7e Mon Sep 17 00:00:00 2001 From: Zhao Shuaihua Date: Thu, 28 Sep 2023 10:28:41 +0000 Subject: [PATCH] 增加闯红灯功能(特定场景);优化货车载人效果(检测框行人及非机动车过滤) --- bin/libSYTSLSystemInfoNativeJNI.so | Bin 43272 -> 0 bytes bin/libtraffic_light_vdec.so | Bin 0 -> 119264 bytes bin/models/village/trlight_det_310p.om | Bin 0 -> 15170682 bytes src/Makefile | 2 +- src/ai_engine_module/ai_engine_module.h | 13 +++++++++++++ src/ai_engine_module/traffic_light_det.h | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/ai_engine_module/traffic_light_process.cpp | 523 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/ai_engine_module/traffic_light_process.h | 123 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/ai_engine_module/truck_manned_process.cpp | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------- src/ai_engine_module/truck_manned_process.h | 1 + src/ai_platform/MultiSourceProcess.cpp | 110 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------- src/ai_platform/MultiSourceProcess.h | 14 ++++---------- src/ai_platform/header.h | 4 +++- src/ai_platform/task_param_manager.cpp | 6 ++++++ src/demo/Makefile | 2 +- src/demo/demo.cpp | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- src/tsl_aiplatform_jni/AiEngineNativeInterface.cpp | 2 ++ 17 files changed, 995 insertions(+), 36 deletions(-) create mode 100755 bin/libtraffic_light_vdec.so create mode 100644 bin/models/village/trlight_det_310p.om create mode 100644 src/ai_engine_module/ai_engine_module.h create mode 100644 src/ai_engine_module/traffic_light_det.h create mode 100644 src/ai_engine_module/traffic_light_process.cpp create mode 100644 src/ai_engine_module/traffic_light_process.h diff --git a/bin/libSYTSLSystemInfoNativeJNI.so b/bin/libSYTSLSystemInfoNativeJNI.so index d9c928f..4232945 100755 Binary files a/bin/libSYTSLSystemInfoNativeJNI.so and b/bin/libSYTSLSystemInfoNativeJNI.so differ diff --git a/bin/libtraffic_light_vdec.so b/bin/libtraffic_light_vdec.so new file mode 100755 index 0000000..b7bc4fc Binary files /dev/null and b/bin/libtraffic_light_vdec.so differ diff --git a/bin/models/village/trlight_det_310p.om b/bin/models/village/trlight_det_310p.om new file mode 100644 index 0000000..9f5d8fe Binary files /dev/null and b/bin/models/village/trlight_det_310p.om differ diff --git a/src/Makefile b/src/Makefile index d8e3733..67cf626 100755 --- a/src/Makefile +++ b/src/Makefile @@ -38,7 +38,7 @@ lib=-lacl_dvpp -lascendcl -lacl_dvpp_mpi -lruntime -lascendalog -lc_sec -lmsprof -lplatform -lgraph_base -lqos_manager LIBS= -L $(SPDLOG_ROOT)/lib -l:libspdlog.a \ - -L $(DEPEND_DIR) -lvpt_det_vdec -lsycheck -lface_det_vdec -lhs_tri_process -lhs_truck_process -lphone_motor_det -lhcp_vdec -lmotor_rainshed_vdec -lhs_motor_process\ + -L $(DEPEND_DIR) -lvpt_det_vdec -lsycheck -lface_det_vdec -lhs_tri_process -lhs_truck_process -lphone_motor_det -lhcp_vdec -lmotor_rainshed_vdec -ltraffic_light_vdec -lhs_motor_process\ -L $(OPENCV_ROOT)/lib -lopencv_world\ -L $(JSON_ROOT)/lib -ljsoncpp \ -L $(FFMPEG_ROOT)/lib -lavformat -lavcodec -lswscale -lavutil -lavfilter -lswresample -lavdevice \ diff --git a/src/ai_engine_module/ai_engine_module.h b/src/ai_engine_module/ai_engine_module.h new file mode 100644 index 0000000..a7c1723 --- /dev/null +++ b/src/ai_engine_module/ai_engine_module.h @@ -0,0 +1,13 @@ +#pragma once + +#include "./VPTProcess.h" +#include "./face_det_ai_engine.h" +#include "./pedestrian_vehicle_retrograde.h" +#include "./pedestrian_vehicle_trespass.h" +#include "./tricycle_manned_process.h" +#include "./truck_manned_process.h" +#include "./motocycle_hs_process.h" +#include "./motocycle_refit_phone_process.h" +#include "./motocycle_phone_process.h" +#include "./motocycle_refit_process.h" +#include "./traffic_light_process.h" \ No newline at end of file diff --git a/src/ai_engine_module/traffic_light_det.h b/src/ai_engine_module/traffic_light_det.h new file mode 100644 index 0000000..1301a65 --- /dev/null +++ b/src/ai_engine_module/traffic_light_det.h @@ -0,0 +1,108 @@ +/******************************************************************************************* +* Version: triffic_light_det_x64_v0.0.1 +* CopyRight: 中科视语(北京)科技有限公司 +* UpdateDate: 20230922 +* Content:头肩检测_货车 +********************************************************************************************/ +#ifndef TRAFFIC_LIGHT_H_ +#define TRAFFIC_LIGHT_H_ + +#ifdef _MSC_VER +#ifdef TRAFFIC_LIGHT_EXPORTS +#define TRAFFIC_LIGHT_API __declspec(dllexport) +#else +#define TRAFFIC_LIGHT_API __declspec(dllimport) +#endif +#else +#define TRAFFIC_LIGHT_API __attribute__ ((visibility ("default"))) +#endif + +#include "sy_common.h" + +#define MAX_OBJ_COUNT 1000 + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct traffic_light_info //结果结构体 + { + int left; + int top; + int right; + int bottom; + double confidence; // 置信度 + int index; // 类别索引 + }traffic_light_info; + + typedef struct traffic_light_result + { + traffic_light_info objinfo[MAX_OBJ_COUNT]; + int objcount; + }; + + typedef struct traffic_light_param + { + //int mode; //运行模式 GPU_MODE 或者 CPU_MODE + int devId; //运行卡号 GPU模式下有效 + char* modelNames; + float thresld; //检测阈值 默认为0.3 + + //int engine; //指定运行引擎(ENGINE_MCAFFE2 / ENGINE_TENSORRT) + //int max_batch; //ָ指定trt最大batch数 + //char* trt_serialize_file; + //traffic_light_param() :mode(DEVICE_GPU), gpuid(0), thresld(0.4), engine(ENGINE_MCAFFE2), max_batch(10){}; + }traffic_light_param; + + /************************************************************************* + * FUNCTION: hst_init + * PURPOSE: 初始化 + * PARAM: + [in] handle -处理句柄 + [in] param -初始化参数 + * RETURN: handle + * NOTES:成功(0)或者错误代码(<0) + *************************************************************************/ + TRAFFIC_LIGHT_API int traffic_light_init(void **handle, traffic_light_param param); + TRAFFIC_LIGHT_API int traffic_light_process_batch(void * handle, sy_img *image_data_array, int batchsize, traffic_light_result *result); + + /************************************************************************* + * FUNCTION: hst_release + * PURPOSE: 资源释放 + * PARAM: + [in] handle - 处理句柄 + * RETURN: NULL + * NOTES: + *************************************************************************/ + TRAFFIC_LIGHT_API void traffic_light_release(void **handle); + + + /************************************************************************* + * FUNCTION: hst_process_gpu + * PURPOSE: + * PARAM: + [in] handle - 处理句柄 + [in] rgb - 图片数据(3通道BGR数据 cv::Mat格式) + [in] width - 图片宽度 + [in] height - 图片高度 + [in] result - 搜索结果,在外部申请足够内存 + * RETURN: -1:图像错误; 其他:检测到的个数 + * NOTES: + *************************************************************************/ + TRAFFIC_LIGHT_API int traffic_light_process(void * handle, sy_img image, traffic_light_result *result); + + /************************************************************************* + * FUNCTION: hst_getversion + * PURPOSE: 释放 + * PARAM: NULL + * RETURN: 版本号 + * NOTES: + *************************************************************************/ + TRAFFIC_LIGHT_API const char * traffic_light_getversion(); + +#ifdef __cplusplus +}; +#endif + +#endif diff --git a/src/ai_engine_module/traffic_light_process.cpp b/src/ai_engine_module/traffic_light_process.cpp new file mode 100644 index 0000000..c25a05c --- /dev/null +++ b/src/ai_engine_module/traffic_light_process.cpp @@ -0,0 +1,523 @@ +#include +#include "./traffic_light_process.h" +#include +#include "../decoder/interface/DeviceMemory.hpp" +#include "../common/logger.hpp" +#include "../ai_platform/mvpt_process_assist.h" + +#if 0 +#include "opencv2/opencv.hpp" +#include "opencv2/imgcodecs/legacy/constants_c.h" +#endif + +namespace ai_engine_module +{ + namespace traffic_light_process + { + static std::set algor_type_list_ = { + algorithm_type_t::PERSON_RUNNING_REDLIGHTS, + algorithm_type_t::NONMOTOR_RUNNING_REDLIGHTS, + }; + + inline bool is_valid_label(const label_t &label) { + return ((label == label_t::red)); + } + + std::set task_id_to_algorithm_type_seq(const task_id_t &task_id, + task_param_manager *const task_param) { + std::set seq; + auto &&algor_map = task_param->get_task_other_param(task_id); + if (algor_map) { + // LOG_TRACE("task id is {} size algor type {}", task_id, algor_map->size()); + for (auto iter = algor_map->begin(); iter != algor_map->end(); ++iter) { + if (algor_type_list_.count(iter->first) > 0) + seq.emplace(iter->first); + } + } + return seq; // N(RVO) + } + + bool is_valid_box(const int top, const int left, const int right, const int bottom, const float score, + const algorithm_type_t &algor_type, + const task_param_manager::algo_param_type_t_ *params_ptr = nullptr) { + if (!params_ptr) + return false; + + if (!snapshot_legal_inarea(params_ptr->basic_param->algor_valid_rect, left, top, right, bottom)) + return false; + + if (params_ptr->algor_param == nullptr) + return false; + + + const unsigned width = right - left; + const unsigned height = bottom - top; + + if (width == 0 || height == 0) + return false; + + //! TODO: use switch to replace. + using data_t = algor_config_param_manned_incident; + data_t *algor_params_ptr = (data_t *) (params_ptr->algor_param); + + if ((width < algor_params_ptr->obj_min_width || height < algor_params_ptr->obj_min_height || score < algor_params_ptr->obj_confidence_threshold)) + return false; + + return true; + } + + vector Mbuild_area(vector args) + { + vector result; + int points_check = args.size(); + //需x y作为一组,是偶数 + if (points_check % 2 == 1) { + LOG_ERROR("points need x and y, but only get one"); + exit(0); + } + + for (int i = 0; i < points_check; i++) { + if (i % 2 == 0) { + tr_point tmp_point; + tmp_point.x = args[i]; + result.push_back(tmp_point); + } + else { + result[result.size() - 1].y = args[i]; + } + } + + return result; + } + + bool McheckPointPolygon(vector tr_boxes, tr_point pCur) { + //任意四边形有4个顶点 + int nCount = tr_boxes.size(); + tr_point RectPoints[MAX_LANE_NUM]; + + // std::cout << "ponits: "; + for (int i = 0; i < nCount; i++) { + RectPoints[i] = tr_boxes[i]; + // std::cout << tr_boxes[i].x << " " << tr_boxes[i].y << " "; + } + // std::cout << std::endl; + + int nCross = 0; + pCur.y += 0.1; + for (int i = 0; i < nCount; i++) { + //依次取相邻的两个点 + tr_point pStart = RectPoints[i]; + tr_point pEnd = RectPoints[(i + 1) % nCount]; + + //相邻的两个点是平行于x轴的,肯定不相交,忽略 + if (pStart.y == pEnd.y) continue; + + //交点在pStart,pEnd的延长线上,pCur肯定不会与pStart.pEnd相交,忽略 + if (pCur.y < min(pStart.y, pEnd.y) || pCur.y > max(pStart.y, pEnd.y)) continue; + + //求当前点和x轴的平行线与pStart,pEnd直线的交点的x坐标 + double x = (double)(pCur.y - pStart.y) * (double)(pEnd.x - pStart.x) / (double)(pEnd.y - pStart.y) + pStart.x; + + //若x坐标大于当前点的坐标,则有交点 + if (x > pCur.x) nCross++; + } + + // 单边交点为偶数,点在多边形之外 + return (nCross % 2 == 1); + } + +#if 0 + void CvtYuvToBgr(sy_img src, sy_img dst) { + const int uvStart = src.w_ * src.h_; + for (int h = 0; h < dst.h_; h++) { + for (int w = 0; w < dst.w_; w++) { + int uvIndex = h / 2 * src.w_ + w - w % 2; + unsigned char y = *(src.data_ + w + h * src.w_); + unsigned char u = *(src.data_ + uvStart + uvIndex); + unsigned char v = *(src.data_ + uvStart + uvIndex + 1); + + int r = (int)(y + 1.402 * (v - 128)); + int g = (int)(y - 0.34414 * (u - 128) - 0.71414 * (v - 128)); + int b = (int)(y + 1.772 * (u -128)); + + if (r > 255) r = 255; + if (g > 255) g = 255; + if (b > 255) b = 255; + if (r < 0) r = 0; + if (g < 0) g = 0; + if (b < 0) b = 0; + *(dst.data_ + h * dst.w_ * 3 + w * 3) = b; + *(dst.data_ + h * dst.w_ * 3 + w * 3 + 1) = g; + *(dst.data_ + h * dst.w_ * 3 + w * 3 + 2) = r; + } + } + } +#endif + + TrafficLightProcess::TrafficLightProcess() + : task_param_manager_(nullptr) + { + + } + + TrafficLightProcess::~TrafficLightProcess() + { + if (tools_) { + traffic_light_release(&tools_); + tools_ = nullptr; + } + if (m_algorthim_ctx) { + aclrtDestroyContext(m_algorthim_ctx); + } + } + + bool TrafficLightProcess::init(int gpu_id, string models_dir) + { + init_ = false; + + string model_path = models_dir + "/models/village/trlight_det_310p.om" ; + LOG_INFO("traffic_light 版本:{} 模型路径:{}", traffic_light_getversion(), model_path); + + traffic_light_param param; + char modelNames[100]; + strcpy(modelNames, model_path.c_str()); + param.modelNames = modelNames; + param.thresld = 0.25; + param.devId = gpu_id; + + m_devId = param.devId; + ACL_CALL(aclrtSetDevice(m_devId), ACL_SUCCESS, -1); + ACL_CALL(aclrtCreateContext(&m_algorthim_ctx, m_devId), ACL_SUCCESS, -1); + + int status; + if (!(init_ = (0 == (status = traffic_light_init(&tools_, param))))) + LOG_ERROR("Init TrafficLightProcessSdk failed error code is {}", status); + else + if (!task_param_manager_) + task_param_manager_ = task_param_manager::getInstance(); + return init_; + } + + + bool TrafficLightProcess::check_initied() + { + if (!init_) + LOG_ERROR("[%s:%d] call init function please.", __FILE__, __LINE__); + return init_; + } + + + void TrafficLightProcess::force_release_result(const task_id_t& task_id) { + for (auto iter = id_to_result_.begin(); iter != id_to_result_.end();) { + const auto& key = iter->first; + if (key.task_id == task_id) { + auto& value = iter->second; + if (value.origin_img_desc != nullptr) { + VPCUtil::vpc_pic_desc_release(value.origin_img_desc); + } + + if (value.roi_img_desc != nullptr) { + VPCUtil::vpc_pic_desc_release(value.roi_img_desc); + } + iter = id_to_result_.erase(iter); + } + else { + ++iter; + } + + } + } + + std::shared_ptr TrafficLightProcess::get_result_by_objectid(const id_t& id, bool do_erase) + { + auto it = id_to_result_.find(id); + if (it == id_to_result_.end()) + return std::shared_ptr(nullptr); + std::shared_ptr res = std::make_shared(it->second); + if (do_erase) + id_to_result_.erase(id); + return res; + } + + bool TrafficLightProcess::update_mstreams(const std::vector& taskIds, vector src_interest_imgs, vector vec_det_input_images, const std::vector &det_results) + { + if (!check_initied()) + return false; + + if (det_results.empty()) + { + LOG_DEBUG("detection result is empty."); + return false; + } + + struct stream_idx_and_algor_seq_t { + unsigned stream_idx; + std::set algors; + }; + + int n_images = det_results.size(); // or n_stream + + unsigned flattened_idx = 0; + std::map flattened_idx_to_batch_idx; + //! 记录每个box对应的算法以及流id. + std::map flattened_idx_to_algor_seq; + + /* 1. Crop & keep some interest class. */ + auto taskId_iter = taskIds.begin(); + std::vector flattened_imgs(0); + std::vector flattened_vpc_imgs(0); + std::vector flattened_interest_data(0); // + VPCUtil* pVpcUtil = VPCUtil::getInstance(); + for (int n = 0; n < n_images; ++n) + { + int n_interest_obj = 0; + auto& src_img = vec_det_input_images[n]; + int src_img_w = src_img->getWidth(); + int src_img_h = src_img->getHeight(); + + auto& boxes_of_one_image = det_results[n].obj; + for (int i = 0; i < det_results[n].obj_count; ++i) + { + auto& box = boxes_of_one_image[i]; + if (static_cast(box.index) == det_class_label_t::MOTOCYCLE || static_cast(box.index) == det_class_label_t::BICYCLE || static_cast(box.index) == det_class_label_t::HUMAN) + { + auto& taskId = *taskId_iter; + input_data_wrap_t data; + int top = std::max(int(box.top - (IMAGE_CROP_EXPAND_RATIO * box.top)), 0); + int left = std::max(int(box.left - (IMAGE_CROP_EXPAND_RATIO * box.left)), 0); + int right = std::min(int(box.right + (IMAGE_CROP_EXPAND_RATIO * box.right)), src_img_w); + int bottom = std::min(int(box.bottom + (IMAGE_CROP_EXPAND_RATIO * box.bottom)), src_img_h); + + //! loop per algor from set. + stream_idx_and_algor_seq_t stream_idx_and_algor_seq{n, {}}; + std::set algorithm_type_seq = task_id_to_algorithm_type_seq(taskId, + task_param_manager_); // N(RVO). + + for (auto algor_iter = algorithm_type_seq.begin();algor_iter != algorithm_type_seq.end(); ++algor_iter) { + const algorithm_type_t algor_type = *algor_iter; + auto &&algor_param_wrap = task_param_manager_->get_task_other_param(taskId, algor_type); + if (!algor_param_wrap) { + LOG_ERROR("{} is nullptr when get algor param from task_param", taskId.c_str()); + continue; + } + + if (!is_valid_box(top, left, right, bottom, box.confidence, algor_type, algor_param_wrap)) + continue; + + //DEBUG增加多边形区域选择及判断================================================================ + tr_point curpos; + curpos.x = (left + right) * 0.5; curpos.y = bottom; + vector args = {1552,435,1756,537,1915,537,1915,499,1725,435}; //区域(泰兴黄桥锦润福府路口) + // vector args = {0,0,0,1080,1920,1080,1920,0}; //区域 + vector tr_boxes = Mbuild_area(args); + int cur_flag = McheckPointPolygon(tr_boxes, curpos); //cur_flag==true表示在区域内 + if (!cur_flag) continue; + //DEBUG END================================================================================== + stream_idx_and_algor_seq.algors.emplace(algor_type); + } + + if (stream_idx_and_algor_seq.algors.empty()) + continue; + + int width = right - left; + int height = bottom - top; + + data.box.top = top; data.box.left = left; + data.box.right = right; data.box.bottom = bottom; + data.box.score = box.confidence; data.box.cls = box.index; + data.taskId = taskId; data.objId = box.id; + + // 抠图 + video_object_info obj; + strcpy(obj.task_id, taskId.c_str()); + obj.object_id = box.id; + obj.left = left; obj.top = top; + obj.right = right; obj.bottom = bottom; + + vpc_img_info img_info = pVpcUtil->crop(src_img, obj); + + sy_img img; + img.w_ = width; + img.h_ = height; + img.c_ = src_img->getChannel(); + + if (img_info.pic_desc != nullptr) { + void *outputDataDev = acldvppGetPicDescData(img_info.pic_desc); + img.data_ = reinterpret_cast(outputDataDev); + } + else { + LOG_ERROR("Crop image NPU failed wh is [{}, {}] ltrb is [{} {} {} {}]", + src_img_w, src_img_h, data.box.left, data.box.top, data.box.right, data.box.bottom); + continue; + } + + flattened_imgs.emplace_back(std::move(img)); + flattened_vpc_imgs.emplace_back(std::move(img_info)); + flattened_interest_data.emplace_back(std::move(data)); + flattened_idx_to_algor_seq[flattened_idx] = std::move(stream_idx_and_algor_seq); + flattened_idx_to_batch_idx[flattened_idx++] = n; + } + } + ++taskId_iter; + } + + int ret = aclrtSetCurrentContext(m_algorthim_ctx); + if (ACL_SUCCESS != ret) { + return false; + } + /* 2. collection result. */ + int n_input_image = flattened_imgs.size(); + int n_input_src_image = src_interest_imgs.size(); + traffic_light_result model_results[n_input_src_image]; + { + int steps = (n_input_src_image + MAX_BATCH - 1) / MAX_BATCH; + for (int step = 0; step < steps; ++step) + { + int offset = step * MAX_BATCH; + int batch_size = (step == steps - 1) ? n_input_src_image - offset : MAX_BATCH; + traffic_light_process_batch(tools_, src_interest_imgs.data() + offset, batch_size, model_results + offset); + } + } + + /* 3. postprocess. */ + { + for (int n = 0; n < n_input_image; ++n) + { + auto& det_result = flattened_interest_data[n]; + auto& objId = det_result.objId; + auto& task_id = det_result.taskId; + + auto &stream_idx_and_algor_seq = flattened_idx_to_algor_seq[n]; + auto &algors = stream_idx_and_algor_seq.algors; + // auto &steram_idx = stream_idx_and_algor_seq.stream_idx; + + const auto& src_img = vec_det_input_images[flattened_idx_to_batch_idx[n]]; + auto &model_result = model_results[flattened_idx_to_batch_idx[n]]; + int red_cnt = 0; //统计直行红灯个数 + for (unsigned i = 0; i < model_result.objcount; ++i) { + auto &box = model_result.objinfo[i]; + const label_t label = static_cast(box.index); + if (!is_valid_label(label)) + continue; + if (box.left < 1200 || box.top < 159 || box.right > 1307 || box.bottom > 212) continue; // 限制红绿灯的出现位置(泰兴黄桥锦润福府路口) + LOG_TRACE("task id is {} obj_id {} label {} index {} score {}", task_id, objId, label, box.index, box.confidence); + red_cnt ++; + } +#if 0 + if (red_cnt > 0) { + sy_img img = src_interest_imgs[flattened_idx_to_batch_idx[n]]; + int dataSize = img.w_ * img.h_ * 3 / 2; + uint8_t* buffer = new uint8_t[dataSize]; + uint8_t* imgBgr = new uint8_t[dataSize]; + aclError aclRet = aclrtMemcpy(buffer, dataSize, img.data_, dataSize, ACL_MEMCPY_DEVICE_TO_HOST); + + sy_img imgyuv_local, tmpbgr; + imgyuv_local.data_ = (unsigned char*)buffer; imgyuv_local.w_ = img.w_; imgyuv_local.h_ = img.h_; + tmpbgr.w_ = img.w_; tmpbgr.h_ = img.h_; tmpbgr.data_ = imgBgr; + CvtYuvToBgr(imgyuv_local, tmpbgr); + + cv::Mat cvImg = cv::Mat(tmpbgr.h_, tmpbgr.w_, CV_8UC3, tmpbgr.data_); + string jpgSaveName1 = "result/oral/" + task_id + "_" + to_string(objId) + ".jpg"; + cv::imwrite(jpgSaveName1, cvImg); + for (unsigned i = 0; i < model_result.objcount; ++i) { + cv::Point lt(model_result.objinfo[i].left, model_result.objinfo[i].top); + cv::Point rb(model_result.objinfo[i].right, model_result.objinfo[i].bottom); + cv::rectangle(cvImg, lt, rb, cv::Scalar(0, 0, 255), 3); + + char buffer[50]; int fontface = cv::FONT_HERSHEY_SIMPLEX; double scale = 0.8; int thickness = 2; int baseline = 0; + snprintf(buffer, sizeof(buffer), "%d:%.2f", model_result.objinfo[i].index, model_result.objinfo[i].confidence); + cv::Size text = cv::getTextSize(buffer, fontface, scale, thickness, &baseline); + cv::putText(cvImg, buffer, lt - cv::Point(0, baseline), fontface, scale, cv::Scalar(0, 0, 255), thickness, 8); + } + string jpgSaveName2 = "result/draw/" + task_id + "_" + to_string(objId) + ".jpg"; + cv::imwrite(jpgSaveName2, cvImg); + + delete[] buffer; buffer = NULL; + delete[] imgBgr; imgBgr = NULL; + } +#endif + + for (auto algor_type_iter = algors.begin();algor_type_iter != algors.end(); ++algor_type_iter) { + const algorithm_type_t algor_type = *algor_type_iter; + + auto &&algor_param_wrap = task_param_manager_->get_task_other_param(task_id, algor_type); + if (!algor_param_wrap) { + LOG_ERROR("{} is nullptr when get algor param from task_param", task_id); + continue; + } + auto algor_param = ((algor_param_type)algor_param_wrap->algor_param); + + id_t obj_key = obj_key_t{ objId, task_id, algor_type}; + if (id_to_result_.find(obj_key) != id_to_result_.end()) + continue; + + // LOG_TRACE("task id is {} algor type is {} obj_id {}", task_id, int(algor_type), objId); + if (algor_type == algorithm_type_t::PERSON_RUNNING_REDLIGHTS && static_cast(det_result.box.cls) != det_class_label_t::HUMAN) + continue; + if (algor_type == algorithm_type_t::NONMOTOR_RUNNING_REDLIGHTS && (static_cast(det_result.box.cls) != det_class_label_t::MOTOCYCLE || + static_cast(det_result.box.cls) != det_class_label_t::BICYCLE)) + continue; + + auto& e = id_to_mn_[obj_key]; + ++e.m_frame; + + // 数量小于设定阈值不报警 + if (red_cnt < 1) + continue; + + { + if (++e.n_frame == algor_param->n) + { + results_data_t result; + { LOG_TRACE("task id is {} obj_id {} red_cnt {}", task_id, det_result.objId, red_cnt); + result.box = det_result.box; + result.taskId = det_result.taskId; + result.objId = det_result.objId; + result.algor_type = algor_type; + // 原图 + vpc_img_info src_img_info = VPCUtil::vpc_devMem2vpcImg(src_img); + result.origin_img_desc = src_img_info.pic_desc; + // 抠图--拷贝后赋值 + void *outputDataDev = acldvppGetPicDescData(flattened_vpc_imgs[n].pic_desc); + int nBufferSize = acldvppGetPicDescSize(flattened_vpc_imgs[n].pic_desc); + + void *devBuffer = nullptr; + auto ret = acldvppMalloc(&devBuffer, nBufferSize); + if (ret != ACL_SUCCESS) { + LOG_ERROR("acldvppMalloc failed, size = %u, errorCode = %d.", nBufferSize, static_cast(ret)); + return false; + } + aclrtMemcpy(devBuffer, nBufferSize, outputDataDev, nBufferSize, ACL_MEMCPY_DEVICE_TO_DEVICE); + + acldvppPicDesc *vpcInputDesc_= acldvppCreatePicDesc(); + acldvppSetPicDescData(vpcInputDesc_, devBuffer); + acldvppSetPicDescFormat(vpcInputDesc_, PIXEL_FORMAT_YUV_SEMIPLANAR_420); + acldvppSetPicDescWidth(vpcInputDesc_, acldvppGetPicDescWidth(flattened_vpc_imgs[n].pic_desc)); + acldvppSetPicDescHeight(vpcInputDesc_, acldvppGetPicDescHeight(flattened_vpc_imgs[n].pic_desc)); + acldvppSetPicDescWidthStride(vpcInputDesc_, acldvppGetPicDescWidthStride(flattened_vpc_imgs[n].pic_desc)); + acldvppSetPicDescHeightStride(vpcInputDesc_, acldvppGetPicDescHeightStride(flattened_vpc_imgs[n].pic_desc)); + acldvppSetPicDescSize(vpcInputDesc_, nBufferSize); + + result.roi_img_desc = vpcInputDesc_; //需复制 + } + id_to_result_.emplace(obj_key, std::move(result)); + } + } + + if (e.m_frame == algor_param->m) + e.reset(); + + } + + VPCUtil::vpc_img_release(flattened_vpc_imgs[n]); //flattened_imgs[n].data_ + + } + } + + return true; + } + + } // namespace traffic_light_process + +} // namespace ai_engine_module + diff --git a/src/ai_engine_module/traffic_light_process.h b/src/ai_engine_module/traffic_light_process.h new file mode 100644 index 0000000..466b26c --- /dev/null +++ b/src/ai_engine_module/traffic_light_process.h @@ -0,0 +1,123 @@ +#pragma once +#include +#include +#include +#include +#include "../util/vpc_util.h" +#include "../ai_platform/task_param_manager.h" +#include "../ai_platform/macro_definition.h" +#include "ai_engine_header.h" +#include "traffic_light_det.h" +#include "acl/acl.h" +#include "acl/ops/acl_dvpp.h" + +#define MAX_BATCH 20 +#define IMAGE_CROP_EXPAND_RATIO 0 +#define MAX_OBJ_BOX_COUNT 100 +#define MAX_LANE_NUM 100 + +namespace ai_engine_module +{ + namespace traffic_light_process + { + // typedef long id_t; + using id_t = obj_key_t; + using task_id_t = std::string; + using algor_param_type = algor_config_param_manned_incident*; + + enum class label_t { + PLACEHOLDER = -1, + red = 0, //直行红灯 + green = 1, //直行绿灯 + yellow = 2, //直行黄灯 + wred = 3, //转向红灯 + wgreen = 4, //转向绿灯 + wyellow = 5, //转向黄灯 + pred = 6, //行人红灯 + pyellow = 7, //行人黄灯 + pgreen = 8, //行人绿灯 + bred = 9, //自行车红灯 + byellow = 10, //自行车黄灯 + bgreen = 11, //自行车绿灯 + no = 12, //灭灯 + }; + + typedef struct input_data_wrap_t + { + id_t id; + long objId; + std::string taskId; + box_t box; + } input_data_wrap_t; + + typedef struct tr_point { + float x, y; + }tr_point; + + + typedef struct mn_frame_t + { + uint m_frame; + uint n_frame; + + // explicit + mn_frame_t(uint m = 0, uint n = 0) + : m_frame(m) + , n_frame(n) + {} + + void reset() + { + m_frame = 0; + n_frame = 0; + } + + } mn_frame_t; + + + typedef struct results_data_t + { + box_t box; + acldvppPicDesc* origin_img_desc{nullptr}; + acldvppPicDesc* roi_img_desc{nullptr}; + id_t id; + long objId; + std::string taskId; + algorithm_type_t algor_type; + } results_data_t; + + class TrafficLightProcess + { + /** + * @brief + * 1. move able + */ + public: + TrafficLightProcess(); + + ~TrafficLightProcess(); + + bool check_initied(); + bool init(int gpu_id, string models_dir); + bool update_mstreams(const std::vector& taskIds, vector src_interest_imgs, vector vec_det_input_images, const std::vector &det_results); + std::shared_ptr get_result_by_objectid(const id_t& id, bool do_erase = true); + + void force_release_result(const task_id_t& task_id); + + TrafficLightProcess(const TrafficLightProcess&) = delete; + TrafficLightProcess& operator=(const TrafficLightProcess&) = delete; + + private: + static algorithm_type_t algor_type_; + int m_devId; + aclrtContext m_algorthim_ctx; + + bool init_; + void* tools_; + task_param_manager* task_param_manager_; + std::map id_to_mn_; + std::map id_to_result_; + }; + } // namespace traffic_light_process +} // namespace ai_engine_module + diff --git a/src/ai_engine_module/truck_manned_process.cpp b/src/ai_engine_module/truck_manned_process.cpp index c1c7a78..91f6348 100644 --- a/src/ai_engine_module/truck_manned_process.cpp +++ b/src/ai_engine_module/truck_manned_process.cpp @@ -12,6 +12,28 @@ namespace ai_engine_module { algorithm_type_t TruckMannedProcess::algor_type_ = algorithm_type_t::TRUCK_MANNED; + int legal_person_motocycle_inarea(const std::vector& person_motocycle_data, int left, int top, int right, int bottom) { + int legal_person_motocycle_count = 0; + for (const auto& det_result : person_motocycle_data) { + int x1_intersection = std::max(det_result.box.left, left); + int y1_intersection = std::max(det_result.box.top, top); + int x2_intersection = std::min(det_result.box.right, right); + int y2_intersection = std::min(det_result.box.bottom, bottom); + + if (x2_intersection <= x1_intersection || y2_intersection <= y1_intersection) continue; // 没有交集 + float area_a = float(det_result.box.right - det_result.box.left) * float(det_result.box.bottom - det_result.box.top); + float area_b = float(right - left) * float(bottom - top); + float area_intersection = float(x2_intersection - x1_intersection) * float(y2_intersection - y1_intersection); + + if (area_a > area_b || area_a <= 0) continue; //暂不考虑非机动车目标比货车大的情况 + // float iou = area_intersection / (area_a + area_b - area_intersection); + float small_overlap_ratio = area_intersection / area_a; //计算非机动车目标相对于自身的重叠程度 + if (small_overlap_ratio > 0.2) legal_person_motocycle_count ++; + } + return legal_person_motocycle_count; + + } + TruckMannedProcess::TruckMannedProcess() : task_param_manager_(nullptr) { @@ -127,6 +149,34 @@ namespace ai_engine_module int src_img_h = src_img->getHeight(); auto& boxes_of_one_image = det_results[n].obj; + + //汇总当前帧的行人/非机动车目标 + std::vector person_motocycle_data(0); + for (int i = 0; i < det_results[n].obj_count; ++i) + { + auto& box = boxes_of_one_image[i]; + if (static_cast(box.index) == det_class_label_t::MOTOCYCLE || static_cast(box.index) == det_class_label_t::BICYCLE || + static_cast(box.index) == det_class_label_t::HUMAN || static_cast(box.index) == det_class_label_t::TRICYCLE) + { + auto& taskId = *taskId_iter; + input_data_wrap_t data; + int top = std::max(int(box.top), 0); int left = std::max(int(box.left), 0); + int right = std::min(int(box.right), src_img_w); int bottom = std::min(int(box.bottom), src_img_h); + int width = right - left; int height = bottom - top; + + if (static_cast(box.index) == det_class_label_t::HUMAN && width >= 0.9*height) //基于载人只能看到半身的假设 + continue; + + data.box.top = top; data.box.left = left; + data.box.right = right; data.box.bottom = bottom; + data.box.score = box.confidence; data.box.cls = box.index; + data.taskId = taskId; data.objId = box.id; + + person_motocycle_data.emplace_back(std::move(data)); + } + } + + for (int i = 0; i < det_results[n].obj_count; ++i) { auto& box = boxes_of_one_image[i]; @@ -154,14 +204,15 @@ namespace ai_engine_module !snapshot_legal_inarea(algor_param_wrap->basic_param->algor_valid_rect, left, top, right, bottom)) continue; - data.box.top = top; - data.box.left = left; - data.box.right = right; - data.box.bottom = bottom; + //统计货车检测框内行人及非机动车的数量 + int person_motocycle_inarea = legal_person_motocycle_inarea(person_motocycle_data, left, top, right, bottom); + + data.box.top = top; data.box.left = left; + data.box.right = right; data.box.bottom = bottom; data.box.score = box.confidence; - data.taskId = taskId; - data.objId = box.id; + data.taskId = taskId; data.objId = box.id; data.id = obj_key_t{ box.id, taskId, algorithm_type_t::TRUCK_MANNED }; + data.person_motocycle_cnt = person_motocycle_inarea; // 抠图 video_object_info obj; @@ -193,6 +244,7 @@ namespace ai_engine_module flattened_idx_to_batch_idx[flattened_idx++] = n; } } + std::vector().swap(person_motocycle_data); ++taskId_iter; } @@ -246,7 +298,8 @@ namespace ai_engine_module auto& e = id_to_mn_[obj_key]; ++e.m_frame; - if (hs_count >= algor_param->hs_count_threshold) + // if (hs_count >= algor_param->hs_count_threshold) + if (hs_count - det_result.person_motocycle_cnt >= algor_param->hs_count_threshold) //头肩数量去除包含的行人和非机动车数量 { if (++e.n_frame == algor_param->n) { diff --git a/src/ai_engine_module/truck_manned_process.h b/src/ai_engine_module/truck_manned_process.h index b19b860..234491a 100644 --- a/src/ai_engine_module/truck_manned_process.h +++ b/src/ai_engine_module/truck_manned_process.h @@ -28,6 +28,7 @@ namespace ai_engine_module { id_t id; long objId; + int person_motocycle_cnt; std::string taskId; box_t box; } input_data_wrap_t; diff --git a/src/ai_platform/MultiSourceProcess.cpp b/src/ai_platform/MultiSourceProcess.cpp index e03020b..b2aebb1 100755 --- a/src/ai_platform/MultiSourceProcess.cpp +++ b/src/ai_platform/MultiSourceProcess.cpp @@ -195,6 +195,11 @@ int CMultiSourceProcess::InitAlgorthim(tsl_aiplatform_param vptParam){ LOG_FATAL("Init motor_refit failed"); return -1; } + // 行人/二轮车闯红灯 + if (!traffic_lightprocess_.init(vptParam.gpuid, models_dir)) { + LOG_FATAL("Init traffic_light failed"); + return -1; + } #endif #ifdef WITH_FACE_DET_SS @@ -711,6 +716,7 @@ bool CMultiSourceProcess::finish_task(const string taskID, const bool delete_sna motor_refit_phoneprocess_.force_release_result(taskID); // motor_phoneprocess_.force_release_result(taskID); motor_refitprocess_.force_release_result(taskID); + traffic_lightprocess_.force_release_result(taskID); m_task_param_manager->delete_task_param(taskID); #endif @@ -905,6 +911,8 @@ int CMultiSourceProcess::algorthim_vpt(vector vec_gpuMem){ algorithm_motor_phone_process(vpt_interest_task_id, vec_vptMem, vptResult);*/ // 电动车改装(加雨棚) algorithm_motor_refit_process(vpt_interest_task_id, vec_vptMem, vptResult); + // 行人/二轮车闯红灯 + algorithm_traffic_light_process(vpt_interest_task_id, vec_vptMem, vptResult); village_snapshot(vpt_interest_task_id, vec_vptMem, deleteObjectID); #endif @@ -1439,6 +1447,42 @@ void CMultiSourceProcess::algorithm_motor_refit_process(vector& vpt_inte } } + +// 行人/二轮车闯红灯 +void CMultiSourceProcess::algorithm_traffic_light_process(vector& vpt_interest_task_id, vector vpt_interest_imgs, + vector& vptResult) { + + vector interest_task_id; + vector interest_vpt_result; + vector interest_imgs; + vector sy_interest_imgs; + + int _idx = 0; + for (auto _task_id_iter = vpt_interest_task_id.begin(); _task_id_iter != vpt_interest_task_id.end(); + ++_task_id_iter, ++_idx) // loop task_id; + { + auto task_id = *_task_id_iter; + auto algor_map = m_task_param_manager->get_task_other_param(task_id); + + if (algor_map->find(algorithm_type_t::PERSON_RUNNING_REDLIGHTS) != algor_map->end() || + algor_map->find(algorithm_type_t::NONMOTOR_RUNNING_REDLIGHTS) != algor_map->end()) { + DeviceMemory* mem = vpt_interest_imgs[_idx]; + sy_img img; + img.w_ = mem->getWidth(); img.h_ = mem->getHeight(); + img.c_ = mem->getChannel(); img.data_ = mem->getMem(); + sy_interest_imgs.push_back(img); + + interest_task_id.emplace_back(task_id); + interest_imgs.emplace_back(vpt_interest_imgs[_idx]); + interest_vpt_result.emplace_back(vptResult[_idx]); + } + } + + if (!interest_imgs.empty()){ + traffic_lightprocess_.update_mstreams(interest_task_id, sy_interest_imgs, interest_imgs, interest_vpt_result); + } +} + // for snapshot algorithm. 轨迹结束目标 做最后的结果返回(当前返回算法结果+快照保存路径) void CMultiSourceProcess::village_snapshot(vector& vpt_interest_task_id, vector vec_vptMem, vector> deleteObjectID) { auto task_iter = vpt_interest_task_id.begin(); @@ -1472,8 +1516,7 @@ void CMultiSourceProcess::village_snapshot(vector& vpt_interest_task_id, auto json_str = helpers::gen_json::gen_manned_json(obj_key.video_id, obj_key.obj_id, result->box, algorithm_type_t::TRICYCLE_MANNED); save_snapshot_process(obj_key, algorithm_type_t::TRICYCLE_MANNED, src_img, roi_img, 0, json_str); } else { - VPCUtil::vpc_img_release(src_img); - VPCUtil::vpc_img_release(roi_img); + VPCUtil::vpc_img_release(src_img); VPCUtil::vpc_img_release(roi_img); } } @@ -1496,8 +1539,7 @@ void CMultiSourceProcess::village_snapshot(vector& vpt_interest_task_id, auto json_str = helpers::gen_json::gen_manned_json(obj_key.video_id, obj_key.obj_id, result->box, algorithm_type_t::TRUCK_MANNED); save_snapshot_process(obj_key, algorithm_type_t::TRUCK_MANNED, src_img, roi_img, 0, json_str); } else { - VPCUtil::vpc_img_release(src_img); - VPCUtil::vpc_img_release(roi_img); + VPCUtil::vpc_img_release(src_img); VPCUtil::vpc_img_release(roi_img); } } @@ -1520,8 +1562,7 @@ void CMultiSourceProcess::village_snapshot(vector& vpt_interest_task_id, auto json_str = helpers::gen_json::gen_manned_json(obj_key.video_id, obj_key.obj_id, result->box, algorithm_type_t::NONMOTOR_VEHICLE_NOHELMET); save_snapshot_process(obj_key, algorithm_type_t::NONMOTOR_VEHICLE_NOHELMET, src_img, roi_img, 0, json_str); } else { - VPCUtil::vpc_img_release(src_img); - VPCUtil::vpc_img_release(roi_img); + VPCUtil::vpc_img_release(src_img); VPCUtil::vpc_img_release(roi_img); } } @@ -1544,8 +1585,7 @@ void CMultiSourceProcess::village_snapshot(vector& vpt_interest_task_id, auto json_str = helpers::gen_json::gen_manned_json(obj_key.video_id, obj_key.obj_id, result->box, algorithm_type_t::NONMOTOR_VEHICLE_OVERMAN); save_snapshot_process(obj_key, algorithm_type_t::NONMOTOR_VEHICLE_OVERMAN, src_img, roi_img, 0, json_str); } else { - VPCUtil::vpc_img_release(src_img); - VPCUtil::vpc_img_release(roi_img); + VPCUtil::vpc_img_release(src_img); VPCUtil::vpc_img_release(roi_img); } } @@ -1569,8 +1609,7 @@ void CMultiSourceProcess::village_snapshot(vector& vpt_interest_task_id, auto json_str = helpers::gen_json::gen_manned_json(obj_key.video_id, obj_key.obj_id, result->box, algorithm_type_t::NONMOTOR_VEHICLE_USEPHONE); save_snapshot_process(obj_key, algorithm_type_t::NONMOTOR_VEHICLE_USEPHONE, src_img, roi_img, 0, json_str); } else { - VPCUtil::vpc_img_release(src_img); - VPCUtil::vpc_img_release(roi_img); + VPCUtil::vpc_img_release(src_img); VPCUtil::vpc_img_release(roi_img); } } @@ -1594,8 +1633,53 @@ void CMultiSourceProcess::village_snapshot(vector& vpt_interest_task_id, auto json_str = helpers::gen_json::gen_manned_json(obj_key.video_id, obj_key.obj_id, result->box, algorithm_type_t::NONMOTOR_VEHICLE_REFIT); save_snapshot_process(obj_key, algorithm_type_t::NONMOTOR_VEHICLE_REFIT, src_img, roi_img, 0, json_str); } else { - VPCUtil::vpc_img_release(src_img); - VPCUtil::vpc_img_release(roi_img); + VPCUtil::vpc_img_release(src_img); VPCUtil::vpc_img_release(roi_img); + } + + } + } + + if (task_param_ptr->nonmotor_vehicle_algors.find(algorithm_type_t::NONMOTOR_RUNNING_REDLIGHTS) != task_param_ptr->nonmotor_vehicle_algors.end()) { + const auto &algor_other_params = task_other_params->find(algorithm_type_t::NONMOTOR_RUNNING_REDLIGHTS); + const algor_basic_config_param_t *basic_param = algor_other_params->second->basic_param; + + auto result = traffic_lightprocess_.get_result_by_objectid(ai_engine_module::obj_key_t{obj_key.obj_id, obj_key.video_id, algorithm_type_t::NONMOTOR_RUNNING_REDLIGHTS}); + if (result.get()) { + village_alarm = true; + algorithm_types.push_back((int)algorithm_type_t::NONMOTOR_RUNNING_REDLIGHTS); + video_folder = basic_param->video_folder; result_folder = basic_param->result_folder; result_folder_little = basic_param->result_folder_little; + // 原图及抠图 + vpc_img_info src_img; src_img.pic_desc = result->origin_img_desc; src_img.task_id = obj_key.video_id; + vpc_img_info roi_img; roi_img.pic_desc = result->roi_img_desc; roi_img.task_id = obj_key.video_id; roi_img.object_id = obj_key.obj_id; + + if (save_single_algor_pic) { + auto json_str = helpers::gen_json::gen_manned_json(obj_key.video_id, obj_key.obj_id, result->box, algorithm_type_t::NONMOTOR_RUNNING_REDLIGHTS); + save_snapshot_process(obj_key, algorithm_type_t::NONMOTOR_RUNNING_REDLIGHTS, src_img, roi_img, 0, json_str); + } else { + VPCUtil::vpc_img_release(src_img); VPCUtil::vpc_img_release(roi_img); + } + + } + } + + if (task_param_ptr->human_algors.find(algorithm_type_t::PERSON_RUNNING_REDLIGHTS) != task_param_ptr->human_algors.end()) { + const auto &algor_other_params = task_other_params->find(algorithm_type_t::PERSON_RUNNING_REDLIGHTS); + const algor_basic_config_param_t *basic_param = algor_other_params->second->basic_param; + + auto result = traffic_lightprocess_.get_result_by_objectid(ai_engine_module::obj_key_t{obj_key.obj_id, obj_key.video_id, algorithm_type_t::PERSON_RUNNING_REDLIGHTS}); + if (result.get()) { + village_alarm = true; + algorithm_types.push_back((int)algorithm_type_t::PERSON_RUNNING_REDLIGHTS); + video_folder = basic_param->video_folder; result_folder = basic_param->result_folder; result_folder_little = basic_param->result_folder_little; + // 原图及抠图 + vpc_img_info src_img; src_img.pic_desc = result->origin_img_desc; src_img.task_id = obj_key.video_id; + vpc_img_info roi_img; roi_img.pic_desc = result->roi_img_desc; roi_img.task_id = obj_key.video_id; roi_img.object_id = obj_key.obj_id; + + if (save_single_algor_pic) { + auto json_str = helpers::gen_json::gen_manned_json(obj_key.video_id, obj_key.obj_id, result->box, algorithm_type_t::PERSON_RUNNING_REDLIGHTS); + save_snapshot_process(obj_key, algorithm_type_t::PERSON_RUNNING_REDLIGHTS, src_img, roi_img, 0, json_str); + } else { + VPCUtil::vpc_img_release(src_img); VPCUtil::vpc_img_release(roi_img); } } @@ -1966,7 +2050,7 @@ bool CMultiSourceProcess::CheckTime() { nYear = info->tm_year + 1900; nMonth = info->tm_mon + 1; nDay = info->tm_mday; - if ((nYear == 2023 && nMonth <= 9) || (nYear == 2023 && nMonth <= 10 && nDay <= 31)) + if ((nYear == 2023 && nMonth <= 10) || (nYear == 2023 && nMonth <= 11 && nDay <= 30)) { return true; } diff --git a/src/ai_platform/MultiSourceProcess.h b/src/ai_platform/MultiSourceProcess.h index c8c4640..89e1e35 100755 --- a/src/ai_platform/MultiSourceProcess.h +++ b/src/ai_platform/MultiSourceProcess.h @@ -12,16 +12,7 @@ #include "task_param_manager.h" #include "../reprocessing_module/snapshot_reprocessing.h" #include "../reprocessing_module/save_snapshot_reprocessing.h" -#include "../ai_engine_module/VPTProcess.h" -#include "../ai_engine_module/face_det_ai_engine.h" -#include "../ai_engine_module/pedestrian_vehicle_retrograde.h" -#include "../ai_engine_module/pedestrian_vehicle_trespass.h" -#include "../ai_engine_module/tricycle_manned_process.h" -#include "../ai_engine_module/truck_manned_process.h" -#include "../ai_engine_module/motocycle_hs_process.h" -#include "../ai_engine_module/motocycle_refit_phone_process.h" -#include "../ai_engine_module/motocycle_phone_process.h" -#include "../ai_engine_module/motocycle_refit_process.h" +#include "../ai_engine_module/ai_engine_module.h" #include "../util/JpegUtil.h" #include "atlas_licence.h"//授权文件 @@ -84,6 +75,8 @@ private: void algorithm_motor_phone_process(vector& vpt_interest_task_id, vector vpt_interest_imgs, vector& vptResult); // 电动车改装(加雨棚) void algorithm_motor_refit_process(vector& vpt_interest_task_id, vector vpt_interest_imgs, vector& vptResult); + // 行人/二轮车闯红灯 + void algorithm_traffic_light_process(vector& vpt_interest_task_id, vector vpt_interest_imgs, vector& vptResult); private: @@ -152,6 +145,7 @@ private: ai_engine_module::motocycle_refit_phone_process::MotorRefitPhoneProcess motor_refit_phoneprocess_; // ai_engine_module::motocycle_phone_process::MotorPhoneProcess motor_phoneprocess_; ai_engine_module::motocycle_refit_process::MotorRefitProcess motor_refitprocess_; + ai_engine_module::traffic_light_process::TrafficLightProcess traffic_lightprocess_; face_det_ai_engine m_face_det_ai_engine; // 人脸检测 diff --git a/src/ai_platform/header.h b/src/ai_platform/header.h index 878a1cc..2f728a2 100755 --- a/src/ai_platform/header.h +++ b/src/ai_platform/header.h @@ -46,7 +46,9 @@ enum class algorithm_type_t { TRICYCLE_MANNED = 503, // 三轮车载人 TRUCK_MANNED = 504, // 货车货箱载人 NONMOTOR_VEHICLE_USEPHONE = 505,// 电动/摩托车驾乘人员使用手机 - NONMOTOR_VEHICLE_REFIT = 506, // 电动车改装(加雨棚) + NONMOTOR_VEHICLE_REFIT = 506, // 电动车改装(加雨棚) + PERSON_RUNNING_REDLIGHTS = 507, // 行人闯红灯 + NONMOTOR_RUNNING_REDLIGHTS = 508, // 非机动车闯红灯 }; diff --git a/src/ai_platform/task_param_manager.cpp b/src/ai_platform/task_param_manager.cpp index 04b7a16..f47d047 100755 --- a/src/ai_platform/task_param_manager.cpp +++ b/src/ai_platform/task_param_manager.cpp @@ -58,9 +58,15 @@ bool copy_algor_param_aux(const algorithm_type_t &algor_type, const std::string case algorithm_type_t::NONMOTOR_VEHICLE_REFIT: m_algor_config_params[task_id].nonmotor_vehicle_algors.insert(algor_type); goto _manned_param_copy; + case algorithm_type_t::NONMOTOR_RUNNING_REDLIGHTS: + m_algor_config_params[task_id].nonmotor_vehicle_algors.insert(algor_type); + goto _manned_param_copy; case algorithm_type_t::TRICYCLE_MANNED: m_algor_config_params[task_id].nonmotor_vehicle_algors.insert(algor_type); goto _manned_param_copy; + case algorithm_type_t::PERSON_RUNNING_REDLIGHTS: + m_algor_config_params[task_id].human_algors.insert(algor_type); + goto _manned_param_copy; case algorithm_type_t::TRUCK_MANNED: { m_algor_config_params[task_id].vehicle_algors.insert(algor_type); _manned_param_copy : { diff --git a/src/demo/Makefile b/src/demo/Makefile index af7c49b..5639d8c 100755 --- a/src/demo/Makefile +++ b/src/demo/Makefile @@ -33,7 +33,7 @@ lib_dir=-L/usr/local/Ascend/ascend-toolkit/6.3.RC1/runtime/lib64 \ lib=-lacl_dvpp -lascendcl -lacl_dvpp_mpi -lruntime -lascendalog -lc_sec -lmsprofiler -lgert -lmmpa -lascend_hal -lexe_graph -lge_executor -lgraph -lprofapi -lascend_protobuf -lerror_manager -lhybrid_executor -lregister -ldavinci_executor -lge_common -lge_common_base \ -lplatform -lgraph_base -lqos_manager -LIBS= -L $(DEPEND_DIR) -lvpt_det_vdec -lsycheck -lface_det_vdec -lhs_tri_process -lhs_truck_process -lhs_motor_process -lphone_motor_det -lhcp_vdec -lmotor_rainshed_vdec -latlaslic -lvpt_ascend\ +LIBS= -L $(DEPEND_DIR) -lvpt_det_vdec -lsycheck -lface_det_vdec -lhs_tri_process -lhs_truck_process -lhs_motor_process -lphone_motor_det -lhcp_vdec -lmotor_rainshed_vdec -ltraffic_light_vdec -latlaslic -lvpt_ascend\ -L $(OPENCV_ROOT)/lib -lopencv_world\ -L $(JSON_ROOT)/lib -ljsoncpp \ -L $(FFMPEG_ROOT)/lib -lavformat -lavcodec -lswscale -lavutil -lavfilter -lswresample -lavdevice \ diff --git a/src/demo/demo.cpp b/src/demo/demo.cpp index c08fdf5..42c3a2d 100755 --- a/src/demo/demo.cpp +++ b/src/demo/demo.cpp @@ -223,6 +223,56 @@ void set_task_params(task_param &tparam, const unsigned &idx, const algorithm_ty algor_init_params->basic_param = basic_params; } break; + case algorithm_type_t::PERSON_RUNNING_REDLIGHTS: { + auto algor_params = new algor_config_param_manned_incident; + { + algor_params->m = 10; + algor_params->n = 8; + algor_params->obj_confidence_threshold = 0.5f; + algor_params->obj_min_height = 6; + algor_params->obj_min_width = 32; + } + + auto basic_params = new algor_basic_config_param_t; + { + // basic_params->algor_valid_rect.top_ = 0; + // basic_params->algor_valid_rect.left_ = 0; + // basic_params->algor_valid_rect.width_ = 1920; + // basic_params->algor_valid_rect.height_ = 1080; + basic_params->video_folder = "res/video_recode"; + basic_params->result_folder = "res/person_runred"; + basic_params->result_folder_little = "res/person_runred_little"; + } + + algor_init_params->algor_param = algor_params; + algor_init_params->basic_param = basic_params; + } break; + + case algorithm_type_t::NONMOTOR_RUNNING_REDLIGHTS: { + auto algor_params = new algor_config_param_manned_incident; + { + algor_params->m = 10; + algor_params->n = 8; + algor_params->obj_confidence_threshold = 0.5f; + algor_params->obj_min_height = 6; + algor_params->obj_min_width = 32; + } + + auto basic_params = new algor_basic_config_param_t; + { + // basic_params->algor_valid_rect.top_ = 0; + // basic_params->algor_valid_rect.left_ = 0; + // basic_params->algor_valid_rect.width_ = 1920; + // basic_params->algor_valid_rect.height_ = 1080; + basic_params->video_folder = "res/video_recode"; + basic_params->result_folder = "res/motor_runred"; + basic_params->result_folder_little = "res/motor_runred_little"; + } + + algor_init_params->algor_param = algor_params; + algor_init_params->basic_param = basic_params; + } break; + case algorithm_type_t::FACE_SNAPSHOT: { auto basic_params = new algor_basic_config_param_t; { @@ -721,7 +771,7 @@ string createTask(void *handle, std::vector algor_vec, int gi, tparam.ipc_url = "/data/share/data/hczr1.mp4"; break; case 8: - tparam.ipc_url = "/opt/share/data/1-00000001d9.mp4"; + tparam.ipc_url = "/data/share/data/燕高路口高点_CVR_2015-12-30_09-00-00_2015-12-30.mp4"; break; case 9: tparam.ipc_url = "/opt/share/data/1-00000002d55_h265.mp4"; @@ -843,7 +893,7 @@ void test_gpu(int gpuID){ std::vector algor_vec2 = {algorithm_type_t::NONMOTOR_VEHICLE_NOHELMET, algorithm_type_t::NONMOTOR_VEHICLE_OVERMAN, algorithm_type_t::TRICYCLE_MANNED, algorithm_type_t::TRUCK_MANNED, algorithm_type_t::NONMOTOR_VEHICLE_USEPHONE, - algorithm_type_t::NONMOTOR_VEHICLE_REFIT}; + algorithm_type_t::NONMOTOR_VEHICLE_REFIT, algorithm_type_t::PERSON_RUNNING_REDLIGHTS, algorithm_type_t::NONMOTOR_RUNNING_REDLIGHTS}; std::vector algor_vec3 = {algorithm_type_t::FACE_SNAPSHOT}; /* @@ -870,7 +920,7 @@ void test_gpu(int gpuID){ createTask(handle, algor_vec2, 5); createTask(handle, algor_vec2, 6); createTask(handle, algor_vec2, 7); - // createTask(handle, algor_vec, 8); + createTask(handle, algor_vec2, 8); // createTask(handle, algor_vec, 9); // createTask(handle, algor_vec, 10); // createTask(handle, algor_vec, 11); diff --git a/src/tsl_aiplatform_jni/AiEngineNativeInterface.cpp b/src/tsl_aiplatform_jni/AiEngineNativeInterface.cpp index 732bd0a..31430a1 100755 --- a/src/tsl_aiplatform_jni/AiEngineNativeInterface.cpp +++ b/src/tsl_aiplatform_jni/AiEngineNativeInterface.cpp @@ -382,6 +382,8 @@ JNIEXPORT jint JNICALL Java_com_objecteye_nativeinterface_TSLAiEngineNativeInter case algorithm_type_t::NONMOTOR_VEHICLE_OVERMAN: case algorithm_type_t::NONMOTOR_VEHICLE_USEPHONE: case algorithm_type_t::NONMOTOR_VEHICLE_REFIT: + case algorithm_type_t::NONMOTOR_RUNNING_REDLIGHTS: + case algorithm_type_t::PERSON_RUNNING_REDLIGHTS: case algorithm_type_t::TRICYCLE_MANNED: case algorithm_type_t::TRUCK_MANNED: { jfieldID fid = env->GetFieldID(cls_AlgorConfigParam, "hs_threshold", "I"); -- libgit2 0.21.4