@@ -405,10 +405,73 @@ CUDA_TEST_P(OpticalFlowDual_TVL1, Accuracy)
405
405
EXPECT_MAT_SIMILAR (flow, d_flow, 4e-3 );
406
406
}
407
407
408
+ class TVL1AsyncParallelLoopBody : public cv ::ParallelLoopBody
409
+ {
410
+ public:
411
+ TVL1AsyncParallelLoopBody (const cv::cuda::GpuMat& d_img1_, const cv::cuda::GpuMat& d_img2_, cv::cuda::GpuMat* d_flow_, int iterations_, double gamma_)
412
+ : d_img1(d_img1_), d_img2(d_img2_), d_flow(d_flow_), iterations(iterations_), gamma(gamma_) {}
413
+ ~TVL1AsyncParallelLoopBody () {}
414
+ void operator ()(const cv::Range& r) const
415
+ {
416
+ for (int i = r.start ; i < r.end ; i++) {
417
+ cv::cuda::Stream stream;
418
+ cv::Ptr <cv::cuda::OpticalFlowDual_TVL1> d_alg = cv::cuda::OpticalFlowDual_TVL1::create ();
419
+ d_alg->setNumIterations (iterations);
420
+ d_alg->setGamma (gamma );
421
+ d_alg->calc (d_img1, d_img2, d_flow[i], stream);
422
+ stream.waitForCompletion ();
423
+ }
424
+ }
425
+ protected:
426
+ const cv::cuda::GpuMat& d_img1;
427
+ const cv::cuda::GpuMat& d_img2;
428
+ cv::cuda::GpuMat* d_flow;
429
+ int iterations;
430
+ double gamma;
431
+ };
432
+
433
+ #define NUM_STREAMS 16
434
+
435
+ CUDA_TEST_P (OpticalFlowDual_TVL1, Async)
436
+ {
437
+ if (!supportFeature (devInfo, cv::cuda::FEATURE_SET_COMPUTE_30))
438
+ {
439
+ throw SkipTestException (" CUDA device doesn't support texture objects" );
440
+ }
441
+ else
442
+ {
443
+ cv::Mat frame0 = readImage (" opticalflow/rubberwhale1.png" , cv::IMREAD_GRAYSCALE);
444
+ ASSERT_FALSE (frame0.empty ());
445
+
446
+ cv::Mat frame1 = readImage (" opticalflow/rubberwhale2.png" , cv::IMREAD_GRAYSCALE);
447
+ ASSERT_FALSE (frame1.empty ());
448
+
449
+ const int iterations = 10 ;
450
+
451
+ // Synchronous call
452
+ cv::Ptr <cv::cuda::OpticalFlowDual_TVL1> d_alg =
453
+ cv::cuda::OpticalFlowDual_TVL1::create ();
454
+ d_alg->setNumIterations (iterations);
455
+ d_alg->setGamma (gamma );
456
+
457
+ cv::cuda::GpuMat d_flow_gold;
458
+ d_alg->calc (loadMat (frame0), loadMat (frame1), d_flow_gold);
459
+
460
+ // Asynchronous call
461
+ cv::cuda::GpuMat d_flow[NUM_STREAMS];
462
+ cv::parallel_for_ (cv::Range (0 , NUM_STREAMS), TVL1AsyncParallelLoopBody (loadMat (frame0), loadMat (frame1), d_flow, iterations, gamma ));
463
+
464
+ // Compare the results of synchronous call and asynchronous call
465
+ for (int i = 0 ; i < NUM_STREAMS; i++)
466
+ EXPECT_MAT_NEAR (d_flow_gold, d_flow[i], 0.0 );
467
+ }
468
+ }
469
+
408
470
INSTANTIATE_TEST_CASE_P (CUDA_OptFlow, OpticalFlowDual_TVL1, testing::Combine(
409
471
ALL_DEVICES,
410
472
testing::Values (Gamma(0.0 ), Gamma(1.0 ))));
411
473
474
+
412
475
// ////////////////////////////////////////////////////
413
476
// NvidiaOpticalFlow_1_0
414
477
0 commit comments