forked from vojirt/kcf
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathvideoio.cpp
75 lines (63 loc) · 1.71 KB
/
videoio.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
#include "videoio.hpp"
#include <iostream>
FileIO::FileIO(std::string video_in)
: capture(video_in), filename(video_in)
{
if (!capture.isOpened())
throw std::runtime_error("Cannot open video stream '" + video_in + "'");
size_t lastdot = filename.find_last_of(".");
std::string txt = (lastdot == std::string::npos) ? filename : filename.substr(0, lastdot);
txt += ".txt";
rect_file.open(txt);
if (!rect_file.is_open())
std::cout << txt << " not found - using empty init rectangle" << std::endl;
}
FileIO::FileIO(int camera_idx)
: capture(camera_idx)
{
if (!capture.isOpened())
throw std::runtime_error("Cannot open camera " + std::to_string(camera_idx));
}
cv::Rect FileIO::getInitRectangle()
{
if (!rect_file.is_open())
return cv::Rect();
if (rect_line.empty())
std::getline(rect_file, rect_line);
cv::Rect r;
if (sscanf(rect_line.c_str(), "%d,%d,%d,%d", &r.x, &r.y, &r.width, &r.height) == 4) {
rect_line.clear();
return r;
}
int num;
if (sscanf(rect_line.c_str(), "%d:%d,%d,%d,%d", &num, &r.x, &r.y, &r.width, &r.height) == 5) {
if (num == getImageNum()) {
rect_line.clear();
return r;
} else {
return cv::Rect();
}
}
std::cerr << "Error parsing init rectangle: " << rect_line << std::endl;
rect_line.clear();
return cv::Rect();
}
void FileIO::outputBoundingBox(const cv::Rect &bbox)
{
(void)bbox;
}
int FileIO::getNextFileName(char *fName)
{
(void)fName;
return 0;
}
int FileIO::getNextImage(cv::Mat &img)
{
capture >> img;
num++;
return img.empty() ? 0 : 1;
}
int FileIO::getImageNum() const
{
return num;
}