forked from gnebehay/CT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vot.hpp
89 lines (71 loc) · 2.26 KB
/
vot.hpp
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
/*
* Author : Tomas Vojir
* Date : 2013-06-05
* Desc : Simple class for parsing VOT inputs and providing
* interface for image loading and storing output.
*/
#ifndef CPP_VOT_H
#define CPP_VOT_H
#include <string>
#include <fstream>
#include <iostream>
#include "opencv2/opencv.hpp"
class VOT
{
public:
VOT(const std::string & region_file, const std::string & images, const std::string & ouput)
{
p_region_stream.open(region_file.c_str());
if (p_region_stream.is_open()){
float x, y, w, h;
char ch;
p_region_stream >> x >> ch >> y >> ch >> w >> ch >> h;
p_init_rectangle = cv::Rect(x, y, w, h);
}else{
std::cerr << "Error loading initial region in file " << region_file << "!" << std::endl;
p_init_rectangle = cv::Rect(0, 0, 0, 0);
}
p_images_stream.open(images.c_str());
if (!p_images_stream.is_open())
std::cerr << "Error loading image file " << images << "!" << std::endl;
p_output_stream.open(ouput.c_str());
if (!p_output_stream.is_open())
std::cerr << "Error opening output file " << ouput << "!" << std::endl;
}
~VOT()
{
p_region_stream.close();
p_images_stream.close();
p_output_stream.close();
}
inline cv::Rect getInitRectangle() const
{ return p_init_rectangle; }
inline void outputBoundingBox(const cv::Rect & bbox)
{ p_output_stream << bbox.x << ", " << bbox.y << ", " << bbox.width << ", " << bbox.height << std::endl; }
inline int getNextFileName(char * fName)
{
if (p_images_stream.eof() || !p_images_stream.is_open())
return -1;
std::string line;
std::getline (p_images_stream, line);
strcpy(fName, line.c_str());
return 1;
}
inline int getNextImage(cv::Mat & img)
{
if (p_images_stream.eof() || !p_images_stream.is_open())
return -1;
std::string line;
std::getline (p_images_stream, line);
img = cv::imread(line, CV_LOAD_IMAGE_COLOR);
printf("Processing");
printf(line.c_str());
printf("\n");
return 1;
}
cv::Rect p_init_rectangle;
std::ifstream p_region_stream;
std::ifstream p_images_stream;
std::ofstream p_output_stream;
};
#endif //CPP_VOT_H