Commit b8de57f8 authored by Alexander Alekhin's avatar Alexander Alekhin

cleanup unnecessary setNumThreads() calls

parent c49d781e
...@@ -37,9 +37,6 @@ static Ptr<BackgroundSubtractor> createBGSubtractorByName(const String& algoName ...@@ -37,9 +37,6 @@ static Ptr<BackgroundSubtractor> createBGSubtractorByName(const String& algoName
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
setUseOptimized(true);
setNumThreads(8);
CommandLineParser parser(argc, argv, keys); CommandLineParser parser(argc, argv, keys);
parser.about(about); parser.about(about);
parser.printMessage(); parser.printMessage();
......
...@@ -20,7 +20,6 @@ PERF_TEST_P(DenseOpticalFlow_DeepFlow, perf, Values(szVGA, sz720p)) ...@@ -20,7 +20,6 @@ PERF_TEST_P(DenseOpticalFlow_DeepFlow, perf, Values(szVGA, sz720p))
randu(frame1, 0, 255); randu(frame1, 0, 255);
randu(frame2, 0, 255); randu(frame2, 0, 255);
cv::setNumThreads(cv::getNumberOfCPUs());
TEST_CYCLE_N(1) TEST_CYCLE_N(1)
{ {
Ptr<DenseOpticalFlow> algo = createOptFlow_DeepFlow(); Ptr<DenseOpticalFlow> algo = createOptFlow_DeepFlow();
......
...@@ -32,7 +32,6 @@ PERF_TEST_P(DenseOpticalFlow_DIS, perf, ...@@ -32,7 +32,6 @@ PERF_TEST_P(DenseOpticalFlow_DIS, perf,
MakeArtificialExample(frame1, frame2); MakeArtificialExample(frame1, frame2);
cv::setNumThreads(cv::getNumberOfCPUs());
TEST_CYCLE_N(10) TEST_CYCLE_N(10)
{ {
Ptr<DenseOpticalFlow> algo = createOptFlow_DIS(preset); Ptr<DenseOpticalFlow> algo = createOptFlow_DIS(preset);
......
...@@ -23,7 +23,6 @@ PERF_TEST_P(DenseOpticalFlow_VariationalRefinement, perf, Combine(Values(szQVGA, ...@@ -23,7 +23,6 @@ PERF_TEST_P(DenseOpticalFlow_VariationalRefinement, perf, Combine(Values(szQVGA,
randu(frame2, 0, 255); randu(frame2, 0, 255);
flow.setTo(0.0f); flow.setTo(0.0f);
cv::setNumThreads(cv::getNumberOfCPUs());
TEST_CYCLE_N(10) TEST_CYCLE_N(10)
{ {
Ptr<VariationalRefinement> var = createVariationalFlowRefinement(); Ptr<VariationalRefinement> var = createVariationalFlowRefinement();
......
...@@ -57,6 +57,9 @@ TEST_P(DenseOpticalFlow_DIS, MultithreadReproducibility) ...@@ -57,6 +57,9 @@ TEST_P(DenseOpticalFlow_DIS, MultithreadReproducibility)
OFParams params = GetParam(); OFParams params = GetParam();
Size size = get<0>(params); Size size = get<0>(params);
int nThreads = cv::getNumThreads();
if (nThreads == 1)
throw SkipTestException("Single thread environment");
for (int iter = 0; iter <= loopsCount; iter++) for (int iter = 0; iter <= loopsCount; iter++)
{ {
Mat frame1(size, CV_8U); Mat frame1(size, CV_8U);
...@@ -79,7 +82,7 @@ TEST_P(DenseOpticalFlow_DIS, MultithreadReproducibility) ...@@ -79,7 +82,7 @@ TEST_P(DenseOpticalFlow_DIS, MultithreadReproducibility)
algo->setUseMeanNormalization(use_mean_normalization); algo->setUseMeanNormalization(use_mean_normalization);
algo->setUseSpatialPropagation(use_spatial_propagation); algo->setUseSpatialPropagation(use_spatial_propagation);
cv::setNumThreads(cv::getNumberOfCPUs()); cv::setNumThreads(nThreads);
Mat resMultiThread; Mat resMultiThread;
algo->calc(frame1, frame2, resMultiThread); algo->calc(frame1, frame2, resMultiThread);
...@@ -111,6 +114,9 @@ TEST_P(DenseOpticalFlow_VariationalRefinement, MultithreadReproducibility) ...@@ -111,6 +114,9 @@ TEST_P(DenseOpticalFlow_VariationalRefinement, MultithreadReproducibility)
OFParams params = GetParam(); OFParams params = GetParam();
Size size = get<0>(params); Size size = get<0>(params);
int nThreads = cv::getNumThreads();
if (nThreads == 1)
throw SkipTestException("Single thread environment");
for (int iter = 0; iter <= loopsCount; iter++) for (int iter = 0; iter <= loopsCount; iter++)
{ {
Mat frame1(size, CV_8U); Mat frame1(size, CV_8U);
...@@ -128,7 +134,7 @@ TEST_P(DenseOpticalFlow_VariationalRefinement, MultithreadReproducibility) ...@@ -128,7 +134,7 @@ TEST_P(DenseOpticalFlow_VariationalRefinement, MultithreadReproducibility)
var->setFixedPointIterations(rng.uniform(1, 20)); var->setFixedPointIterations(rng.uniform(1, 20));
var->setOmega(rng.uniform(1.01f, 1.99f)); var->setOmega(rng.uniform(1.01f, 1.99f));
cv::setNumThreads(cv::getNumberOfCPUs()); cv::setNumThreads(nThreads);
Mat resMultiThread; Mat resMultiThread;
flow.copyTo(resMultiThread); flow.copyTo(resMultiThread);
var->calc(frame1, frame2, resMultiThread); var->calc(frame1, frame2, resMultiThread);
......
...@@ -506,8 +506,6 @@ bool TrackerCSRTImpl::updateImpl(const Mat& image_, Rect2d& boundingBox) ...@@ -506,8 +506,6 @@ bool TrackerCSRTImpl::updateImpl(const Mat& image_, Rect2d& boundingBox)
// ********************************************************************* // *********************************************************************
bool TrackerCSRTImpl::initImpl(const Mat& image_, const Rect2d& boundingBox) bool TrackerCSRTImpl::initImpl(const Mat& image_, const Rect2d& boundingBox)
{ {
cv::setNumThreads(getNumThreads());
//treat gray image as color image //treat gray image as color image
Mat image; Mat image;
if(image_.channels() == 1) { if(image_.channels() == 1) {
......
...@@ -29,9 +29,7 @@ PERF_TEST_P( AdaptiveManifoldPerfTest, perf, ...@@ -29,9 +29,7 @@ PERF_TEST_P( AdaptiveManifoldPerfTest, perf,
Mat src(sz, CV_MAKE_TYPE(depth, srcCnNum)); Mat src(sz, CV_MAKE_TYPE(depth, srcCnNum));
Mat dst(sz, CV_MAKE_TYPE(depth, srcCnNum)); Mat dst(sz, CV_MAKE_TYPE(depth, srcCnNum));
cv::setNumThreads(cv::getNumberOfCPUs()); declare.in(joint, src, WARMUP_RNG).out(dst);
declare.in(joint, src, WARMUP_RNG).out(dst).tbb_threads(cv::getNumberOfCPUs());
double sigma_s = 16; double sigma_s = 16;
double sigma_r = 0.5; double sigma_r = 0.5;
......
...@@ -29,8 +29,7 @@ PERF_TEST_P(BilateralTextureFilterTest, perf, ...@@ -29,8 +29,7 @@ PERF_TEST_P(BilateralTextureFilterTest, perf,
Mat src(sz, CV_MAKE_TYPE(depth,srcCn)); Mat src(sz, CV_MAKE_TYPE(depth,srcCn));
Mat dst(sz, src.type()); Mat dst(sz, src.type());
cv::setNumThreads(cv::getNumberOfCPUs()); declare.in(src, WARMUP_RNG).out(dst);
declare.in(src, WARMUP_RNG).out(dst).tbb_threads(cv::getNumberOfCPUs());
TEST_CYCLE_N(1) TEST_CYCLE_N(1)
{ {
......
...@@ -41,7 +41,6 @@ PERF_TEST_P( DisparityWLSFilterPerfTest, perf, Combine(GuideTypes::all(), SrcTyp ...@@ -41,7 +41,6 @@ PERF_TEST_P( DisparityWLSFilterPerfTest, perf, Combine(GuideTypes::all(), SrcTyp
ROI = Rect(ROI.x/2,ROI.y/2,ROI.width/2,ROI.height/2); ROI = Rect(ROI.x/2,ROI.y/2,ROI.width/2,ROI.height/2);
} }
cv::setNumThreads(cv::getNumberOfCPUs());
TEST_CYCLE_N(10) TEST_CYCLE_N(10)
{ {
Ptr<DisparityWLSFilter> wls_filter = createDisparityWLSFilterGeneric(use_conf); Ptr<DisparityWLSFilter> wls_filter = createDisparityWLSFilterGeneric(use_conf);
......
...@@ -34,9 +34,8 @@ PERF_TEST_P( DomainTransformTest, perf, ...@@ -34,9 +34,8 @@ PERF_TEST_P( DomainTransformTest, perf,
Mat src(size, srcType); Mat src(size, srcType);
Mat dst(size, srcType); Mat dst(size, srcType);
declare.in(guide, src, WARMUP_RNG).out(dst).tbb_threads(cv::getNumberOfCPUs()); declare.in(guide, src, WARMUP_RNG).out(dst);
cv::setNumThreads(cv::getNumberOfCPUs());
TEST_CYCLE_N(5) TEST_CYCLE_N(5)
{ {
dtFilter(guide, src, dst, sigmaSpatial, sigmaColor, dtfType); dtFilter(guide, src, dst, sigmaSpatial, sigmaColor, dtfType);
......
...@@ -24,9 +24,8 @@ PERF_TEST_P( FGSFilterPerfTest, perf, Combine(GuideTypes::all(), SrcTypes::all() ...@@ -24,9 +24,8 @@ PERF_TEST_P( FGSFilterPerfTest, perf, Combine(GuideTypes::all(), SrcTypes::all()
Mat src(sz, srcType); Mat src(sz, srcType);
Mat dst(sz, srcType); Mat dst(sz, srcType);
declare.in(guide, src, WARMUP_RNG).out(dst).tbb_threads(cv::getNumberOfCPUs()); declare.in(guide, src, WARMUP_RNG).out(dst);
cv::setNumThreads(cv::getNumberOfCPUs());
TEST_CYCLE_N(10) TEST_CYCLE_N(10)
{ {
double lambda = rng.uniform(500.0, 10000.0); double lambda = rng.uniform(500.0, 10000.0);
......
...@@ -24,9 +24,8 @@ PERF_TEST_P( GuidedFilterPerfTest, perf, Combine(GuideTypes::all(), SrcTypes::al ...@@ -24,9 +24,8 @@ PERF_TEST_P( GuidedFilterPerfTest, perf, Combine(GuideTypes::all(), SrcTypes::al
Mat src(sz, srcType); Mat src(sz, srcType);
Mat dst(sz, srcType); Mat dst(sz, srcType);
declare.in(guide, src, WARMUP_RNG).out(dst).tbb_threads(cv::getNumberOfCPUs()); declare.in(guide, src, WARMUP_RNG).out(dst);
cv::setNumThreads(cv::getNumberOfCPUs());
TEST_CYCLE_N(3) TEST_CYCLE_N(3)
{ {
int radius = rng.uniform(5, 30); int radius = rng.uniform(5, 30);
......
...@@ -23,8 +23,7 @@ PERF_TEST_P(L0SmoothTest, perf, ...@@ -23,8 +23,7 @@ PERF_TEST_P(L0SmoothTest, perf,
Mat src(sz, CV_MAKE_TYPE(depth, srcCn)); Mat src(sz, CV_MAKE_TYPE(depth, srcCn));
Mat dst(sz, src.type()); Mat dst(sz, src.type());
cv::setNumThreads(cv::getNumberOfCPUs()); declare.in(src, WARMUP_RNG).out(dst);
declare.in(src, WARMUP_RNG).out(dst).tbb_threads(cv::getNumberOfCPUs());
RNG rnd(sz.height + depth + srcCn); RNG rnd(sz.height + depth + srcCn);
double lambda = rnd.uniform(0.01, 0.05); double lambda = rnd.uniform(0.01, 0.05);
......
...@@ -25,8 +25,7 @@ PERF_TEST_P(RollingGuidanceFilterTest, perf, ...@@ -25,8 +25,7 @@ PERF_TEST_P(RollingGuidanceFilterTest, perf,
Mat src(sz, CV_MAKE_TYPE(depth, srcCn)); Mat src(sz, CV_MAKE_TYPE(depth, srcCn));
Mat dst(sz, src.type()); Mat dst(sz, src.type());
cv::setNumThreads(cv::getNumberOfCPUs()); declare.in(src, WARMUP_RNG).out(dst);
declare.in(src, WARMUP_RNG).out(dst).tbb_threads(cv::getNumberOfCPUs());
RNG rnd(cvRound(10*sigmaS) + sz.height + depth + srcCn); RNG rnd(cvRound(10*sigmaS) + sz.height + depth + srcCn);
double sigmaC = rnd.uniform(1.0, 255.0); double sigmaC = rnd.uniform(1.0, 255.0);
......
...@@ -34,8 +34,7 @@ PERF_TEST_P(WeightedMedianFilterTest, perf, ...@@ -34,8 +34,7 @@ PERF_TEST_P(WeightedMedianFilterTest, perf,
Mat src(sz, CV_MAKE_TYPE(srcDepth, srcCn)); Mat src(sz, CV_MAKE_TYPE(srcDepth, srcCn));
Mat dst(sz, src.type()); Mat dst(sz, src.type());
cv::setNumThreads(cv::getNumberOfCPUs()); declare.in(joint, src, WARMUP_RNG).out(dst);
declare.in(joint, src, WARMUP_RNG).out(dst).tbb_threads(cv::getNumberOfCPUs());
TEST_CYCLE_N(1) TEST_CYCLE_N(1)
{ {
......
...@@ -29,8 +29,7 @@ PERF_TEST_P(JointBilateralFilterTest, perf, ...@@ -29,8 +29,7 @@ PERF_TEST_P(JointBilateralFilterTest, perf,
Mat src(sz, CV_MAKE_TYPE(depth, srcCn)); Mat src(sz, CV_MAKE_TYPE(depth, srcCn));
Mat dst(sz, src.type()); Mat dst(sz, src.type());
cv::setNumThreads(cv::getNumberOfCPUs()); declare.in(joint, src, WARMUP_RNG).out(dst);
declare.in(joint, src, WARMUP_RNG).out(dst).tbb_threads(cv::getNumberOfCPUs());
RNG rnd(cvRound(10*sigmaS) + sz.height + depth + jCn + srcCn); RNG rnd(cvRound(10*sigmaS) + sz.height + depth + jCn + srcCn);
double sigmaC = rnd.uniform(1.0, 255.0); double sigmaC = rnd.uniform(1.0, 255.0);
......
...@@ -91,9 +91,6 @@ int main(int argc, char** argv) { ...@@ -91,9 +91,6 @@ int main(int argc, char** argv) {
return -1; return -1;
} }
setUseOptimized(true);
setNumThreads(8);
Ptr<GraphSegmentation> gs = createGraphSegmentation(); Ptr<GraphSegmentation> gs = createGraphSegmentation();
if (argc > 3) if (argc > 3)
......
...@@ -158,7 +158,6 @@ void changeModeCallback(int state, void *filter) ...@@ -158,7 +158,6 @@ void changeModeCallback(int state, void *filter)
void changeNumberOfCpuCallback(int count, void*) void changeNumberOfCpuCallback(int count, void*)
{ {
count = std::max(1, count); count = std::max(1, count);
cv::setNumThreads(count);
g_numberOfCPUs = count; g_numberOfCPUs = count;
} }
...@@ -188,7 +187,6 @@ int main() ...@@ -188,7 +187,6 @@ int main()
displayOverlay("Demo", "Press Ctrl+P to show property window", 5000); displayOverlay("Demo", "Press Ctrl+P to show property window", 5000);
//Thread trackbar //Thread trackbar
cv::setNumThreads(g_numberOfCPUs); //speedup filtering
createTrackbar("Threads", String(), &g_numberOfCPUs, cv::getNumberOfCPUs(), changeNumberOfCpuCallback); createTrackbar("Threads", String(), &g_numberOfCPUs, cv::getNumberOfCPUs(), changeNumberOfCpuCallback);
//Buttons to choose different modes //Buttons to choose different modes
...@@ -219,6 +217,8 @@ int main() ...@@ -219,6 +217,8 @@ int main()
cap >> rawFrame; cap >> rawFrame;
} while (rawFrame.empty()); } while (rawFrame.empty());
cv::setNumThreads(g_numberOfCPUs); //speedup filtering
splitScreen(rawFrame, outputFrame, srcFrame, processedFrame); splitScreen(rawFrame, outputFrame, srcFrame, processedFrame);
g_filterOp(srcFrame, processedFrame); g_filterOp(srcFrame, processedFrame);
......
...@@ -59,11 +59,6 @@ int main(int argc, char** argv) { ...@@ -59,11 +59,6 @@ int main(int argc, char** argv) {
return -1; return -1;
} }
setUseOptimized(true);
setNumThreads(8);
std::srand((int)std::time(0));
Mat img = imread(argv[1]); Mat img = imread(argv[1]);
Ptr<SelectiveSearchSegmentation> gs = createSelectiveSearchSegmentation(); Ptr<SelectiveSearchSegmentation> gs = createSelectiveSearchSegmentation();
......
...@@ -29,8 +29,6 @@ TEST(AdaptiveManifoldTest, SplatSurfaceAccuracy) ...@@ -29,8 +29,6 @@ TEST(AdaptiveManifoldTest, SplatSurfaceAccuracy)
{ {
RNG rnd(0); RNG rnd(0);
cv::setNumThreads(cv::getNumberOfCPUs());
for (int i = 0; i < 5; i++) for (int i = 0; i < 5; i++)
{ {
Size sz(rnd.uniform(512, 1024), rnd.uniform(512, 1024)); Size sz(rnd.uniform(512, 1024), rnd.uniform(512, 1024));
...@@ -90,8 +88,6 @@ TEST(AdaptiveManifoldTest, AuthorsReferenceAccuracy) ...@@ -90,8 +88,6 @@ TEST(AdaptiveManifoldTest, AuthorsReferenceAccuracy)
Mat srcImg = imread(getOpenCVExtraDir() + srcImgPath); Mat srcImg = imread(getOpenCVExtraDir() + srcImgPath);
ASSERT_TRUE(!srcImg.empty()); ASSERT_TRUE(!srcImg.empty());
cv::setNumThreads(cv::getNumberOfCPUs());
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
{ {
Mat refRes = imread(getOpenCVExtraDir() + refPaths[i]); Mat refRes = imread(getOpenCVExtraDir() + refPaths[i]);
...@@ -148,13 +144,16 @@ TEST_P(AdaptiveManifoldRefImplTest, RefImplAccuracy) ...@@ -148,13 +144,16 @@ TEST_P(AdaptiveManifoldRefImplTest, RefImplAccuracy)
resize(guide, guide, dstSize, 0, 0, INTER_LINEAR_EXACT); resize(guide, guide, dstSize, 0, 0, INTER_LINEAR_EXACT);
resize(src, src, dstSize, 0, 0, INTER_LINEAR_EXACT); resize(src, src, dstSize, 0, 0, INTER_LINEAR_EXACT);
int nThreads = cv::getNumThreads();
if (nThreads == 1)
throw SkipTestException("Single thread environment");
for (int iter = 0; iter < 4; iter++) for (int iter = 0; iter < 4; iter++)
{ {
double sigma_s = rnd.uniform(1.0, 50.0); double sigma_s = rnd.uniform(1.0, 50.0);
double sigma_r = rnd.uniform(0.1, 0.9); double sigma_r = rnd.uniform(0.1, 0.9);
bool adjust_outliers = (iter % 2 == 0); bool adjust_outliers = (iter % 2 == 0);
cv::setNumThreads(cv::getNumberOfCPUs()); cv::setNumThreads(nThreads);
Mat res; Mat res;
amFilter(guide, src, res, sigma_s, sigma_r, adjust_outliers); amFilter(guide, src, res, sigma_s, sigma_r, adjust_outliers);
......
...@@ -66,9 +66,12 @@ TEST_P(BilateralTextureFilterTest, MultiThreadReproducibility) ...@@ -66,9 +66,12 @@ TEST_P(BilateralTextureFilterTest, MultiThreadReproducibility)
else else
randu(src, 0.0f, 1.0f); randu(src, 0.0f, 1.0f);
int nThreads = cv::getNumThreads();
if (nThreads == 1)
throw SkipTestException("Single thread environment");
for (int iter = 0; iter <= loopsCount; iter++) for (int iter = 0; iter <= loopsCount; iter++)
{ {
cv::setNumThreads(cv::getNumberOfCPUs()); cv::setNumThreads(nThreads);
Mat resMultiThread; Mat resMultiThread;
bilateralTextureFilter(src, resMultiThread, fr, 1, sigmaAlpha, sigmaAvg); bilateralTextureFilter(src, resMultiThread, fr, 1, sigmaAlpha, sigmaAvg);
......
...@@ -39,7 +39,6 @@ TEST(DisparityWLSFilterTest, ReferenceAccuracy) ...@@ -39,7 +39,6 @@ TEST(DisparityWLSFilterTest, ReferenceAccuracy)
double ref_MSE = (double)reference_res["MSE_after"]; double ref_MSE = (double)reference_res["MSE_after"];
double ref_BadPercent = (double)reference_res["BadPercent_after"]; double ref_BadPercent = (double)reference_res["BadPercent_after"];
cv::setNumThreads(cv::getNumberOfCPUs());
Mat res; Mat res;
Ptr<DisparityWLSFilter> wls_filter = createDisparityWLSFilterGeneric(true); Ptr<DisparityWLSFilter> wls_filter = createDisparityWLSFilterGeneric(true);
...@@ -88,6 +87,9 @@ TEST_P(DisparityWLSFilterTest, MultiThreadReproducibility) ...@@ -88,6 +87,9 @@ TEST_P(DisparityWLSFilterTest, MultiThreadReproducibility)
ROI = Rect(ROI.x/2,ROI.y/2,ROI.width/2,ROI.height/2); ROI = Rect(ROI.x/2,ROI.y/2,ROI.width/2,ROI.height/2);
} }
int nThreads = cv::getNumThreads();
if (nThreads == 1)
throw SkipTestException("Single thread environment");
for (int iter = 0; iter <= loopsCount; iter++) for (int iter = 0; iter <= loopsCount; iter++)
{ {
double lambda = rng.uniform(100.0, 10000.0); double lambda = rng.uniform(100.0, 10000.0);
...@@ -97,7 +99,7 @@ TEST_P(DisparityWLSFilterTest, MultiThreadReproducibility) ...@@ -97,7 +99,7 @@ TEST_P(DisparityWLSFilterTest, MultiThreadReproducibility)
wls_filter->setLambda(lambda); wls_filter->setLambda(lambda);
wls_filter->setSigmaColor(sigma); wls_filter->setSigmaColor(sigma);
cv::setNumThreads(cv::getNumberOfCPUs()); cv::setNumThreads(nThreads);
Mat resMultiThread; Mat resMultiThread;
wls_filter->filter(left_disp,left,resMultiThread,right_disp,ROI); wls_filter->filter(left_disp,left,resMultiThread,right_disp,ROI);
......
...@@ -100,12 +100,15 @@ TEST_P(DomainTransformTest, MultiThreadReproducibility) ...@@ -100,12 +100,15 @@ TEST_P(DomainTransformTest, MultiThreadReproducibility)
Mat guide = convertTypeAndSize(original, guideType, size); Mat guide = convertTypeAndSize(original, guideType, size);
Mat src = convertTypeAndSize(original, srcType, size); Mat src = convertTypeAndSize(original, srcType, size);
int nThreads = cv::getNumThreads();
if (nThreads == 1)
throw SkipTestException("Single thread environment");
for (int iter = 0; iter <= loopsCount; iter++) for (int iter = 0; iter <= loopsCount; iter++)
{ {
double ss = rng.uniform(0.0, 100.0); double ss = rng.uniform(0.0, 100.0);
double sc = rng.uniform(0.0, 100.0); double sc = rng.uniform(0.0, 100.0);
cv::setNumThreads(cv::getNumberOfCPUs()); cv::setNumThreads(nThreads);
Mat resMultithread; Mat resMultithread;
dtFilter(guide, src, resMultithread, ss, sc, mode); dtFilter(guide, src, resMultithread, ss, sc, mode);
...@@ -194,7 +197,6 @@ TEST(DomainTransformTest, AuthorReferenceAccuracy) ...@@ -194,7 +197,6 @@ TEST(DomainTransformTest, AuthorReferenceAccuracy)
ASSERT_FALSE(ref_IC.empty()); ASSERT_FALSE(ref_IC.empty());
ASSERT_FALSE(ref_RF.empty()); ASSERT_FALSE(ref_RF.empty());
cv::setNumThreads(cv::getNumberOfCPUs());
Mat res_NC, res_IC, res_RF; Mat res_NC, res_IC, res_RF;
dtFilter(src, src, res_NC, ss, sc, DTF_NC); dtFilter(src, src, res_NC, ss, sc, DTF_NC);
dtFilter(src, src, res_IC, ss, sc, DTF_IC); dtFilter(src, src, res_IC, ss, sc, DTF_IC);
......
...@@ -55,7 +55,6 @@ TEST(FastGlobalSmootherTest, ReferenceAccuracy) ...@@ -55,7 +55,6 @@ TEST(FastGlobalSmootherTest, ReferenceAccuracy)
ASSERT_FALSE(src.empty()); ASSERT_FALSE(src.empty());
ASSERT_FALSE(ref.empty()); ASSERT_FALSE(ref.empty());
cv::setNumThreads(cv::getNumberOfCPUs());
Mat res; Mat res;
fastGlobalSmootherFilter(src,src,res,1000.0,10.0); fastGlobalSmootherFilter(src,src,res,1000.0,10.0);
...@@ -90,12 +89,15 @@ TEST_P(FastGlobalSmootherTest, MultiThreadReproducibility) ...@@ -90,12 +89,15 @@ TEST_P(FastGlobalSmootherTest, MultiThreadReproducibility)
else else
randu(src, -100000.0f, 100000.0f); randu(src, -100000.0f, 100000.0f);
int nThreads = cv::getNumThreads();
if (nThreads == 1)
throw SkipTestException("Single thread environment");
for (int iter = 0; iter <= loopsCount; iter++) for (int iter = 0; iter <= loopsCount; iter++)
{ {
double lambda = rng.uniform(100.0, 10000.0); double lambda = rng.uniform(100.0, 10000.0);
double sigma = rng.uniform(1.0, 100.0); double sigma = rng.uniform(1.0, 100.0);
cv::setNumThreads(cv::getNumberOfCPUs()); cv::setNumThreads(nThreads);
Mat resMultiThread; Mat resMultiThread;
fastGlobalSmootherFilter(guide, src, resMultiThread, lambda, sigma); fastGlobalSmootherFilter(guide, src, resMultiThread, lambda, sigma);
......
...@@ -324,12 +324,15 @@ TEST_P(GuidedFilterTest, accuracy) ...@@ -324,12 +324,15 @@ TEST_P(GuidedFilterTest, accuracy)
guide = convertTypeAndSize(guide, CV_MAKE_TYPE(guide.depth(), guideCnNum), dstSize); guide = convertTypeAndSize(guide, CV_MAKE_TYPE(guide.depth(), guideCnNum), dstSize);
src = convertTypeAndSize(src, CV_MAKE_TYPE(src.depth(), srcCnNum), dstSize); src = convertTypeAndSize(src, CV_MAKE_TYPE(src.depth(), srcCnNum), dstSize);
int nThreads = cv::getNumThreads();
if (nThreads == 1)
throw SkipTestException("Single thread environment");
for (int iter = 0; iter < 2; iter++) for (int iter = 0; iter < 2; iter++)
{ {
int radius = rng.uniform(0, 50); int radius = rng.uniform(0, 50);
double eps = rng.uniform(0.0, SQR(255.0)); double eps = rng.uniform(0.0, SQR(255.0));
cv::setNumThreads(cv::getNumberOfCPUs()); cv::setNumThreads(nThreads);
Mat res; Mat res;
Ptr<GuidedFilter> gf = createGuidedFilter(guide, radius, eps); Ptr<GuidedFilter> gf = createGuidedFilter(guide, radius, eps);
gf->filter(src, res); gf->filter(src, res);
......
...@@ -192,10 +192,8 @@ TEST_P(JointBilateralFilterTest_NaiveRef, Accuracy) ...@@ -192,10 +192,8 @@ TEST_P(JointBilateralFilterTest_NaiveRef, Accuracy)
Mat resNaive; Mat resNaive;
jointBilateralFilterNaive(joint, src, resNaive, 0, sigmaC, sigmaS); jointBilateralFilterNaive(joint, src, resNaive, 0, sigmaC, sigmaS);
cv::setNumThreads(cv::getNumberOfCPUs());
Mat res; Mat res;
jointBilateralFilter(joint, src, res, 0, sigmaC, sigmaS); jointBilateralFilter(joint, src, res, 0, sigmaC, sigmaS);
cv::setNumThreads(1);
checkSimilarity(res, resNaive); checkSimilarity(res, resNaive);
} }
...@@ -226,8 +224,6 @@ TEST_P(JointBilateralFilterTest_BilateralRef, Accuracy) ...@@ -226,8 +224,6 @@ TEST_P(JointBilateralFilterTest_BilateralRef, Accuracy)
RNG rnd(cvRound(10*sigmaS) + srcPath.length() + srcType + src.rows); RNG rnd(cvRound(10*sigmaS) + srcPath.length() + srcType + src.rows);
double sigmaC = rnd.uniform(0.0, 255.0); double sigmaC = rnd.uniform(0.0, 255.0);
cv::setNumThreads(cv::getNumberOfCPUs());
Mat resRef; Mat resRef;
bilateralFilter(src, resRef, 0, sigmaC, sigmaS); bilateralFilter(src, resRef, 0, sigmaC, sigmaS);
......
...@@ -57,12 +57,15 @@ TEST_P(L0SmoothTest, MultiThreadReproducibility) ...@@ -57,12 +57,15 @@ TEST_P(L0SmoothTest, MultiThreadReproducibility)
randu(src, -100000.0f, 100000.0f); randu(src, -100000.0f, 100000.0f);
int nThreads = cv::getNumThreads();
if (nThreads == 1)
throw SkipTestException("Single thread environment");
for (int iter = 0; iter <= loopsCount; iter++) for (int iter = 0; iter <= loopsCount; iter++)
{ {
double lambda = rng.uniform(0.01, 0.05); double lambda = rng.uniform(0.01, 0.05);
double kappa = rng.uniform(1.5, 5.0); double kappa = rng.uniform(1.5, 5.0);
cv::setNumThreads(cv::getNumberOfCPUs()); cv::setNumThreads(nThreads);
Mat resMultiThread; Mat resMultiThread;
l0Smooth(src, resMultiThread, lambda, kappa); l0Smooth(src, resMultiThread, lambda, kappa);
......
...@@ -104,12 +104,15 @@ TEST_P(RollingGuidanceFilterTest, MultiThreadReproducibility) ...@@ -104,12 +104,15 @@ TEST_P(RollingGuidanceFilterTest, MultiThreadReproducibility)
else else
randu(src, -100000.0f, 100000.0f); randu(src, -100000.0f, 100000.0f);
int nThreads = cv::getNumThreads();
if (nThreads == 1)
throw SkipTestException("Single thread environment");
for (int iter = 0; iter <= loopsCount; iter++) for (int iter = 0; iter <= loopsCount; iter++)
{ {
int iterNum = int(rnd.uniform(1.0, 5.0)); int iterNum = int(rnd.uniform(1.0, 5.0));
double sigmaC = rnd.uniform(1.0, 255.0); double sigmaC = rnd.uniform(1.0, 255.0);
cv::setNumThreads(cv::getNumberOfCPUs()); cv::setNumThreads(nThreads);
Mat resMultiThread; Mat resMultiThread;
rollingGuidanceFilter(src, resMultiThread, -1, sigmaC, sigmaS, iterNum); rollingGuidanceFilter(src, resMultiThread, -1, sigmaC, sigmaS, iterNum);
...@@ -150,8 +153,6 @@ TEST_P(RollingGuidanceFilterTest_BilateralRef, Accuracy) ...@@ -150,8 +153,6 @@ TEST_P(RollingGuidanceFilterTest_BilateralRef, Accuracy)
RNG rnd(0); RNG rnd(0);
double sigmaC = rnd.uniform(0.0, 255.0); double sigmaC = rnd.uniform(0.0, 255.0);
cv::setNumThreads(cv::getNumberOfCPUs());
Mat resRef; Mat resRef;
bilateralFilter(src, resRef, 0, sigmaC, sigmaS); bilateralFilter(src, resRef, 0, sigmaC, sigmaS);
......
...@@ -81,7 +81,6 @@ TEST(InterpolatorTest, ReferenceAccuracy) ...@@ -81,7 +81,6 @@ TEST(InterpolatorTest, ReferenceAccuracy)
to_points.push_back(Point2f(to_x,to_y)); to_points.push_back(Point2f(to_x,to_y));
} }
cv::setNumThreads(cv::getNumberOfCPUs());
Mat res_flow; Mat res_flow;
Ptr<EdgeAwareInterpolator> interpolator = createEdgeAwareInterpolator(); Ptr<EdgeAwareInterpolator> interpolator = createEdgeAwareInterpolator();
...@@ -123,6 +122,9 @@ TEST_P(InterpolatorTest, MultiThreadReproducibility) ...@@ -123,6 +122,9 @@ TEST_P(InterpolatorTest, MultiThreadReproducibility)
to_points.push_back(Point2f(rng.uniform(0.01f,(float)size.width-1.01f),rng.uniform(0.01f,(float)size.height-1.01f))); to_points.push_back(Point2f(rng.uniform(0.01f,(float)size.width-1.01f),rng.uniform(0.01f,(float)size.height-1.01f)));
} }
int nThreads = cv::getNumThreads();
if (nThreads == 1)
throw SkipTestException("Single thread environment");
for (int iter = 0; iter <= loopsCount; iter++) for (int iter = 0; iter <= loopsCount; iter++)
{ {
int K = rng.uniform(4,512); int K = rng.uniform(4,512);
...@@ -137,7 +139,7 @@ TEST_P(InterpolatorTest, MultiThreadReproducibility) ...@@ -137,7 +139,7 @@ TEST_P(InterpolatorTest, MultiThreadReproducibility)
interpolator->setFGSLambda(FGSlambda); interpolator->setFGSLambda(FGSlambda);
interpolator->setFGSSigma(FGSsigma); interpolator->setFGSSigma(FGSsigma);
cv::setNumThreads(cv::getNumberOfCPUs()); cv::setNumThreads(nThreads);
Mat resMultiThread; Mat resMultiThread;
interpolator->interpolate(from,from_points,Mat(),to_points,resMultiThread); interpolator->interpolate(from,from_points,Mat(),to_points,resMultiThread);
......
...@@ -52,7 +52,6 @@ TEST(WeightedMedianFilterTest, ReferenceAccuracy) ...@@ -52,7 +52,6 @@ TEST(WeightedMedianFilterTest, ReferenceAccuracy)
ASSERT_FALSE(src.empty()); ASSERT_FALSE(src.empty());
ASSERT_FALSE(ref.empty()); ASSERT_FALSE(ref.empty());
cv::setNumThreads(cv::getNumberOfCPUs());
Mat res; Mat res;
weightedMedianFilter(src, src, res, 7); weightedMedianFilter(src, src, res, 7);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment