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.

119 lines
3.0 KiB

// 暴力锁定解锁鲁棒性测试
#include "NeoArithStandardDll.h"
#include "utils.h"
#include <iostream>
#include <memory>
#include <string.h>
#include <algorithm>
#include <thread>
#include "opencv2/opencv.hpp"
#include "TestAPI_Profile.h"
#include <random>
using std::cout;
using std::endl;
int TestAPI_SOT_LockUnlock_Stress()
{
// 产生一个仿真数据
int nWidth = 1920;
int nHeight = 1080;
const int Test_Len = 100000;
// 初始化随机数生成器
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<> offsetDist(-2000, 2000); // 在目标周围±5像素范围内随机
SimTargetImage factory(nWidth, nHeight);
factory.setCheckerboardBackGround(120, 0, 80);
// 创建算法句柄
ArithHandle pTracker = STD_CreatEOArithHandle();
// 初始化为凝视-对空模式
ARIDLL_EOArithInitWithMode(pTracker, nWidth, nHeight, GD_PIXEL_FORMAT_E::GD_PIXEL_FORMAT_NV12,
GLB_SYS_MODE::GLB_SYS_STARE, GLB_SCEN_MODE::GLB_SCEN_GROUND);
ARIDLL_INPUTPARA stInputPara = { 0 };
stInputPara.unFrmId++;
stInputPara.unFreq = 50;
stInputPara.stCameraInfo.fPixelSize = 15;
stInputPara.stCameraInfo.nFocus = 300;
stInputPara.stCameraInfo.unVideoType = GLB_VIDEO_IR_MW;
ARIDLL_OUTPUT stOutput = { 0 };
// 生成随机锁定解锁序列
std::vector<int> lockUnlockSequence = generateRandomLockUnlockSequence(Test_Len);
int nTrackSuc = 0;
int nLock = 0, nUnlock = 0, nLost = 0;
bool locked = false;
for (int i = 0; i < Test_Len; i++)
{
stInputPara.unFrmId++;
factory.update();
cv::Mat src = factory.getImageNV12();
GD_VIDEO_FRAME_S img = { 0 };
img.enPixelFormat = GD_PIXEL_FORMAT_E::GD_PIXEL_FORMAT_NV12;
img.u32Width = nWidth;
img.u32Height = nHeight;
img.u32Stride[0] = img.u32Width;
img.u64VirAddr[0] = (UBYTE8*)src.data;
int targetNum = 0;
cv::TickMeter tm1;
tm1.start();
{
//targetNum = ARIDLL_SearchFrameTargets(pTracker, img);
}
tm1.stop();
printf("det time:%.2f", tm1.getTimeMilli());
// 根据序列执行锁定/解锁操作
switch (lockUnlockSequence[i])
{
case 1: // 锁定
{
// 在目标周围随机选择锁定位置
int offsetX = offsetDist(gen);
int offsetY = offsetDist(gen);
//ARIDLL_LockCommand_DefaultSize(pTracker, (int)nWidth / 2 + offsetX, (int)nHeight / 2 + offsetY, 30, 30);
//ARIDLL_LockTarget_DefaultSize(pTracker, img,(int)nWidth / 2 + offsetX, (int)nHeight / 2 + offsetY, 30, 30);
locked = true;
nLock++;
}
break;
case 2: // 解锁
ARIDLL_unLockCommand(pTracker);
locked = false;
nUnlock++;
break;
default: // 普通帧
break;
}
cv::TickMeter tm2;
tm2.start();
ARIDLL_RunController(pTracker, img, stInputPara, &stOutput);
tm2.stop();
printf(" trk time:%.2f\n", tm2.getTimeMilli());
#ifdef SHOW
cv::Mat rgb = factory.getImageRGB();
showArithInfo(rgb, &stOutput);
imshow("res", rgb);
cv::waitKey(1);
#endif
printf("nStatus:%d,Proc:%d", stOutput.nStatus,stInputPara.unFrmId);
}
// 输出测试统计结果
return 0;
}