4 * Desc : Simple class for parsing VOT inputs and providing
5 * interface for image loading and storing output.
14 #include <opencv2/opencv.hpp>
23 float x1; //bottom left
29 float x4; //bottom right
36 VOT(const std::string & region_file, const std::string & images, const std::string & ouput)
39 p_region_stream.open(region_file.c_str());
41 if (p_region_stream.is_open()){
43 std::getline(p_region_stream, line);
44 std::vector<float> numbers;
45 std::istringstream s( line );
52 if (numbers.size() == 4) {
53 float x = numbers[0], y = numbers[1], w = numbers[2], h = numbers[3];
62 } else if (numbers.size() == 8) {
72 std::cerr << "Error loading initial region in file - unknow format " << region_file << "!" << std::endl;
83 std::cerr << "Error loading initial region in file " << region_file << "!" << std::endl;
96 p_images_stream.open(images.c_str());
97 if (!p_images_stream.is_open())
98 std::cerr << "Error loading image file " << images << "!" << std::endl;
100 p_output_stream.open(ouput.c_str());
101 if (!p_output_stream.is_open())
102 std::cerr << "Error opening output file " << ouput << "!" << std::endl;
103 p_region_stream.close();
108 p_images_stream.close();
109 p_output_stream.close();
112 inline cv::Rect getInitRectangle() const
114 // read init box from ground truth file
115 VOTPolygon initPolygon = getInitPolygon();
116 float x1 = std::min(initPolygon.x1, std::min(initPolygon.x2, std::min(initPolygon.x3, initPolygon.x4)));
117 float x2 = std::max(initPolygon.x1, std::max(initPolygon.x2, std::max(initPolygon.x3, initPolygon.x4)));
118 float y1 = std::min(initPolygon.y1, std::min(initPolygon.y2, std::min(initPolygon.y3, initPolygon.y4)));
119 float y2 = std::max(initPolygon.y1, std::max(initPolygon.y2, std::max(initPolygon.y3, initPolygon.y4)));
120 return cv::Rect(x1, y1, x2-x1, y2-y1);
123 inline VOTPolygon getInitPolygon() const
124 { return p_init_polygon; }
127 inline void outputBoundingBox(const cv::Rect & bbox)
129 p_output_stream << bbox.x << "," << bbox.y << ",";
130 p_output_stream << bbox.width << "," << bbox.height << std::endl;
133 inline void outputPolygon(const VOTPolygon & poly)
135 p_output_stream << poly.x1 << "," << poly.y1 << ",";
136 p_output_stream << poly.x2 << "," << poly.y2 << ",";
137 p_output_stream << poly.x3 << "," << poly.y3 << ",";
138 p_output_stream << poly.x4 << "," << poly.y4 << std::endl;
141 inline int getNextFileName(char * fName)
143 if (p_images_stream.eof() || !p_images_stream.is_open())
146 std::getline (p_images_stream, line);
147 strcpy(fName, line.c_str());
151 inline int getNextImage(cv::Mat & img)
153 if (p_images_stream.eof() || !p_images_stream.is_open())
157 std::getline (p_images_stream, line);
158 if (line.empty() && p_images_stream.eof()) return -1;
159 img = cv::imread(line, CV_LOAD_IMAGE_COLOR);
166 VOTPolygon p_init_polygon;
167 std::ifstream p_region_stream;
168 std::ifstream p_images_stream;
169 std::ofstream p_output_stream;