Ocean
Loading...
Searching...
No Matches
TransitionHistory.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#ifndef OCEAN_CV_DETECTOR_BULLSEYES_TRANSITION_HISTORY_H
9#define OCEAN_CV_DETECTOR_BULLSEYES_TRANSITION_HISTORY_H
10
12
13namespace Ocean
14{
15
16namespace CV
17{
18
19namespace Detector
20{
21
22namespace Bullseyes
23{
24
25/**
26 * This class implements a simple history for previous pixel transitions (a sliding window of pixel transitions) used for bullseye detection.
27 * The history tracks intensity differences (deltas) between adjacent pixels to identify transitions from black to white (or vice versa).
28 * The delta is computed as the signed difference between successive pixel intensities, with range [-255, 255].
29 * @ingroup cvdetectorbullseyes
30 */
31class OCEAN_CV_DETECTOR_BULLSEYES_EXPORT TransitionHistory
32{
33 public:
34
35 /**
36 * Creates a new history object.
37 */
38 TransitionHistory() = default;
39
40 /**
41 * Returns the history with window size 1.
42 * @return The previous intensity difference (delta) between adjacent pixels, with range [-255, 255]
43 */
44 int history1() const;
45
46 /**
47 * Returns the history with window size 2.
48 * @return The sum of the previous two intensity differences (deltas), with range [-510, 510]
49 */
50 int history2() const;
51
52 /**
53 * Returns the history with window size 3.
54 * @return The sum of the previous three intensity differences (deltas), with range [-765, 765]
55 */
56 int history3() const;
57
58 /**
59 * Adds a new intensity difference (delta) as the most recent history entry.
60 * Existing history entries will be shifted back by one position (deltaMinus1 becomes deltaMinus2, etc.).
61 * @param newDelta The new intensity difference to be added, with range [-255, 255]
62 */
63 void push(const int newDelta);
64
65 /**
66 * Resets the history object to its initial state (all deltas set to zero).
67 */
68 void reset();
69
70 /**
71 * Checks whether the given pixel is a transition-to-black pixel (whether the direct left neighbor is a bright pixel).
72 * @param pixel The pixel to be checked, must be valid
73 * @param history The history object containing information about previous pixels
74 * @param deltaThreshold The intensity difference threshold between successive pixels to count as a transition, with range [0, 255]
75 * @return True, if so
76 */
77 static bool isTransitionToBlack(const uint8_t* pixel, TransitionHistory& history, const int deltaThreshold = defaultDeltaThreshold());
78
79 /**
80 * Checks whether the given pixel is a transition-to-white pixel (whether the direct left neighbor is a dark pixel).
81 * @param pixel The pixel to be checked, must be valid
82 * @param history The history object containing information about previous pixels
83 * @param deltaThreshold The intensity difference threshold between successive pixels to count as a transition, with range [0, 255]
84 * @return True, if so
85 */
86 static bool isTransitionToWhite(const uint8_t* pixel, TransitionHistory& history, const int deltaThreshold = defaultDeltaThreshold());
87
88 /**
89 * Returns the default intensity threshold between two successive pixels to count as a transition from black to white (or vice versa).
90 * The delta (intensity difference) is computed as the absolute difference between adjacent pixel intensities.
91 * @return The default threshold value, with range [0, 255]
92 */
93 constexpr static int defaultDeltaThreshold();
94
95 protected:
96
97 /// The previous intensity difference (delta) between adjacent pixels, with range [-255, 255]
98 int deltaMinus1 = 0;
99
100 /// The second previous intensity difference (delta) between adjacent pixels, with range [-255, 255]
101 int deltaMinus2 = 0;
102
103 /// The third previous intensity difference (delta) between adjacent pixels, with range [-255, 255]
104 int deltaMinus3 = 0;
105};
106
108{
109 return 20;
110}
111
112} // namespace Bullseyes
113
114} // namespace Detector
115
116} // namespace CV
117
118} // namespace Ocean
119
120#endif // OCEAN_CV_DETECTOR_BULLSEYES_TRANSITION_HISTORY_H
This class implements a simple history for previous pixel transitions (a sliding window of pixel tran...
Definition TransitionHistory.h:32
static constexpr int defaultDeltaThreshold()
Returns the default intensity threshold between two successive pixels to count as a transition from b...
Definition TransitionHistory.h:107
static bool isTransitionToBlack(const uint8_t *pixel, TransitionHistory &history, const int deltaThreshold=defaultDeltaThreshold())
Checks whether the given pixel is a transition-to-black pixel (whether the direct left neighbor is a ...
int history1() const
Returns the history with window size 1.
int history2() const
Returns the history with window size 2.
static bool isTransitionToWhite(const uint8_t *pixel, TransitionHistory &history, const int deltaThreshold=defaultDeltaThreshold())
Checks whether the given pixel is a transition-to-white pixel (whether the direct left neighbor is a ...
void push(const int newDelta)
Adds a new intensity difference (delta) as the most recent history entry.
void reset()
Resets the history object to its initial state (all deltas set to zero).
int history3() const
Returns the history with window size 3.
TransitionHistory()=default
Creates a new history object.
std::vector< Bullseye > Bullseyes
Definition of a vector holding bullseyes.
Definition Bullseye.h:103
The namespace covering the entire Ocean framework.
Definition Accessor.h:15