-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_fight.cpp
91 lines (84 loc) · 2.93 KB
/
test_fight.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <chrono>
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <assert.h>
#include <thread>
#include <stdio.h>
#include "libai_core.hpp"
#include "config.hpp"
using namespace std;
using namespace ucloud;
/**
* ./test_fight
*/
int main(int argc, char* argv[]) {
float threshold, nms_threshold;
AlgoAPIName mainApiName, subApiName;
ucloud::TvaiResolution maxTarget={0,0};
ucloud::TvaiResolution minTarget={0,0};
std::vector<ucloud::TvaiRect> pRoi;
int use_batch = 0;
task_parser(TASKNAME::FIGHT, threshold,nms_threshold, mainApiName, subApiName, use_batch);
AlgoAPISPtr algoHandle = AICoreFactory::getAlgoAPI(mainApiName);
RET_CODE ret = algoHandle->init(modelInfo[mainApiName]);
cout << "@@ init return = " << ret << endl;
ret = algoHandle->set_param(threshold, nms_threshold, maxTarget, minTarget, pRoi);
std::string datapath = "fight/";
std::ifstream infile;
std::string filename = datapath + "list.txt";
//DATA
infile.open(filename, std::ios::in);
std::string imgname;
std::vector<string> vec_imgnames;
bool use_yuv = false;
while(infile >> imgname){
if(imgname.find(".yuv")>=0 && imgname.find(".yuv")!=std::string::npos){
use_yuv = true;
}
vec_imgnames.push_back(imgname);
}
double total_tm_cost = 0;
BatchImageIN batch_tvimages;
const int batch_size_in = 8;
for(auto iter=vec_imgnames.begin(); iter!=vec_imgnames.end(); iter++){
unsigned char* ptrImg = nullptr;
unsigned char* ptrShow = nullptr;
int width, height, stride;
int _width, _height, _stride;
int inpSz;
TvaiImageFormat inpFmt = TVAI_IMAGE_FORMAT_NV21;
std::string imgname_full = datapath + *iter;
if(!use_yuv){
ptrImg = readImg_to_NV21(imgname_full, width, height, stride );
ptrShow = readImg(imgname_full, _width, _height);
_stride = _width;
}
else{
width = 1920; height = 1080; stride = width;
ptrImg = yuv_reader(imgname_full, width, height);
}
inpSz = 3*stride*height/2*sizeof(unsigned char);
TvaiImage inpImg(inpFmt,width,height,stride,ptrImg,inpSz);
batch_tvimages.push_back(inpImg);
if(batch_tvimages.size()==batch_size_in){
//ALGO
BatchBBoxIN batch_bboxes;
VecObjBBox result;
ret = algoHandle->run(batch_tvimages, result);
cout << "@@ run return = " << ret << endl;
if(!result.empty()){
cout << "fight prob = " << result[0].confidence << endl;
}
for(auto iter=batch_tvimages.begin(); iter!=batch_tvimages.end(); iter++ ){
free(iter->pData);
}
batch_tvimages.clear();
}
}
for(auto iter=batch_tvimages.begin(); iter!=batch_tvimages.end(); iter++ ){
free(iter->pData);
}
}