24
24
Eigen::Vector3d utiles_direction (double x, double y, int width, int height){
25
25
26
26
// Convert pixel coordinates to geographic mapping coordinates
27
- double lamda ( (x/width) * 2 .* M_PI );
28
- double phi ( ((y/(height-1 )) - 0.5 ) * M_PI );
27
+ double lamda ((x/width)*2 .*M_PI);
28
+ double phi (((y/(height-1 ))-0.5 )*M_PI);
29
+
30
+ // Precompute cosine value
31
+ double cosine (cos (phi));
29
32
30
33
// Compute and return direction vector
31
- return Eigen::Vector3d (cos (phi) *cos (lamda), cos (phi) *sin (lamda), sin (phi));
34
+ return Eigen::Vector3d (cosine *cos (lamda),cosine *sin (lamda),sin (phi));
32
35
33
36
}
34
37
@@ -51,24 +54,25 @@ void profile(std::string msg){
51
54
msgLast = msg;
52
55
}
53
56
57
+ /* delete */
54
58
std::mutex exitMutex;
55
59
int exitCounter = 0 ;
56
60
61
+ /* delete */
57
62
void exitRetain (){
58
63
exitMutex.lock ();
59
64
exitCounter++;
60
65
exitMutex.unlock ();
61
66
}
62
67
63
-
68
+ /* delete */
64
69
void exitRelease (){
65
70
exitMutex.lock ();
66
71
exitCounter--;
67
72
if (exitCounter <= 0 ) exit (0 );
68
73
exitMutex.unlock ();
69
74
}
70
75
71
-
72
76
double bilinear_sample (double *p, double x, double y, int width){
73
77
int ix = x;
74
78
int iy = y;
@@ -122,3 +126,52 @@ void utiles_directories( std::string rootPath, std::string modeName ) {
122
126
123
127
}
124
128
129
+ double utilesDetectMotion (std::vector<cv::KeyPoint> *kp1, std::vector<cv::KeyPoint> *kp2, std::vector<cv::DMatch> *matches, cv::Size size) {
130
+
131
+ // Vector containing the distances for each pair of features
132
+ std::vector<double > vec_dist {};
133
+
134
+ // loop over the vector of matches
135
+ for (const auto &m : *matches) {
136
+
137
+ auto width = size.width ;
138
+ auto height = size.height ;
139
+
140
+ // m.queryIdx is the index of the Keypoints on the first image
141
+ // m.trainIdx is the index of the Keypoints on the second image
142
+
143
+ // Convert cartesian to spherical
144
+ // Spherical coordinate of the feature on the first image
145
+ Eigen::Vector3d p1 = utiles_direction (static_cast <double >((*kp1)[m.queryIdx ].pt .x ), static_cast <double >((*kp1)[m.queryIdx ].pt .y ), width, height);
146
+ // Spherical coordinate of the feature on the second image
147
+ Eigen::Vector3d p2 = utiles_direction (static_cast <double >((*kp2)[m.trainIdx ].pt .x ), static_cast <double >((*kp2)[m.trainIdx ].pt .y ), width, height);
148
+
149
+ // p1*p2 computes the dot product between p1 and p2
150
+ // push it to vector of distances
151
+ vec_dist.push_back (acos (p1.dot (p2)));
152
+
153
+ }
154
+
155
+ // calculation of the mean value
156
+ double m { std::accumulate (vec_dist.begin (), vec_dist.end (), 0.0 ) / vec_dist.size () };
157
+
158
+ // calculation of variance
159
+ double var { 0.0 };
160
+ for (const auto & val : vec_dist) {
161
+ var += pow (val - m, 2 );
162
+ }
163
+
164
+ // check error to avoid division by 0
165
+ if (vec_dist.size () <= 1 ) {
166
+ throw (std::runtime_error (" Number of features is less or equal to 1" ));
167
+ }
168
+ var /= (vec_dist.size () - 1 );
169
+
170
+ // calculation of std
171
+ double vec_std = sqrt (var);
172
+
173
+ // return mean * std
174
+ return m * vec_std;
175
+
176
+ }
177
+
0 commit comments