MCPcopy Create free account
hub / github.com/NVIDIA/cuda-samples / ComputeFlowGold

Function ComputeFlowGold

cpp/5_Domain_Specific/HSOpticalFlow/flowGold.cpp:350–523  ·  view source on GitHub ↗

////////////////////////////////////////////////////////////////////////// \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

Source from the content-addressed store, hash-verified

348/// \param[out] v vertical displacement
349///////////////////////////////////////////////////////////////////////////////
350void 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,

Callers 1

mainFunction · 0.85

Calls 7

DownscaleFunction · 0.85
WarpImageFunction · 0.85
ComputeDerivativesFunction · 0.85
SolveForUpdateFunction · 0.85
SwapFunction · 0.85
UpscaleFunction · 0.85
iAlignUpFunction · 0.70

Tested by

no test coverage detected