-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
100 lines (82 loc) · 2.83 KB
/
main.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
#include <fstream>
#include <optional>
#include <list>
#include <opencv2/highgui.hpp>
#include <opencv2/video/video.hpp>
#include <Hand.h>
#include <Timer.h>
#include <Debug.hpp>
#include <VideoSequenceCapture.h>
#include <HandDetector.hpp>
#include <GesturesRecognition.h>
using namespace std;
using namespace cv;
// Отрисовка всех найденных рук.
void printHands(InputArray image, const std::list<Hand>& hands)
{
Mat frame = image.getMat();
for (const auto& hand : hands)
{
hand.print(frame);
}
}
int main()
{
Timer total_timer, gestures_timer;
VideoCapture video(0);
//VideoSequenceCapture video("d:\\test_videos\\Input7\\0.png");
namedWindow("Input");
namedWindow("Background");
namedWindow("Motion");
namedWindow("Tracker");
// Пропускаем первые кадры, чтобы стабилизировалась
// яркость на изображениях, полученных с камеры.
Mat frame;
for (int i = 0; i < 20; i++)
{
video >> frame;
if (frame.empty()) continue;
imageShow("Input", frame);
waitKey(30);
}
Mat tracker_image(frame.size(), CV_8UC3);
HandDetector hand_detector(frame.rows, frame.cols);
GesturesRecognition gestures_recognition;
while (true)
{
// Получение входного изображения.
total_timer.start();
video >> frame;
if (frame.empty())
break;
imageShow("Input", frame);
hand_detector.detect(frame);
imageShow("Motion", hand_detector.getMotionImage());
auto hands = hand_detector.getHands();
gestures_timer.start();
gestures_recognition.apply(hands);
gestures_timer.stop();
frame.copyTo(tracker_image);
printHands(tracker_image, hands);
gestures_recognition.printClicks(tracker_image);
imageShow("Tracker", tracker_image);
total_timer.stop();
int c = waitKey(30);
if (c == 27)
break;
}
frame.release();
tracker_image.release();
destroyAllWindows();
// Записываем время работы программы.
ofstream time_log("Time.txt");
time_log << "Program time:" << endl;
time_log << "Total time: " << total_timer.getTime() << " sec." << endl;
time_log << "Correction of exposition: " << hand_detector.getExpositionTime() << " sec." << endl;
time_log << "Motion detection: " << hand_detector.getMotionTime() << " sec." << endl;
time_log << "Hand tracking: " << hand_detector.getTrackerTime() << " sec." << endl;
time_log << "Hand detection: " << hand_detector.getDetectorTime() << " sec." << endl;
time_log << "Gestures Recognition: " << gestures_timer.getTime() << " sec." << endl;
time_log.close();
return 0;
}