You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
187 lines
6.7 KiB
187 lines
6.7 KiB
|
11 months ago
|
/*
|
||
|
|
* @Author: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
|
||
|
|
* @Date: 2024-03-29 11:44:17
|
||
|
|
* @LastEditors: Jacky
|
||
|
|
* @LastEditTime: 2024-04-02 09:54:42
|
||
|
|
* @FilePath: \main_app_hi3559a\mpp\ai_track\ai\daSiamRpnTrck.h
|
||
|
|
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
||
|
|
*/
|
||
|
|
//
|
||
|
|
|
||
|
|
#ifndef NNIE_LITE_SIAMCAR_TRACKER_H
|
||
|
|
#define NNIE_LITE_SIAMCAR_TRACKER_H
|
||
|
|
|
||
|
|
#include <cmath>
|
||
|
|
#include <chrono>
|
||
|
|
#include <iostream>
|
||
|
|
#include <vector>
|
||
|
|
#include <deque>
|
||
|
|
#include <opencv2/opencv.hpp>
|
||
|
|
#include "Net.h"
|
||
|
|
#include "use_mnn.hpp"
|
||
|
|
#include "use_reid.h"
|
||
|
|
#include "AIT_GlobalStruct.h"
|
||
|
|
#include "guidePlat.h"
|
||
|
|
#include "gd_alg_type.h"
|
||
|
|
|
||
|
|
//#define DUSE_REID_ALG (1)
|
||
|
|
#define DUSE_UPDATENET (0)
|
||
|
|
#define DUSE_TARGET_UPDATE (1)
|
||
|
|
#define UPDATE_TEMPLATE_ANCHOR_THD (30)
|
||
|
|
#define UPDATE_TEMPLATE_ANCHOR_SCORE (0.95)
|
||
|
|
#define DELAY_30MS (80000)
|
||
|
|
#define DEBUG_PRINT (0)
|
||
|
|
#define D_IN_VIODE_FPS (0)
|
||
|
|
#define D_MIN_TARGET_SIZE (10)
|
||
|
|
|
||
|
|
using namespace std::chrono;
|
||
|
|
|
||
|
|
namespace GUD
|
||
|
|
{
|
||
|
|
namespace ALG
|
||
|
|
{
|
||
|
|
class DaSiamRPNtracker
|
||
|
|
{
|
||
|
|
public:
|
||
|
|
explicit DaSiamRPNtracker(const gud_siamrpn_config_t config);
|
||
|
|
~DaSiamRPNtracker();
|
||
|
|
|
||
|
|
int nnieSearThrd();
|
||
|
|
|
||
|
|
void trackerInit(GuideImage *pSrcImg, gud_rect_t initBox, ai_detect_result_t *od_res);
|
||
|
|
void trackerReInit(GuideImage *pSrcImg, gud_rect_t initBox, ai_detect_result_t *od_res);
|
||
|
|
void trackerReInitFloat(GuideImage *pSrcImg, gud_rect_f initBox, ai_detect_result_t *od_res);
|
||
|
|
void trackerUpdateNpu(GuideImage *pSrcImg, cv::Rect2f &searRegion, bool useOutReg);
|
||
|
|
void trackerUpdateMnn(AIT_OUTPUT *pAiOut);
|
||
|
|
void trackerProcess(GuideImage *pSrcImg, gud_rect_t searchBox, ai_detect_result_t *od_res, AIT_OUTPUT *pAiOut);
|
||
|
|
void trackerProcessF(GuideImage *pSrcImg, gud_rect_f searchBox, ai_detect_result_t *od_res, AIT_OUTPUT *pAiOut);
|
||
|
|
|
||
|
|
gud_rect_t selectTagFromDetection(gud_rect_t bbox,ai_detect_result_t *AIod_res);
|
||
|
|
gud_rect_f selectTagFromDetectionF(gud_rect_f bbox,ai_detect_result_t *AIod_res);
|
||
|
|
void showFloatInputs(float* input, int size, int diff);
|
||
|
|
void showTrackerTimes(double timeEsp);
|
||
|
|
int calRectIOU(gud_rect_t re1, gud_rect_t re2);
|
||
|
|
void draw_rect(cv::Mat frame, cv::Rect targetBox, int type);
|
||
|
|
void reid_jsonReader(const char *reid_path, gud_reid_config_t *reid_config);
|
||
|
|
gud_rect_t LinearSpeed_TracePredict(std::deque<gud_rect_t> &trace);
|
||
|
|
|
||
|
|
struct trackerTime
|
||
|
|
{
|
||
|
|
double timeThd;
|
||
|
|
double minTime;
|
||
|
|
double maxTime;
|
||
|
|
double avgTime;
|
||
|
|
int expandTimes;
|
||
|
|
int updateTimes;
|
||
|
|
float expandRate;
|
||
|
|
};
|
||
|
|
|
||
|
|
struct trackerConfig
|
||
|
|
{
|
||
|
|
float windowInfluence = 0.43f;
|
||
|
|
float lr = 0.4f;
|
||
|
|
int scale = 8;
|
||
|
|
bool swapRB = false;
|
||
|
|
int totalStride = 8;
|
||
|
|
float penaltyK = 0.055f;
|
||
|
|
int exemplarSize = 127;
|
||
|
|
int instanceSize = 271;
|
||
|
|
float contextAmount = 0.5f;
|
||
|
|
std::vector<float> ratios = { 0.33f, 0.5f, 1.0f, 2.0f, 3.0f };
|
||
|
|
int anchorNum = int(ratios.size());
|
||
|
|
cv::Mat anchors;
|
||
|
|
cv::Mat windows;
|
||
|
|
cv::Scalar avgChans;
|
||
|
|
cv::Size imgSize = {0, 0};
|
||
|
|
cv::Rect2f targetBox = {0, 0, 0, 0};
|
||
|
|
cv::Rect2f searchBox = {0, 0, 0, 0};
|
||
|
|
int scoreSize = (instanceSize - exemplarSize) / totalStride + 1;
|
||
|
|
float tracking_score;
|
||
|
|
int label;
|
||
|
|
int FRN;
|
||
|
|
|
||
|
|
void update_scoreSize()
|
||
|
|
{
|
||
|
|
scoreSize = int((instanceSize - exemplarSize) / totalStride + 1);
|
||
|
|
}
|
||
|
|
};
|
||
|
|
trackerConfig trackState;
|
||
|
|
|
||
|
|
GuideBuf tmpBuf0;
|
||
|
|
//GuideBuf tmpBuf1;
|
||
|
|
GuideImage subImg;
|
||
|
|
GuideImage *fullImg;
|
||
|
|
cv::Rect2f outBox_ = { 0, 0, 0, 0 };
|
||
|
|
bool updateReg_;
|
||
|
|
|
||
|
|
int updataFlag = 0;
|
||
|
|
std::deque<gud_rect_t> traces_;
|
||
|
|
std::deque<gud_rect_f> tracesf_;
|
||
|
|
std::deque<gud_trk_res_t> trkRes_;
|
||
|
|
std::deque<cv::Mat> tagTemplates_;
|
||
|
|
|
||
|
|
private:
|
||
|
|
int initFlag_;
|
||
|
|
int ReidInit_;
|
||
|
|
int ReidFrq_;
|
||
|
|
int ReidCycleUp_;
|
||
|
|
float ReidUpRatio_;
|
||
|
|
int UpdataTemp_;
|
||
|
|
int UpdateFrq_;
|
||
|
|
int UseTrace_;
|
||
|
|
unsigned int TraceLen_;
|
||
|
|
unsigned int TempNum_;
|
||
|
|
float detThd_;
|
||
|
|
int acNumThd_;
|
||
|
|
|
||
|
|
int mnnIdx_;
|
||
|
|
int nnieIdx_;
|
||
|
|
float RegMap[256*22*22] = {0};
|
||
|
|
float ClsMap[256*22*22] = {0};
|
||
|
|
nnie::Net temple_net_;
|
||
|
|
NpuTensor tem_output01, tem_output02;
|
||
|
|
NpuTensor outTnsr[2];
|
||
|
|
nnie::Net detect_net_;
|
||
|
|
NpuTensor det_output01, det_output02;
|
||
|
|
nnie::Net uptemp_net_;
|
||
|
|
|
||
|
|
std::string RegOutputName = "52"; // output shape [4, 1805]
|
||
|
|
std::vector<int> RegOutputDim = {4, 1805};
|
||
|
|
float* RegOutputData = (float *)malloc(sizeof(float)*4*1805);
|
||
|
|
|
||
|
|
std::string ClsOutputName = "54"; // output shape [2, 1805]
|
||
|
|
std::vector<int> ClsOutputDim = {2, 1805};
|
||
|
|
float* ClsOutputData = (float *)malloc(sizeof(float)*2*1805);
|
||
|
|
|
||
|
|
MNN::Tensor::DimensionType net_type_caffe = MNN::Tensor::CAFFE;
|
||
|
|
|
||
|
|
cv::Mat generateAnchors();
|
||
|
|
cv::Mat generateHanningWindow();
|
||
|
|
cv::Mat getSubwindow(cv::Mat& img, const cv::Rect2f& targetBox, float originalSize, cv::Scalar avgChans, const int& out_sz);
|
||
|
|
|
||
|
|
cv::Mat xCrop, sc, rc, penalty, pscore;
|
||
|
|
cv::Rect2f resBox = { 0, 0, 0, 0 };
|
||
|
|
|
||
|
|
trackerTime tkTime_ = {0};
|
||
|
|
int MnnLoad_;
|
||
|
|
ForwardNet* mnnDoubleBranch_;
|
||
|
|
|
||
|
|
NNIE_REID* nnie_reid_;
|
||
|
|
gud_reid_config_t reid_config_;
|
||
|
|
gud_reid_result_t reid_result_;
|
||
|
|
|
||
|
|
steady_clock::time_point tt1_;
|
||
|
|
steady_clock::time_point tt2_;
|
||
|
|
steady_clock::time_point tt3_;
|
||
|
|
steady_clock::time_point tt4_;
|
||
|
|
duration<double> time_span_;
|
||
|
|
double time_all_ = 0;
|
||
|
|
|
||
|
|
};
|
||
|
|
|
||
|
|
};
|
||
|
|
};
|
||
|
|
|
||
|
|
|
||
|
|
#endif
|