////////////////////////////////////////////////////////////////////////// \brief method logic handles memory allocation and control flow \param[in] I0 source image \param[in] I1 tracked image \param[in] width images width \param[in] height images height \param[in] stride images stride \param[in] alpha degree of displacement field smoothness \pa
| 348 | /// \param[out] v vertical displacement |
| 349 | /////////////////////////////////////////////////////////////////////////////// |
| 350 | void ComputeFlowGold(const float *I0, |
| 351 | const float *I1, |
| 352 | int width, |
| 353 | int height, |
| 354 | int stride, |
| 355 | float alpha, |
| 356 | int nLevels, |
| 357 | int nWarpIters, |
| 358 | int nSolverIters, |
| 359 | float *u, |
| 360 | float *v) |
| 361 | { |
| 362 | printf("Computing optical flow on CPU...\n"); |
| 363 | |
| 364 | float *u0 = u; |
| 365 | float *v0 = v; |
| 366 | |
| 367 | const float **pI0 = new const float *[nLevels]; |
| 368 | const float **pI1 = new const float *[nLevels]; |
| 369 | |
| 370 | int *pW = new int[nLevels]; |
| 371 | int *pH = new int[nLevels]; |
| 372 | int *pS = new int[nLevels]; |
| 373 | |
| 374 | const int pixelCountAligned = height * stride; |
| 375 | |
| 376 | float *tmp = new float[pixelCountAligned]; |
| 377 | float *du0 = new float[pixelCountAligned]; |
| 378 | float *dv0 = new float[pixelCountAligned]; |
| 379 | float *du1 = new float[pixelCountAligned]; |
| 380 | float *dv1 = new float[pixelCountAligned]; |
| 381 | float *Ix = new float[pixelCountAligned]; |
| 382 | float *Iy = new float[pixelCountAligned]; |
| 383 | float *Iz = new float[pixelCountAligned]; |
| 384 | float *nu = new float[pixelCountAligned]; |
| 385 | float *nv = new float[pixelCountAligned]; |
| 386 | |
| 387 | // prepare pyramid |
| 388 | int currentLevel = nLevels - 1; |
| 389 | pI0[currentLevel] = I0; |
| 390 | pI1[currentLevel] = I1; |
| 391 | |
| 392 | pW[currentLevel] = width; |
| 393 | pH[currentLevel] = height; |
| 394 | pS[currentLevel] = stride; |
| 395 | |
| 396 | for (; currentLevel > 0; --currentLevel) { |
| 397 | int nw = pW[currentLevel] / 2; |
| 398 | int nh = pH[currentLevel] / 2; |
| 399 | int ns = iAlignUp(nw); |
| 400 | pI0[currentLevel - 1] = new float[ns * nh]; |
| 401 | pI1[currentLevel - 1] = new float[ns * nh]; |
| 402 | |
| 403 | Downscale(pI0[currentLevel], |
| 404 | pW[currentLevel], |
| 405 | pH[currentLevel], |
| 406 | pS[currentLevel], |
| 407 | nw, |
no test coverage detected