changing brisk detector parameter while in a concurency parallel_for (Bug #3292)
Description
Hi,
I am testing detectors with the concurency librarie in windows (ppl.h) to speed up things. I encountered a bug that seems only present with the brisk keypoint detector, when runing in parallel. sift, surf and orb seem to be ok. More precisely, a crash occurs if I run a loop in parallel (concurency::parallel_for), create a brisk detector in the loop and change its "thres" parameter. It doesnt happen if the parameter is not changed. Also, it doesnt happen if the loop is run sequentially.
The following code will generate the crash:
Concurrency::parallel_for(size_t(0), size_t(500), [&](size_t iPair)
//for(int iPair=0;iPair<500;iPair++)
{
std::vector<KeyPoint> kp;
Mat img = Mat::zeros(1000,1000,CV_8U);
img(Rect(500,500,20,20)) = 255; //black image with white square in the middle
Ptr<FeatureDetector> detector = FeatureDetector::create("BRISK");
detector->set("thres",6);
detector->detect(img,kp);
printf("\n %i",iPair);
});
//}
if you comment the set("thresh",6) line, it will not crash. Also, if you switch the comment to run the loop sequentially, it will not crash.
Thank you for your time, and keep up the good work !
Regards,
-jno
Related issues
related to Bug #2697: Algorithm set/info not threadsafe | Open | 2013-01-14 |
Associated revisions
Merge pull request #3292 from mshabunin:fix-ios-warnings
History
Updated by Vladislav Vinogradov over 11 years ago
Hello Jean-Nicolas Ouellet,
Thanks for your report.
This bug relates to algorithm initialization in multi-threaded enviroment.
You can fix the issue by creating algorithm instance before parallel loop to initialize parameters in single thread:
initModule_features2d(); // this will initialize internal Algorithm struct Ptr<FeatureDetector> dummy = FeatureDetector::create("BRISK"); dummy->set("thres", 6); Concurrency::parallel_for(size_t(0), size_t(500), [&](size_t iPair) { std::vector<KeyPoint> kp; Mat img = Mat::zeros(1000,1000,CV_8U); img(Rect(500,500,20,20)) = 255; //black image with white square in the middle Ptr<FeatureDetector> detector = FeatureDetector::create("BRISK"); detector->set("thres",6); detector->detect(img,kp); printf("\n %i",iPair); });
Updated by Vladislav Vinogradov over 11 years ago
I'm cancelling this bug, because it is a part of another bug : http://code.opencv.org/issues/2697
- Target version deleted (
2.4.7) - Assignee changed from Maria Dimashova to Vadim Pisarevsky
- Status changed from New to Cancelled