forked from andrewssobral/bgslibrary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVideoAnalysis.cpp
169 lines (140 loc) · 4.48 KB
/
VideoAnalysis.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*
This file is part of BGSLibrary.
BGSLibrary is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
BGSLibrary is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with BGSLibrary. If not, see <http://www.gnu.org/licenses/>.
*/
#include "VideoAnalysis.h"
namespace bgslibrary
{
VideoAnalysis::VideoAnalysis() :
use_file(false), use_camera(false), cameraIndex(0),
use_comp(false), frameToStop(0)
{
std::cout << "VideoAnalysis()" << std::endl;
}
VideoAnalysis::~VideoAnalysis()
{
std::cout << "~VideoAnalysis()" << std::endl;
}
bool VideoAnalysis::setup(int argc, const char **argv)
{
bool flag = false;
#if CV_MAJOR_VERSION == 2
const char* keys =
"{hp|help|false|Print this message}"
"{uf|use_file|false|Use video file}"
"{fn|filename||Specify video file}"
"{uc|use_cam|false|Use camera}"
"{ca|camera|0|Specify camera index}"
"{co|use_comp|false|Use mask comparator}"
"{st|stopAt|0|Frame number to stop}"
"{im|imgref||Specify image file}"
;
#elif CV_MAJOR_VERSION >= 3
const std::string keys =
"{h help ? | | Print this message }"
"{uf use_file |false| Use a video file }"
"{fn filename | | Specify a video file }"
"{uc use_cam |false| Use a webcamera }"
"{ca camera | 0 | Specify camera index }"
"{co use_comp |false| Use mask comparator }"
"{st stopAt | 0 | Frame number to stop }"
"{im imgref | | Specify a image file }"
;
#endif
cv::CommandLineParser cmd(argc, argv, keys);
#if CV_MAJOR_VERSION == 2
if (argc <= 1 || cmd.get<bool>("help") == true)
{
std::cout << "Usage: " << argv[0] << " [options]" << std::endl;
std::cout << "Available options:" << std::endl;
cmd.printParams();
return false;
}
#elif CV_MAJOR_VERSION >= 3
if (argc <= 1 || cmd.has("help"))
{
std::cout << "Usage: " << argv[0] << " [options]" << std::endl;
std::cout << "Available options:" << std::endl;
cmd.printMessage();
return false;
}
if (!cmd.check())
{
cmd.printErrors();
return false;
}
#endif
use_file = cmd.get<bool>("uf"); //use_file
filename = cmd.get<std::string>("fn"); //filename
use_camera = cmd.get<bool>("uc"); //use_cam
cameraIndex = cmd.get<int>("ca"); //camera
use_comp = cmd.get<bool>("co"); //use_comp
frameToStop = cmd.get<int>("st"); //stopAt
imgref = cmd.get<std::string>("im"); //imgref
std::cout << "use_file: " << use_file << std::endl;
std::cout << "filename: " << filename << std::endl;
std::cout << "use_camera: " << use_camera << std::endl;
std::cout << "cameraIndex: " << cameraIndex << std::endl;
std::cout << "use_comp: " << use_comp << std::endl;
std::cout << "frameToStop: " << frameToStop << std::endl;
std::cout << "imgref: " << imgref << std::endl;
//return false;
if (use_file)
{
if (filename.empty())
{
std::cout << "Specify filename" << std::endl;
return false;
}
flag = true;
}
if (use_camera)
flag = true;
if (flag && use_comp)
{
if (imgref.empty())
{
std::cout << "Specify image reference" << std::endl;
return false;
}
}
return flag;
}
void VideoAnalysis::start()
{
//std::cout << "Press 'ESC' to stop..." << std::endl;
do
{
videoCapture = new VideoCapture;
frameProcessor = new FrameProcessor;
frameProcessor->init();
frameProcessor->frameToStop = frameToStop;
frameProcessor->imgref = imgref;
videoCapture->setFrameProcessor(frameProcessor);
if (use_file)
videoCapture->setVideo(filename);
if (use_camera)
videoCapture->setCamera(cameraIndex);
videoCapture->start();
if (use_file || use_camera)
break;
frameProcessor->finish();
int key = cvWaitKey(500);
if (key == KEY_ESC)
break;
delete frameProcessor;
delete videoCapture;
} while (1);
delete frameProcessor;
delete videoCapture;
}
}