Path: blob/master/modules/imgproc/perf/perf_threshold.cpp
16354 views
// This file is part of OpenCV project.1// It is subject to the license terms in the LICENSE file found in the top-level directory2// of this distribution and at http://opencv.org/license.html.3#include "perf_precomp.hpp"45namespace opencv_test {67CV_ENUM(ThreshType, THRESH_BINARY, THRESH_BINARY_INV, THRESH_TRUNC, THRESH_TOZERO, THRESH_TOZERO_INV)89typedef tuple<Size, MatType, ThreshType> Size_MatType_ThreshType_t;10typedef perf::TestBaseWithParam<Size_MatType_ThreshType_t> Size_MatType_ThreshType;1112PERF_TEST_P(Size_MatType_ThreshType, threshold,13testing::Combine(14testing::Values(TYPICAL_MAT_SIZES),15testing::Values(CV_8UC1, CV_16SC1, CV_32FC1, CV_64FC1),16ThreshType::all()17)18)19{2021Size sz = get<0>(GetParam());22int type = get<1>(GetParam());23ThreshType threshType = get<2>(GetParam());2425Mat src(sz, type);26Mat dst(sz, type);2728double thresh = theRNG().uniform(1, 254);29double maxval = theRNG().uniform(1, 254);3031declare.in(src, WARMUP_RNG).out(dst);3233int runs = (sz.width <= 640) ? 40 : 1;34TEST_CYCLE_MULTIRUN(runs) cv::threshold(src, dst, thresh, maxval, threshType);3536SANITY_CHECK(dst);37}3839typedef perf::TestBaseWithParam<Size> Size_Only;4041PERF_TEST_P(Size_Only, threshold_otsu, testing::Values(TYPICAL_MAT_SIZES))42{43Size sz = GetParam();4445Mat src(sz, CV_8UC1);46Mat dst(sz, CV_8UC1);4748double maxval = theRNG().uniform(1, 254);4950declare.in(src, WARMUP_RNG).out(dst);5152int runs = 15;53TEST_CYCLE_MULTIRUN(runs) cv::threshold(src, dst, 0, maxval, THRESH_BINARY|THRESH_OTSU);5455SANITY_CHECK(dst);56}5758CV_ENUM(AdaptThreshType, THRESH_BINARY, THRESH_BINARY_INV)59CV_ENUM(AdaptThreshMethod, ADAPTIVE_THRESH_MEAN_C, ADAPTIVE_THRESH_GAUSSIAN_C)6061typedef tuple<Size, AdaptThreshType, AdaptThreshMethod, int, double> Size_AdaptThreshType_AdaptThreshMethod_BlockSize_Delta_t;62typedef perf::TestBaseWithParam<Size_AdaptThreshType_AdaptThreshMethod_BlockSize_Delta_t> Size_AdaptThreshType_AdaptThreshMethod_BlockSize_Delta;6364PERF_TEST_P(Size_AdaptThreshType_AdaptThreshMethod_BlockSize_Delta, adaptiveThreshold,65testing::Combine(66testing::Values(TYPICAL_MAT_SIZES),67AdaptThreshType::all(),68AdaptThreshMethod::all(),69testing::Values(3, 5),70testing::Values(0.0, 10.0)71)72)73{74Size sz = get<0>(GetParam());75AdaptThreshType adaptThreshType = get<1>(GetParam());76AdaptThreshMethod adaptThreshMethod = get<2>(GetParam());77int blockSize = get<3>(GetParam());78double C = get<4>(GetParam());7980double maxValue = theRNG().uniform(1, 254);8182int type = CV_8UC1;8384Mat src_full(cv::Size(sz.width + 2, sz.height + 2), type);85Mat src = src_full(cv::Rect(1, 1, sz.width, sz.height));86Mat dst(sz, type);8788declare.in(src, WARMUP_RNG).out(dst);8990TEST_CYCLE() cv::adaptiveThreshold(src, dst, maxValue, adaptThreshMethod, adaptThreshType, blockSize, C);9192SANITY_CHECK(dst);93}9495} // namespace969798