#include <windows.h>
#include <fstream>
#include <iostream>
#include <string>
#include "opencv2/video/tracking.hpp"
#include "opencv2/highgui/highgui.hpp"
using
namespace
std;
using
namespace
cv;
typedef
struct
TrackingBox
{
int
frame;
int
id;
Rect_<
float
> box;
}TrackingBox;
void
TXTtoBOX() {
string inFileName =
"det.txt"
;
string outFileName =
"out.txt"
;
ifstream myfile(inFileName);
ofstream outfile(outFileName, ios::app);
if
(!myfile.is_open())
{
cerr <<
"Error: can not find file "
<<infilename <<endl;=
""
return
;=
""
}=
""
if
=
""
(!outfile.is_open())=
""
{=
""
cerr=
""
<<
"error:="
" can="
" not="
" find="
" file="
" "
=
""
<<outfilename=
""
string=
""
detline;=
""
存放读取出的单个目标信息=
""
istringstream=
""
ss;=
""
vector<trackingbox=
""
> detData;
char
ch;
float
tpx, tpy, tpw, tph;
while
(getline(myfile, detLine))
{
TrackingBox tb;
ss.str(detLine);
ss >> tb.frame >> ch >> tb.id >> ch;
ss >> tpx >> ch >> tpy >> ch >> tpw >> ch >> tph;
ss.str(
""
);
tb.box = Rect_<
float
>(Point_<
float
>(tpx, tpy), Point_<
float
>(tpx + tpw, tpy + tph));
detData.push_back(tb);
outfile <<detline <<endl;=
""
写文件=
""
cout=
""
<<
"detline:"
<<detline=
""
<<
"x:"
<<tpx=
""
<<
"="
" y:"
<<tpy=
""
w:
"="
" <<tpw="
" h:"
=
""
<<tph=
""
}=
""
myfile.close();=
""
outfile.close();=
""
while
=
""
(1);=
""
int
=
""
main()=
""
{=
""
txttobox();=
""
return
=
""
0;=
""
}<=
""
pre=
""
>
</detline></
float
></
float
></
float
></infilename></
float
></string></iostream></fstream></windows.h>