opencv_contrib
opencv_contrib copied to clipboard
CUDA SparsePyrLKOpticalFlow is not ThreadSafe ?
System information (version)
- OpenCV => 4.5.4
- OpenCV Contrib => Last Version
- Operating System / Platform => Windows 10 64 Bit
- Compiler => Visual Studio 2019
Detailed description
When I using cuda::SparsePyrLKOpticalFlow in multi thread application failed to calc optical flow properly. I run it on different cuda::GpuMats and in separate cuda::Streams with separate Algorithm instances. I find similar problem in other cuda functions that are not thread safe. https://github.com/opencv/opencv/issues/18051 Is cuda::SparsePyrLKOpticalFlow thread safe ?
Steps to reproduce
I call bellow code in different thread simultaneously
mSparseLK->calc(GpuPervFrame, GpuFrame, gOldFeaturePoints, gNewFeaturePoints, gStatus, gErrors, mStream);
Algorithm instance is not thread safe by default (due to efficiency). Different threads must use different instances. (exceptions are containers like cv::Mat/UMat/etc)
Usage questions should go to Users OpenCV Q/A forum: https://forum.opencv.org/
Convert pixel format from CV_8U to CV_16U fix the problem even without use cv::Stream
https://forum.opencv.org/t/how-to-use-cuda-sparsepyrlkopticalflow-in-multi-thread-environment/9632/9