-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDetector.cpp
107 lines (90 loc) · 1.93 KB
/
Detector.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
#include "Detector.h"
#include "DetectorThread.h"
Detector* Detector::_instance = NULL;
Detector* Detector::getInstance()
{
if(Detector::_instance == NULL)
{
Detector::_instance = new Detector();
}
return Detector::_instance;
}
Detector::Detector()
{
_mod = {0};
_region = {0};
_detect_region = false;
_thread = NULL;
init_mod(&_mod);
}
void Detector::detectDefault(Video *video)
{
_mod = {0};
_region = {0};
init_mod(&_mod);
_detect_region = false;
if (_thread != NULL)
{
delete _thread;
_thread = NULL;
}
_thread = new DetectorThread;
video->setCallback(Detector::detectionHandler, this);
_thread->setVideo(video);
_thread->start();
}
Period_Array* Detector::getPeriods()
{
if(_thread->isFinished())
{
return get_dynamic_period_array(&_mod);
}
return NULL;
}
void Detector::detectRegion(Video *video, Region region)
{
_mod = {0};
_region = region;
init_mod(&_mod);
_detect_region = true;
if (_thread != NULL)
{
delete _thread;
_thread = NULL;
}
_thread = new DetectorThread;
video->setCallback(Detector::detectionHandler, this);
_thread->setVideo(video);
_thread->start();
}
DetectorThread* Detector::getWorkingThread()
{
return _thread;
}
void Detector::stop()
{
if(_thread->isRunning())
{
_thread->terminate();
}
}
void Detector::detectionHandler(void* master, uint8_t *frame_y, uint8_t *frame_u, uint8_t *frame_v, uint32_t index, uint32_t width, uint32_t height)
{
Detector* detector = (Detector*)master;
if(detector->_detect_region)
{
detect_region(&(detector->_mod), frame_y, index, width, height, detector->_region);
}
else
{
detect(&(detector->_mod), frame_y, index, width, height);
}
}
Detector::~Detector()
{
if( _thread != NULL )
{
delete _thread;
}
release_mod(&_mod);
}