//
|
// Created by Scheaven on 2019/11/19.
|
//
|
|
#include "detecter_manager.h"
|
#include <thread>
|
#include <unistd.h>
|
#include <cstdlib>
|
|
DetecterManager* DetecterManager::instance = NULL;
|
|
DetecterManager* DetecterManager::getInstance()
|
{
|
if(instance==NULL)
|
{
|
instance = new DetecterManager();
|
}
|
return instance;
|
}
|
|
DetecterManager::DetecterManager()
|
{
|
Config config;
|
config.net_type = YOLOV4;
|
config.file_model_cfg = m_staticStruct::model_cfg;
|
config.file_model_weights = m_staticStruct::model_wts;
|
config.calibration_image_list_file_txt = "../configs/calibration_images.txt";
|
config.inference_precison = INT8;
|
config.detect_thresh = 0.5;
|
|
//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);
|
std::cout << "loading detector model......" << std::endl;
|
}
|
|
|
DetecterManager::~DetecterManager()
|
{
|
}
|
|
void DetecterManager::release()
|
{
|
// Detector::getInstance()->release();
|
|
delete DetecterManager::instance;
|
DetecterManager::instance = NULL;
|
}
|
|
void DetecterManager::detecter_main(cv::Mat &mat_image, DETECTIONS& detection)
|
{
|
std::vector<BatchResult> batch_res;
|
std::vector<cv::Mat> batch_img;
|
|
batch_img.push_back(mat_image.clone());
|
this->detector->detect(batch_img, batch_res);
|
encoder_features(batch_res, detection);
|
|
// show_result(result_vec);
|
// draw_boxes(mat_image, result_vec);
|
}
|
|
void DetecterManager::encoder_features(std::vector<BatchResult> boxes, DETECTIONS &detection)
|
{
|
std::vector<float> confidences;
|
std::vector<int> human_index;
|
|
int result_index=0;
|
|
for (const auto &result_box:boxes[0])
|
{
|
// #ifdef S_DEBUG
|
// printf("--%d-%d-%d-%d-%d---result_box-----\n", result_box.obj_id, result_box.x, result_box.y, result_box.w, result_box.h);
|
// #endif
|
if(result_box.id == 1)
|
{
|
// cv::Rect box = cv::Rect(result_box.x,result_box.y,result_box.w,result_box.h);
|
// get_detections(DETECTBOX(box.x, box.y,box.width, box.height), confidences[idx],d);
|
DETECTION_ROW tmpRow;
|
tmpRow.tlwh = DETECTBOX(result_box.rect.x,result_box.rect.y,result_box.rect.width,result_box.rect.height); //DETECTBOX(x, y, w, h);
|
tmpRow.confidence = result_box.prob*100;
|
tmpRow.obj_id = 0;
|
tmpRow.is_hat = true;
|
tmpRow.is_mask = true;
|
tmpRow.is_smoke = true;
|
tmpRow.hatScore = 0;
|
tmpRow.maskScore = 0;
|
tmpRow.smokeScore = 0;
|
// tmpRow.img_time = this->img_time;
|
|
tmpRow.isFall = false;
|
tmpRow.fallScore = 0;
|
tmpRow.runScore = 0;
|
tmpRow.isRun = false;
|
|
// tmpRow.human_face = nullptr;
|
|
int sub_box_index=0;
|
human_index.push_back(result_index);
|
|
detection.push_back(tmpRow);
|
}
|
result_index++;
|
}
|
}
|
|
// bool DetecterManager::sort_score(bbox_t box1, bbox_t box2)
|
// {
|
// return (box1.prob>box2.prob);
|
// }
|
|
// float DetecterManager::box_iou(bbox_t box1, bbox_t box2)
|
// {
|
// int x1 = std::max(box1.x, box2.x);
|
// int y1 = std::max(box1.y, box2.y);
|
// int x2 = std::min((box1.x+box1.w),(box2.x+box2.w));
|
// int y2 = std::min((box1.y+box1.h),(box2.y+box2.h));
|
// float over_area = (x2-x1)*(y2-y1);
|
// // printf("over_ares---%f ----%d----%d\n", over_area, box1.w*box1.h, box2.w*box2.h);
|
// float iou = over_area/((box1.w*box1.h<box2.w*box2.h)?box1.w*box1.h:box2.w*box2.h);
|
// return iou;
|
// }
|
|
void DetecterManager::set_imgTime(long img_time)
|
{
|
this->img_time = img_time;
|
}
|