-
Notifications
You must be signed in to change notification settings - Fork 82
Expand file tree
/
Copy pathtest_features.h
More file actions
139 lines (113 loc) · 3.71 KB
/
test_features.h
File metadata and controls
139 lines (113 loc) · 3.71 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
// This file is part of KWIVER, and is distributed under the
// OSI-approved BSD 3-Clause License. See top-level LICENSE file or
// https://github.com/Kitware/kwiver/blob/master/LICENSE for details.
/**
* \file
*
* \brief Functions to create a set of features with attributes
* for testing the filter_features implementations
*
* These functions are shared by various tests
*/
#ifndef KWIVER_TEST_TEST_FEATURES_H_
#define KWIVER_TEST_TEST_FEATURES_H_
#include <random>
#include <vital/types/feature.h>
#include <vital/types/feature_set.h>
using namespace kwiver::vital;
namespace kwiver {
namespace testing {
// Generate a set of generic features
// Function spreads feature values evenly over the number of features
// see <vital/types/feature.h> for parameter descriptions
template < typename T >
feature_set_sptr
make_n_features( size_t num_feat )
{
std::vector< feature_sptr > feat;
for( unsigned i = 0; i < num_feat; ++i )
{
T v = static_cast< T >( i ) / num_feat;
auto f = std::make_shared< feature_< T > >();
T x = v * 5000, y = v * 5000 + 5;
f->set_loc( Eigen::Matrix< T, 2, 1 >( x, y ) );
f->set_scale( 1.0 + v );
f->set_magnitude( 1 - v );
f->set_angle( v * 3.14159f );
f->set_color(
rgb_color(
static_cast< uint8_t >( i ),
static_cast< uint8_t >( i + 5 ),
static_cast< uint8_t >( i + 10 ) ) );
f->set_covar( covariance_< 2, T >( v ) );
feat.push_back( f );
}
return std::make_shared< simple_feature_set >( feat );
}
// Create a set of 10 features with known (unordered )
// scale and magnitude values for unit testing
template < typename T >
feature_set_sptr
make_10_features()
{
unsigned num_feat = 10;
std::vector< double > scale = {
1.0, 2.0, 1.8, 1.2, 1.1, 1.3, 1.7, 1.2, 1.1, 1.1 };
std::vector< double > mag = {
0.7, 0.1, 0.1, 0.2, 0.3, 0.5, 0.8, 0.5, 0.9, 0.1 };
std::vector< feature_sptr > feat;
for( unsigned i = 0; i < num_feat; ++i )
{
T v = static_cast< T >( i ) / num_feat;
auto f = std::make_shared< feature_< T > >();
T x = v * 1000, y = v * 1000 + 5;
f->set_loc( Eigen::Matrix< T, 2, 1 >( x, y ) );
f->set_scale( scale[ i ] );
f->set_magnitude( mag[ i ] );
f->set_angle( v * 3.14159f );
f->set_color(
rgb_color(
static_cast< uint8_t >( i ),
static_cast< uint8_t >( i + 5 ),
static_cast< uint8_t >( i + 10 ) ) );
f->set_covar( covariance_< 2, T >( v ) );
feat.push_back( f );
}
return std::make_shared< simple_feature_set >( feat );
}
// Create a set of 10 features with known (unordered )
// scale and magnitude values for unit testing
// set the locations for nonmax filtering
template < typename T >
feature_set_sptr
make_12_features()
{
unsigned num_feat = 12;
std::vector< double > scale = {
1.0, 1.0, 2.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 4.0, 1.0 };
std::vector< double > mag = {
0.5, 1.0, 1.0, 0.5, 1.0, 0.2, 1.0, 0.2, 1.0, 1.0, 1.0, 1.0 };
std::vector< unsigned > coord = {
100, 110, 300, 310, 320, 505, 510, 515, 700, 710, 720, 800 };
std::vector< feature_sptr > feat;
for( unsigned i = 0; i < num_feat; ++i )
{
T v = static_cast< T >( i ) / num_feat;
auto f = std::make_shared< feature_< T > >();
f->set_loc( Eigen::Matrix< T, 2, 1 >( coord[ i ], coord[ i ] ) );
f->set_scale( scale[ i ] );
f->set_magnitude( mag[ i ] );
f->set_angle( v * 3.14159f );
f->set_color(
rgb_color(
static_cast< uint8_t >( i ),
static_cast< uint8_t >( i + 5 ),
static_cast< uint8_t >( i + 10 ) ) );
f->set_covar( covariance_< 2, T >( v ) );
feat.push_back( f );
}
return std::make_shared< simple_feature_set >( feat );
}
} // end namespace testing
} // end namespace kwiver
#endif