Merge branch '3090' of ssh://192.168.5.5:29418/Algorithm/baseDetector into 3090
1个文件已删除
2个文件已添加
1 文件已重命名
9个文件已修改
| | |
| | | cmake_minimum_required(VERSION 3.5) |
| | | project(yoloDetector VERSION 1.0) |
| | | project(baseDetector VERSION 1.0) |
| | | enable_language(CUDA) |
| | | |
| | | set(CMAKE_CXX_COMPILIER "/usr/bin/g++") |
File was renamed from config/log4cplus.properties |
| | |
| | | log4cplus.appender.DEBUG_MSGS.MaxBackupIndex=1 |
| | | |
| | | #设置输出日志路径 |
| | | log4cplus.appender.DEBUG_MSGS.File=../logs/trt_debug.log |
| | | log4cplus.appender.DEBUG_MSGS.File=/opt/vasystem/valog/01_Scheanve/01_baseDetector_debug.log |
| | | log4cplus.appender.DEBUG_MSGS.layout=log4cplus::PatternLayout |
| | | |
| | | #设置日志打印格式 |
| | |
| | | log4cplus.appender.ERROR_MSGS.MaxBackupIndex=1 |
| | | |
| | | #设置输出日志路径 |
| | | log4cplus.appender.ERROR_MSGS.File=../logs/trt_error.log |
| | | log4cplus.appender.ERROR_MSGS.File=/opt/vasystem/valog/01_Scheanve/01_baseDetector_error.log |
| | | log4cplus.appender.ERROR_MSGS.layout=log4cplus::PatternLayout |
| | | |
| | | #设置日志打印格式 |
| | |
| | | log4cplus.appender.WARN_MSGS.MaxBackupIndex=1 |
| | | |
| | | #设置输出日志路径 |
| | | log4cplus.appender.WARN_MSGS.File=../logs/trt_warn.log |
| | | log4cplus.appender.WARN_MSGS.File=/opt/vasystem/valog/01_Scheanve/01_baseDetector_warn.log |
| | | log4cplus.appender.WARN_MSGS.layout=log4cplus::PatternLayout |
| | | |
| | | #设置日志打印格式 |
| | |
| | | sr = get_result(handle, img, 0); |
| | | TResult * t_result = (TResult*) sr; |
| | | cout << "t_result->count==" << t_result->count << endl; |
| | | for (int i=0; i<t_result->count; i++){ |
| | | for (int i=0; i<t_result->count; i++) |
| | | { |
| | | cout << "confidence:" << t_result->targets[i].confidence << endl; |
| | | draw_SDK_result(frame, t_result->targets[i]); |
| | | // draw_SDK_result(frame, t_result->targets[i]); |
| | | } |
| | | }else{ |
| | | cout << "------------over--" << endl; |
| | |
| | |
|
| | | #ifndef INC_01_CPP_SORT_CONFIG_H
|
| | | #define INC_01_CPP_SORT_CONFIG_H
|
| | | #include "utils/timer_utils.hpp"
|
| | | #include "utils/time_util.h"
|
| | |
|
| | | #include <opencv2/opencv.hpp>
|
| | | #include <algorithm>
|
| | |
| | |
|
| | | // 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)
|
| | | // {
|
| | | if(result_box.id == 1)
|
| | | {
|
| | | Target target;
|
| | | init_target(&target);
|
| | |
|
| | |
| | |
|
| | | t_result.targets[w_count] = target;
|
| | | w_count ++;
|
| | | // }
|
| | | }
|
| | | }
|
| | | std::cout << "eve batch_res size:: "<< batch_res[0].size() << " w_count: " << w_count <<std::endl;
|
| | | t_result.count = w_count;
|
| | | draw_SDK_result(cam_id, frame, t_result); //多线程无法调用绘图
|
| | | }
|
| | |
|
| | | void AriManager::init_target(Target *t){
|
| | |
| | | #include "std_target.h"
|
| | | #include "config.h"
|
| | | #include "detector.h"
|
| | | #include "../utils/draw_util.h"
|
| | |
|
| | | using namespace std;
|
| | | using namespace cv;
|
| | |
| | | #include <stdint.h> |
| | | #include <string> |
| | | #include <vector> |
| | | #include "../utils/timer_utils.hpp" |
| | | #include "../utils/time_util.h" |
| | | #include "../config.h" |
| | | #include "opencv2/opencv.hpp" |
| | | |
| | |
| | | // 创建
|
| | | API void* create(const char *conf, int *max_chan)
|
| | | {
|
| | | CLog::Initialize("../config/log4cplus.properties");
|
| | | CLog::Initialize("/opt/vasystem/bin/models/baseDetector/log.properties");
|
| | | ReadJsonFromFile(conf);
|
| | | AriManager *handle = new AriManager();
|
| | | Timer::getInstance()->reset();
|
| | | return handle;
|
| | | }
|
| | |
|
| | |
| | | AriManager *h = (AriManager*)handle;
|
| | | TResult *t_result = (TResult*)malloc(sizeof(TResult));
|
| | | init_TResult(t_result);
|
| | |
|
| | | Timer::getInstance()->out("eveTime before yolo");
|
| | | h->single_SDK(chan, img, *t_result);
|
| | | Timer::getInstance()->out("eveTime runing yolo");
|
| | | return t_result;
|
| | | }
|
| | |
|
| | |
| | | // DEBUG( ":::::::::create folder! error!::::::");
|
| | | // }
|
| | | // }
|
| | | DEBUG("=2==create_path:")
|
| | | DEBUG("=2==create_path:");
|
| | | char DirName[256];
|
| | | strcpy(DirName,path);
|
| | | int i,len = strlen(DirName);
|
| | | if(DirName[len-1]!='/')
|
| | | strcat(DirName,"/");
|
| | | strcat(DirName,"/");
|
| | | len = strlen(DirName);
|
| | | for(i=1;i<len;i++)
|
| | | {
|
| | |
| | | // perror("mkdir error");
|
| | | // }
|
| | | // }
|
| | | DEBUG("=1==create_path:")
|
| | | DEBUG("=1==create_path:");
|
| | | int a = access(DirName, F_OK);
|
| | | if(a ==-1)
|
| | | {
|
| | |
| | | cv::imshow(to_string(1), mat_img);
|
| | | cv::waitKey(0);
|
| | | }
|
| | |
|
| | | cv::VideoWriter writer("./01_baseDetector.avi", cv::VideoWriter::fourcc('M','J','P','G'),24, cv::Size(800,500), true);
|
| | | // cv::VideoWriter writer("/opt/vasystem/valog/01_Scheanve/01_baseDetector.avi", cv::VideoWriter::fourcc('M','J','P','G'),24, cv::Size(800,500), true);
|
| | |
|
| | | void draw_SDK_result(const int cam_id, cv::Mat mat_img, TResult& t_result)
|
| | | {
|
| | | cv::Rect tmp_rect;
|
| | |
|
| | | for (int i = 0; i < t_result.count; ++i)
|
| | | {
|
| | | auto &result = t_result.targets[i];
|
| | | tmp_rect = cv::Rect(result.rect.left,result.rect.top,result.rect.right-result.rect.left,result.rect.bottom-result.rect.top);
|
| | | cv::rectangle(mat_img, tmp_rect , cv::Scalar(50, 200, 50), 2);
|
| | | // cv::putText(mat_img, std::to_string(result.id), Point((result.rect.left+result.rect.right)/2,result.rect.top+150), CV_FONT_HERSHEY_SIMPLEX, 0.8, Scalar(255,255,0), 2);
|
| | | }
|
| | | // delete tmp_rect;
|
| | | cv::resize(mat_img, mat_img, cv::Size(800,500));
|
| | | // cv::imwrite("1111.jpg", mat_img);
|
| | | // cv::imshow("RESULT", mat_img);
|
| | | writer<< mat_img;
|
| | | // cv::waitKey(0);
|
| | | }
|
| | |
| | | void create_foldert(const char *path);
|
| | |
|
| | | void draw_SDK_result(cv::Mat mat_img, Target& target);
|
| | | void draw_SDK_result(const int cam_id, cv::Mat mat_img, TResult& t_result);
|
| | |
|
| | |
|
| | |
|
| | | #endif //DRAW_UTIL_H
|
New file |
| | |
| | | //
|
| | | // Created by Scheaven on 2020/5/14.
|
| | | //
|
| | |
|
| | | #include "time_util.h"
|
| | |
|
| | | #include <stdio.h>
|
| | | #include <memory.h>
|
| | | #include <iostream>
|
| | | #include <ctime>
|
| | | #include <string>
|
| | | #include "stdlib.h"
|
| | | #include <sys/time.h>
|
| | | #include <time.h>
|
| | | #include <unistd.h>
|
| | |
|
| | | using namespace std;
|
| | |
|
| | | int get_run_time(struct timeval *result, struct timeval *begin, struct timeval * end)
|
| | | {
|
| | | if(begin->tv_sec > end->tv_sec) return -1;
|
| | | if((begin->tv_sec == end->tv_sec) && (begin->tv_usec > end->tv_usec)) return -2;
|
| | | result->tv_sec = end->tv_sec - begin->tv_sec;
|
| | | result->tv_usec = end->tv_usec - begin->tv_usec;
|
| | |
|
| | | if(result->tv_usec<0)
|
| | | {
|
| | | result->tv_sec--;
|
| | | result->tv_usec += 1000000;
|
| | | }
|
| | | return 0;
|
| | | }
|
| | |
|
| | | time_t strTime2unix(char* timeStamp)
|
| | | {
|
| | | struct tm tm;
|
| | | memset(&tm, 0, sizeof(tm));
|
| | |
|
| | | sscanf(timeStamp, "%d-%d-%d %d:%d:%d",
|
| | | &tm.tm_year, &tm.tm_mon, &tm.tm_mday,
|
| | | &tm.tm_hour, &tm.tm_min, &tm.tm_sec);
|
| | |
|
| | | tm.tm_year -= 1900;
|
| | | tm.tm_mon--;
|
| | |
|
| | | return mktime(&tm);
|
| | | }
|
| | |
|
| | | long char_2_unix(char* str1)
|
| | | {
|
| | | char str[100];
|
| | | // std::cout<< "==char_2_unix=%s:" << str1<< std::endl;
|
| | |
|
| | | strcpy(str, str1);
|
| | | const char *mySplit = ".";
|
| | | char *p;
|
| | | char *p1;
|
| | | char *p2;
|
| | |
|
| | | p1 = strtok(str, mySplit);
|
| | | p2 = strtok(NULL, mySplit);
|
| | | // std::cout<< "--p1=:" << p1 << " : " << p2 << std::endl;
|
| | | time_t t = strTime2unix(p1);
|
| | |
|
| | | // std::cout<< "char_2_unix=t=%s:" << t << std::endl;
|
| | | return t*1000+atoi(p2);
|
| | | }
|
| | |
|
| | |
|
| | | char* fa_getSysTime()
|
| | | {
|
| | | struct timeval tv;
|
| | | gettimeofday(&tv,NULL);
|
| | | struct tm* pTime;
|
| | | pTime = localtime(&tv.tv_sec);
|
| | |
|
| | | static char sTemp[30] = "0";
|
| | | snprintf(sTemp, sizeof(sTemp), "%04d-%02d-%02d %02d:%02d:%02d:%03d", pTime->tm_year+1900, \
|
| | | pTime->tm_mon+1, pTime->tm_mday, pTime->tm_hour, pTime->tm_min, pTime->tm_sec, \
|
| | | tv.tv_usec/1000);
|
| | | char* TP = sTemp;
|
| | | return TP;
|
| | | }
|
| | |
|
| | | string random_int(size_t length)
|
| | | {
|
| | | long seed = (unsigned)time(NULL) + (unsigned)clock();
|
| | | srand(seed);
|
| | | auto randchar= []() ->char
|
| | | {
|
| | | const char charset[] = "0123456789";
|
| | | const size_t max_index = (sizeof(charset) - 1);
|
| | | return charset[rand()%max_index];
|
| | | };
|
| | | std::string str(length,0);
|
| | | std::generate_n(str.begin(),length,randchar);
|
| | | //SLOG::getInstance()->addLog(0, str + "------seed and id--init-----id:" + to_string(seed));
|
| | | return str;
|
| | | }
|
| | |
|
| | |
|
| | | Timer* Timer::instance = NULL;
|
| | | Timer* Timer::getInstance()
|
| | | {
|
| | | if (instance==NULL)
|
| | | {
|
| | | instance = new Timer();
|
| | | }
|
| | | return instance;
|
| | | }
|
| | |
|
| | | Timer::Timer():beg_(clock_::now()){}
|
| | | void Timer::reset()
|
| | | {
|
| | | beg_ = clock_::now();
|
| | | }
|
| | |
|
| | | double Timer::elapsed() const
|
| | | {
|
| | | return std::chrono::duration_cast<second_>(clock_::now() - beg_).count();
|
| | | }
|
| | |
|
| | | void Timer::out(std::string message)
|
| | | {
|
| | | double t = elapsed();
|
| | | // std::cout << message << " elasped time:" << t << "ms" << std::endl;
|
| | | DEBUG((boost::format("%e: %f ms")%message %t).str());
|
| | | reset();
|
| | | }
|
| | |
|
| | | double Timer::get_duration() const
|
| | | {
|
| | | return elapsed();
|
| | | }
|
New file |
| | |
| | | //
|
| | | // Created by Scheaven on 2020/5/14.
|
| | | //
|
| | |
|
| | | #ifndef DEMO_TIME_UTIL_H
|
| | | #define DEMO_TIME_UTIL_H
|
| | |
|
| | | #include <sys/time.h>
|
| | | #include <cstdio>
|
| | | #include <time.h>
|
| | | #include <stdlib.h>
|
| | | #include <string>
|
| | | #include <algorithm>
|
| | | #include <sstream>
|
| | |
|
| | | int get_run_time(struct timeval *result, struct timeval *begin, struct timeval *end);
|
| | |
|
| | | time_t strTime2unix(char* timeStamp);
|
| | |
|
| | | long char_2_unix(char* str1);
|
| | |
|
| | | char* fa_getSysTime();
|
| | |
|
| | | std::string random_int(size_t length);
|
| | |
|
| | | #include <chrono>
|
| | | #include "log_util.h"
|
| | | #include <boost/format.hpp>
|
| | |
|
| | | class Timer
|
| | | {
|
| | | public:
|
| | | static Timer* instance;
|
| | | static Timer* getInstance();
|
| | |
|
| | | Timer();
|
| | | public:
|
| | | void reset();
|
| | | double elapsed() const;
|
| | | void out(std::string message="");
|
| | | // DEBUG((boost::format("nhao%d")%1).str());
|
| | | double get_duration() const;
|
| | | private:
|
| | | using clock_ = std::chrono::high_resolution_clock;
|
| | | using second_=std::chrono::duration<double,std::milli>;
|
| | | std::chrono::time_point<clock_>beg_;
|
| | | };
|
| | |
|
| | | #endif //DEMO_TIME_UTIL_H
|