From 84a81579ba839c4224d3b1fba806e1d64a475597 Mon Sep 17 00:00:00 2001 From: Noah Stier Date: Wed, 27 Oct 2021 12:01:53 -0700 Subject: [PATCH] tvl1 cuda optflow optimization --- modules/cudaoptflow/src/tvl1flow.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/modules/cudaoptflow/src/tvl1flow.cpp b/modules/cudaoptflow/src/tvl1flow.cpp index 5f28d4c617..3ea2d365a6 100644 --- a/modules/cudaoptflow/src/tvl1flow.cpp +++ b/modules/cudaoptflow/src/tvl1flow.cpp @@ -162,7 +162,9 @@ namespace GpuMat p32_buf; GpuMat diff_buf; - GpuMat norm_buf; + + GpuMat diff_sum_dev; + Mat diff_sum_host; }; void OpticalFlowDual_TVL1_Impl::calc(InputArray _frame0, InputArray _frame1, InputOutputArray _flow, Stream& stream) @@ -361,8 +363,11 @@ namespace estimateU(I1wx, I1wy, grad, rho_c, p11, p12, p21, p22, p31, p32, u1, u2, u3, diff, l_t, static_cast(theta_), gamma_, calcError, stream); if (calcError) { + cuda::calcSum(diff, diff_sum_dev, cv::noArray(), _stream); + diff_sum_dev.download(diff_sum_host, _stream); _stream.waitForCompletion(); - error = cuda::sum(diff, norm_buf)[0]; + + error = diff_sum_host.at(0,0); prevError = error; } else