forked from andrewssobral/bgslibrary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
VideoAnalysis.cpp
135 lines (107 loc) · 3.22 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
/*
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;
const char* keys =
"{hp|help|false|Print help 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}"
;
cv::CommandLineParser cmd(argc, argv, keys);
if (argc <= 1 || cmd.get<bool>("help") == true)
{
std::cout << "Usage: " << argv[0] << " [options]" << std::endl;
std::cout << "Avaible options:" << std::endl;
cmd.printParams();
return false;
}
use_file = cmd.get<bool>("use_file");
if (use_file)
{
filename = cmd.get<std::string>("filename");
if (filename.empty())
{
std::cout << "Specify filename" << std::endl;
return false;
}
flag = true;
}
use_camera = cmd.get<bool>("use_cam");
if (use_camera)
{
cameraIndex = cmd.get<int>("camera");
flag = true;
}
if (flag == true)
{
use_comp = cmd.get<bool>("use_comp");
if (use_comp)
{
frameToStop = cmd.get<int>("stopAt");
imgref = cmd.get<std::string>("imgref");
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;
}
}