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.

162 lines
3.6 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

// 单目标对地跟踪流程测试:将TLD从算法中剥离到外部导致API调用形式调整
// 读取avi视频进行测试
#include "NeoArithStandardDll.h"
#include "utils.h"
#include <iostream>
#include <memory>
#include <string.h>
#include <algorithm>
#include <thread>
#include "opencv2/opencv.hpp"
#include <stdio.h>
#include <time.h>
#include <chrono>
using std::cout;
using std::endl;
#include <pthread.h>
#include <sys/time.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <net/if.h>
#include <termios.h>
#include <unistd.h>
int main()
{
//cv::VideoCapture capture("/mnt/wang/tv00.avi");
std::string folder_path = "/app/sd/wang/cut/"; // 图片文件夹路径
std::string file_extension = ".jpg"; // 文件扩展名
int total_images = 1500; // 总图片数量
std::stringstream filename;
filename << folder_path << std::setw(4) << std::setfill('0') << 1 << file_extension;
printf("filename:%s\n",filename.str().c_str());
// 读取图像
cv::Mat image = cv::imread(filename.str());
int nWidth = int(image.cols);
int nHeight = int(image.rows);
printf("nWidth = %d,nHeight = %d\n",nWidth,nHeight);
// 创建算法句柄
ArithHandle pTracker = STD_CreatEOArithHandle();
// 初始化为凝视-对地模式
ARIDLL_EOArithInitWithMode(pTracker,nWidth,nHeight,GD_PIXEL_FORMAT_E::GD_PIXEL_FORMAT_RGB_PACKED,
GLB_SYS_MODE::GLB_SYS_STARE,GLB_SCEN_MODE::GLB_SCEN_GROUND);
// 算法输入部分
ARIDLL_INPUTPARA stInputPara = { 0 };
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++;
std::stringstream filename;
filename << folder_path << std::setw(4) << std::setfill('0') << stInputPara.unFrmId << file_extension;
// 读取图像
cv::Mat frame = cv::imread(filename.str());
printf("read %s\n",filename.str());
if(frame.empty())
break;
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];
}
// 下发面锁定指令
if (stInputPara.unFrmId == 100)
{
int tmpW = 20;
int tmpH = 10;
int tmpX = 955;
int tmpY = 535;
ARIDLL_LockCommand(pTracker, tmpX,tmpY,tmpW,tmpH);
}
cv::TickMeter tm;tm.start();
// 构建图像类型
// 构建图像类型
GD_VIDEO_FRAME_S img = { 0 };
img.enPixelFormat = GD_PIXEL_FORMAT_E::GD_PIXEL_FORMAT_RGB_PACKED;
img.u32Width = nWidth;
img.u32Height = nHeight;
img.u32Stride[0] = img.u32Width * 3;
img.u64VirAddr[0] = (unsigned char*)frame.data;
ARIDLL_RunController(pTracker, img, stInputPara, &stOutput);
tm.stop();
printf("cv time = %g\n",tm.getTimeMilli());
auto trackerOut = stOutput.stTrackers[0];
cv::Rect outRect;
outRect.width = MAX(15,(int)trackerOut.nObjW);
outRect.height= MAX(15, (int)trackerOut.nObjW);
outRect.x = (int)trackerOut.nX-outRect.width/2;
outRect.y = (int)trackerOut.nY-outRect.height/2;
//cv::rectangle(frame,outRect,cv::Scalar(0,0,255));
stInputPara.bImageRataSys = true;
stInputPara.nElevationDiff = 100;
//cv::resize(frame,frame,cv::Size(nWidth/2,nHeight/2));
//writer << frame;
// imshow("res",frame);
// cv::waitKey(2);
}
// if (nTrackSuc > 270 * 0.95)
// {
// cout << "pass" << endl;
// }
cout << "pass" << endl;
return 0;
}