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

Function SolveForUpdate

cpp/5_Domain_Specific/HSOpticalFlow/flowGold.cpp:285–332  ·  view source on GitHub ↗

////////////////////////////////////////////////////////////////////////// \brief one iteration of classical Horn-Schunck method It is one iteration of Jacobi method for a corresponding linear system \param[in] du0 current horizontal displacement approximation \param[in] dv0 current vertical displacement approximation \param[in] Ix image x derivative \param[in] Iy image y de

Source from the content-addressed store, hash-verified

283/// \param[out] dv1 new vertical displacement approximation
284///////////////////////////////////////////////////////////////////////////////
285static void SolveForUpdate(const float *du0,
286 const float *dv0,
287 const float *Ix,
288 const float *Iy,
289 const float *Iz,
290 int w,
291 int h,
292 int s,
293 float alpha,
294 float *du1,
295 float *dv1)
296{
297 for (int i = 0; i < h; ++i) {
298 for (int j = 0; j < w; ++j) {
299 const int pos = j + i * s;
300 int left, right, up, down;
301
302 // handle borders
303 if (j != 0)
304 left = pos - 1;
305 else
306 left = pos;
307
308 if (j != w - 1)
309 right = pos + 1;
310 else
311 right = pos;
312
313 if (i != 0)
314 down = pos - s;
315 else
316 down = pos;
317
318 if (i != h - 1)
319 up = pos + s;
320 else
321 up = pos;
322
323 float sumU = (du0[left] + du0[right] + du0[up] + du0[down]) * 0.25f;
324 float sumV = (dv0[left] + dv0[right] + dv0[up] + dv0[down]) * 0.25f;
325
326 float frac = (Ix[pos] * sumU + Iy[pos] * sumV + Iz[pos]) / (Ix[pos] * Ix[pos] + Iy[pos] * Iy[pos] + alpha);
327
328 du1[pos] = sumU - Ix[pos] * frac;
329 dv1[pos] = sumV - Iy[pos] * frac;
330 }
331 }
332}
333
334///////////////////////////////////////////////////////////////////////////////
335/// \brief method logic

Callers 1

ComputeFlowGoldFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected