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.

109 lines
2.5 KiB

// 单目标对地跟踪流程测试:将TLD从算法中剥离到外部导致API调用形式调整
// 读取avi视频进行测试
#include "NeoArithStandardDll.h"
#include "utils.h"
#include <iostream>
#include <memory>
#include <string.h>
#include <algorithm>
#include <thread>
#include "opencv2/opencv.hpp"
using std::cout;
using std::endl;
using std::string;
int main(int argc,char *argv[])
{
cv::VideoCapture capture(argv[1]);
int nWidth = int(capture.get(cv::CAP_PROP_FRAME_WIDTH));
int nHeight = int(capture.get(cv::CAP_PROP_FRAME_HEIGHT));
// 创建算法句柄
ArithHandle pTracker = STD_CreatEOArithHandle();
// 初始化为凝视-对地模式
ARIDLL_EOArithInitWithMode(pTracker,nWidth,nHeight,GD_PIXEL_FORMAT_E::GD_PIXEL_FORMAT_GRAY_Y16,
GLB_SYS_MODE::GLB_SYS_STARE,GLB_SCEN_MODE::GLB_SCEN_GROUND);
// 算法输入部分
ARIDLL_INPUTPARA stInputPara = { 0 };
stInputPara.unFrmId++;
stInputPara.stCameraInfo.fPixelSize = 15;
stInputPara.stCameraInfo.nFocus = 300;
// 算法输出部分
ARIDLL_OUTPUT stOutput = { 0 };
unsigned char* pY8Data = new unsigned char[nWidth * nHeight];
// 模拟算法执行流程
int nTrackSuc = 0;
cv::Mat frame;
while(1)
{
stInputPara.unFrmId++;
capture.read(frame);
if(frame.empty())
break;
// 下发面锁定指令
if (stInputPara.unFrmId == 10)
{
ARIDLL_LockCommand(pTracker, 228*2,279*2,40,25);
}
cv::Mat srcGray(nHeight,nWidth,CV_8UC1);
cv::cvtColor(frame,srcGray,cv::COLOR_RGB2GRAY);
for (size_t i = 0; i < nWidth * nHeight; i++)
{
pY8Data[i] = srcGray.data[i];
}
// 构建图像类型
GD_VIDEO_FRAME_S img = { 0 };
img.enPixelFormat = GD_PIXEL_FORMAT_E::GD_PIXEL_FORMAT_GRAY_Y8;
img.u32Width = nWidth;
img.u32Height = nHeight;
img.u32Stride[0] = img.u32Width * 1;
img.u64VirAddr[0] = (unsigned char*)pY8Data;
// 运行算法主控逻辑API
ARIDLL_RunController(pTracker, img, stInputPara, &stOutput);
auto trackerOut = stOutput.stTrackers[0];
cv::Rect outRect;
outRect.width = MAX(15,(int)trackerOut.nObjW);
outRect.height= MAX(15, (int)trackerOut.nObjH);
outRect.x = (int)trackerOut.nX-outRect.width/2;
outRect.y = (int)trackerOut.nY-outRect.height/2;
//cv::rectangle(srcGray,outRect,cv::Scalar(0,0,255));
//cv::resize(srcGray,srcGray,cv::Size(nWidth/2,nHeight/2));
//imshow("res",srcGray);
//cv::waitKey(2);
}
delete[] pY8Data;
if(fabs(stOutput.stTrackers[0].nX - 1508) < 20 &&
fabs(stOutput.stTrackers[0].nY - 750) < 20)
{
cout << "pass" << endl;
}
return 0;
}