| 206 | } |
| 207 | |
| 208 | std::map<size_t,CamTrajectory> CVStabilization::SmoothTrajectory(std::vector <CamTrajectory> &trajectory){ |
| 209 | |
| 210 | std::map <size_t,CamTrajectory> smoothed_trajectory; // trajectory at all frames |
| 211 | |
| 212 | for(size_t i=0; i < trajectory.size(); i++) { |
| 213 | double sum_x = 0; |
| 214 | double sum_y = 0; |
| 215 | double sum_a = 0; |
| 216 | int count = 0; |
| 217 | |
| 218 | for(int j=-smoothingWindow; j <= smoothingWindow; j++) { |
| 219 | if(i+j < trajectory.size()) { |
| 220 | sum_x += trajectory[i+j].x; |
| 221 | sum_y += trajectory[i+j].y; |
| 222 | sum_a += trajectory[i+j].a; |
| 223 | |
| 224 | count++; |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | double avg_a = sum_a / count; |
| 229 | double avg_x = sum_x / count; |
| 230 | double avg_y = sum_y / count; |
| 231 | |
| 232 | // Add smoothed trajectory data to map |
| 233 | smoothed_trajectory[i + start] = CamTrajectory(avg_x, avg_y, avg_a); |
| 234 | } |
| 235 | return smoothed_trajectory; |
| 236 | } |
| 237 | |
| 238 | // Generate new transformations parameters for each frame to follow the smoothed trajectory |
| 239 | std::map<size_t,TransformParam> CVStabilization::GenNewCamPosition(std::map <size_t,CamTrajectory> &smoothed_trajectory){ |
nothing calls this directly
no test coverage detected