-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVisualTracking.h
More file actions
executable file
·172 lines (137 loc) · 5.39 KB
/
VisualTracking.h
File metadata and controls
executable file
·172 lines (137 loc) · 5.39 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*----------------------------------------------------------------------------*/
/* Copyright (c) TechForKid 2014. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef VISUALTRACKING_H
#define VISUALTRACKING_H
#include "WPILib.h"
#include "t4kHSLImage.h"
#include "Config.h"
//Score limits used for target identification
#define RECTANGULARITY_LIMIT 40
#define ASPECT_RATIO_LIMIT 55
// extern AxisCamera& g_Camera;
class VisualTracking
{
public:
// Constructors
VisualTracking();
~VisualTracking();
// Instances
// Properties
//Structure to represent the scores for the various tests used for target identification
struct Scores
{
double rectangularity;
double aspectRatioVertical;
double aspectRatioHorizontal;
};
struct TargetReport
{
int verticalIndex;
int horizontalIndex;
bool Hot;
double totalScore;
double leftScore;
double rightScore;
double tapeWidthScore;
double verticalScore;
TargetReport()
{
verticalIndex = 0;
horizontalIndex = 0;
Hot = false;
totalScore = 0.0;
leftScore = 0.0;
rightScore = 0.0;
tapeWidthScore = 0.0;
verticalScore = 0.0;
}
};
enum TargetType
{
c_VisTarget_None = 0,
c_VisTarget_HotGoal = 1,
c_VisTarget_BlockedBall,
};
enum TargetType m_TargetToFind;
bool m_IsActive;
bool m_AccessCounter;
t4kHSLImage m_Image;
Threshold m_HSVThresholds; //HSV threshold criteria, ranges are in that order ie.
t4kBinaryImage m_ThresholdImage;
t4kBinaryImage m_FilteredImage;
//
// Methods
//
void processImage(bool& o_LeftTargetFound, bool& o_LeftTargetHot,
bool& o_RightTargetFound, bool& o_RightTargetHot);
/**
* Image processing code to identify 2013 Vision targets
*/
void ActivateTracking(bool iActive)
{
m_IsActive = iActive;
}
/**
* Image processing code to identify 2013 Vision targets
*/
void SelectTarget(enum TargetType iTarget)
{
m_TargetToFind = iTarget;
}
void FindTarget(bool& o_LeftTargetFound, bool& o_LeftTargetHot,
bool& o_RightTargetFound, bool& o_RightTargetHot);
/**
* Computes the estimated distance to a target using the height of the particle in the image. For more information and graphics
* showing the math behind this approach see the Vision Processing section of the ScreenStepsLive documentation.
*
* @param image The image to use for measuring the particle estimated rectangle
* @param report The Particle Analysis Report for the particle
* @return The estimated distance to the target in feet.
*/
double computeDistance (BinaryImage *image, ParticleAnalysisReport *report);
/**
* Computes a score (0-100) comparing the aspect ratio to the ideal aspect ratio for the target. This method uses
* the equivalent rectangle sides to determine aspect ratio as it performs better as the target gets skewed by moving
* to the left or right. The equivalent rectangle is the rectangle with sides x and y where particle area= x*y
* and particle perimeter= 2x+2y
*
* @param image The image containing the particle to score, needed to perform additional measurements
* @param report The Particle Analysis Report for the particle, used for the width, height, and particle number
* @param outer Indicates whether the particle aspect ratio should be compared to the ratio for the inner target or the outer
* @return The aspect ratio score (0-100)
*/
double scoreAspectRatio(t4kBinaryImage& iImage, ParticleAnalysisReport *report, bool vertical);
/**
* Compares scores to defined limits and returns true if the particle appears to be a target
*
* @param scores The structure containing the scores to compare
* @param vertical True if the particle should be treated as a vertical target, false to treat it as a horizontal target
*
* @return True if the particle meets all limits, false otherwise
*/
bool scoreCompare(Scores scores, bool vertical);
/**
* Computes a score (0-100) estimating how rectangular the particle is by comparing the area of the particle
* to the area of the bounding box surrounding it. A perfect rectangle would cover the entire bounding box.
*
* @param report The Particle Analysis Report for the particle to score
* @return The rectangularity score (0-100)
*/
double scoreRectangularity(ParticleAnalysisReport *report);
/**
* Converts a ratio with ideal value of 1 to a score. The resulting function is piecewise
* linear going from (0,0) to (1,100) to (2,0) and is 0 for all inputs outside the range 0-2
*/
double ratioToScore(double ratio);
/**
* Takes in a report on a target and compares the scores to the defined score limits to evaluate
* if the target is a hot target or not.
*
* Returns True if the target is hot. False if it is not.
*/
bool hotOrNot(TargetReport target);
};
#endif //VISUALTRACKING_H