Repository navigation
Expand file tree
/
Copy pathBlackScreenDetector.cpp
More file actions
129 lines (103 loc) · 3.52 KB
/
Copy pathBlackScreenDetector.cpp
File metadata and controls
129 lines (103 loc) · 3.52 KB
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
/* Black Border Detector
*
* From: https://github.com/PokemonAutomation/
*
*
* Returns true after a black screen has been detected and
* the black screen has ended.
*
*/
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
#include "CommonTools/Images/SolidColorTest.h"
#include "BlackScreenDetector.h"
//#include <iostream>
//using std::cout;
//using std::endl;
namespace PokemonAutomation{
BlackScreenDetector::BlackScreenDetector(
Color color, const ImageFloatBox& box,
double max_rgb_sum,
double max_stddev_sum
)
: m_color(color)
, m_box(box)
, m_max_rgb_sum(max_rgb_sum)
, m_max_stddev_sum(max_stddev_sum)
{}
void BlackScreenDetector::make_overlays(VideoOverlaySet& items) const{
items.add(m_color, m_box);
}
bool BlackScreenDetector::detect(const ImageViewRGB32& screen){
return is_black(extract_box_reference(screen, m_box), m_max_rgb_sum, m_max_stddev_sum);
}
WhiteScreenDetector::WhiteScreenDetector(
Color color, const ImageFloatBox& box,
double min_rgb_sum,
double max_stddev_sum
)
: m_color(color)
, m_box(box)
, m_min_rgb_sum(min_rgb_sum)
, m_max_stddev_sum(max_stddev_sum)
{}
void WhiteScreenDetector::make_overlays(VideoOverlaySet& items) const{
items.add(m_color, m_box);
}
bool WhiteScreenDetector::detect(const ImageViewRGB32& screen){
return is_white(extract_box_reference(screen, m_box), m_min_rgb_sum, m_max_stddev_sum);
}
BlackScreenOverWatcher::BlackScreenOverWatcher(
Color color, const ImageFloatBox& box,
double max_rgb_sum,
double max_stddev_sum,
std::chrono::milliseconds hold_duration,
std::chrono::milliseconds release_duration
)
: VisualInferenceCallback("BlackScreenOverWatcher")
, m_on(color, box, max_rgb_sum, max_stddev_sum, BlackScreenWatcher::FinderType::PRESENT, hold_duration)
, m_off(color, box, max_rgb_sum, max_stddev_sum, BlackScreenWatcher::FinderType::GONE, release_duration)
{}
void BlackScreenOverWatcher::make_overlays(VideoOverlaySet& items) const{
m_on.make_overlays(items);
}
bool BlackScreenOverWatcher::process_frame(const ImageViewRGB32& frame, WallClock timestamp){
if (m_black_is_over.load(std::memory_order_acquire)){
return true;
}
if (!m_has_been_black){
m_has_been_black = m_on.process_frame(frame, timestamp);
// cout << "m_has_been_black = " << m_has_been_black << endl;
return false;
}
bool is_over = m_off.process_frame(frame, timestamp);
if (!is_over){
return false;
}
m_black_is_over.store(true, std::memory_order_release);
return true;
}
bool BlackScreenOverWatcher::black_is_over(const ImageViewRGB32& frame){
return m_black_is_over.load(std::memory_order_acquire);
}
WhiteScreenOverWatcher::WhiteScreenOverWatcher(
Color color, const ImageFloatBox& box,
double min_rgb_sum,
double max_stddev_sum
)
: VisualInferenceCallback("BlackScreenOverWatcher")
, m_detector(color, box, min_rgb_sum, max_stddev_sum)
{}
void WhiteScreenOverWatcher::make_overlays(VideoOverlaySet& items) const{
m_detector.make_overlays(items);
}
bool WhiteScreenOverWatcher::process_frame(const ImageViewRGB32& frame, WallClock timestamp){
return white_is_over(frame);
}
bool WhiteScreenOverWatcher::white_is_over(const ImageViewRGB32& frame){
if (m_detector.detect(frame)){
m_has_been_white = true;
return false;
}
return m_has_been_white;
}
}