//
|
// Created by Scheaven on 2020/3/23.
|
//
|
|
#include "ari_manager.h"
|
|
|
AriManager::AriManager()
|
{
|
Config config;
|
// config.net_type = COMMON;
|
if(m_staticStruct::type==2)
|
config.net_type = SMALL;
|
else
|
config.net_type = COMMON;
|
|
|
this->detector = std::shared_ptr<Detector>(new Detector());
|
this->detector->init(config);
|
}
|
|
AriManager::~AriManager()
|
{
|
|
}
|
|
void AriManager::single_SDK(const int cam_id, const void *img, TResult& t_result)
|
{
|
TImage *frame_img = (TImage*)img;
|
cv::Mat frame(Size(frame_img->width, frame_img->height), CV_8UC3);
|
frame.data = (uchar*)frame_img->data;
|
|
std::vector<bbox_t> result_vec;
|
|
std::vector<BatchResult> batch_res;
|
std::vector<cv::Mat> batch_img;
|
|
// cv::Mat image0 = cv::imread("/data/disk1/project/03_tensorRT/yolo-tensorrt/configs/dog.jpg", cv::IMREAD_UNCHANGED);
|
// cv::Mat image1 = cv::imread("/data/disk1/project/03_tensorRT/yolo-tensorrt/configs/person.jpg", cv::IMREAD_UNCHANGED);
|
batch_img.push_back(frame.clone());
|
// batch_img.push_back(image1.clone());
|
// batch_img.push_back(image1.clone());
|
// batch_img.push_back(image0.clone());
|
// batch_img.push_back(image0.clone());
|
// batch_img.push_back(image0.clone());
|
// batch_img.push_back(image0.clone());
|
// batch_img.push_back(image0.clone());
|
// batch_img.push_back(image0.clone());
|
// batch_img.push_back(image0.clone());
|
// batch_img.push_back(image0.clone());
|
// batch_img.push_back(image0.clone());
|
// batch_img.push_back(image0.clone());
|
// batch_img.push_back(image0.clone());
|
// batch_img.push_back(image0.clone());
|
// batch_img.push_back(image1.clone());
|
|
// cv::imshow("img",image0);
|
// cv::waitKey(0);
|
Timer timer;
|
timer.reset();
|
this->detector->detect(batch_img, batch_res);
|
timer.out("detect");
|
|
t_result.targets = (Target*)malloc(sizeof(Target)*batch_res[0].size());
|
// 将算法结果转化为标准的格式(以目标检测为例)
|
int w_count = 0;
|
for (const auto &result_box:batch_res[0])
|
{
|
// if(result_box.id == 0)
|
// {
|
Target target;
|
init_target(&target);
|
|
target.rect.left = result_box.rect.x;
|
target.rect.top = result_box.rect.y;
|
target.rect.right = result_box.rect.x + result_box.rect.width;
|
target.rect.bottom = result_box.rect.y + result_box.rect.height;
|
|
target.confidence = result_box.prob*100; // 置信度转化成百分制
|
// target.id = 1; //
|
|
// target.attribute 可根据实际情况来添加,输出格式要求是json格式
|
|
//string attribute_json = "{";
|
//attribute_json += "\"smokingScore\":" + to_string(track->smokeScore)+",";
|
//if(attribute_json.length()>2)
|
//{
|
// attribute_json = attribute_json.substr(0, attribute_json.length()-1) +"}";
|
// target.attribute = new char[strlen(attribute_json.c_str())+1];
|
// target.attribute_size = strlen(attribute_json.c_str());
|
// strcpy(target.attribute, attribute_json.c_str());
|
//}
|
|
t_result.targets[w_count] = target;
|
w_count ++;
|
// }
|
}
|
t_result.count = w_count;
|
}
|
|
void AriManager::init_target(Target *t){
|
t->attribute = NULL;
|
t->feature = NULL;
|
t->id = 0;
|
t->rect = TRect{0,0,0,0};
|
t->confidence = 0;
|
t->attribute_size = 0;
|
t->feature_size = 0;
|
}
|