<commit_before>#include "perf_precomp.hpp"

using namespace std;
using namespace testing;

namespace {

///////////////////////////////////////////////////////////////
// HOG

DEF_PARAM_TEST_1(Image, string);

PERF_TEST_P(Image, ObjDetect_HOG, Values<string>("gpu/hog/road.png"))
{
    cv::Mat img = readImage(GetParam(), cv::IMREAD_GRAYSCALE);
    ASSERT_FALSE(img.empty());

    std::vector<cv::Rect> found_locations;

    if (PERF_RUN_GPU())
    {
        cv::gpu::GpuMat d_img(img);

        cv::gpu::HOGDescriptor d_hog;
        d_hog.setSVMDetector(cv::gpu::HOGDescriptor::getDefaultPeopleDetector());

        d_hog.detectMultiScale(d_img, found_locations);

        TEST_CYCLE()
        {
            d_hog.detectMultiScale(d_img, found_locations);
        }
    }
    else
    {
        cv::HOGDescriptor hog;
        hog.setSVMDetector(cv::gpu::HOGDescriptor::getDefaultPeopleDetector());

        hog.detectMultiScale(img, found_locations);

        TEST_CYCLE()
        {
            hog.detectMultiScale(img, found_locations);
        }
    }

    SANITY_CHECK(found_locations);
}

//===========test for CalTech data =============//
DEF_PARAM_TEST_1(HOG, string);

PERF_TEST_P(HOG, CalTech, Values<string>("gpu/caltech/image_00000009_0.png", "gpu/caltech/image_00000032_0.png",
    "gpu/caltech/image_00000165_0.png", "gpu/caltech/image_00000261_0.png", "gpu/caltech/image_00000469_0.png",
    "gpu/caltech/image_00000527_0.png", "gpu/caltech/image_00000574_0.png"))
{
    cv::Mat img = readImage(GetParam(), cv::IMREAD_GRAYSCALE);
    ASSERT_FALSE(img.empty());

    std::vector<cv::Rect> found_locations;

    if (PERF_RUN_GPU())
    {
        cv::gpu::GpuMat d_img(img);

        cv::gpu::HOGDescriptor d_hog;
        d_hog.setSVMDetector(cv::gpu::HOGDescriptor::getDefaultPeopleDetector());

        d_hog.detectMultiScale(d_img, found_locations);

        TEST_CYCLE()
        {
            d_hog.detectMultiScale(d_img, found_locations);
        }
    }
    else
    {
        cv::HOGDescriptor hog;
        hog.setSVMDetector(cv::gpu::HOGDescriptor::getDefaultPeopleDetector());

        hog.detectMultiScale(img, found_locations);

        TEST_CYCLE()
        {
            hog.detectMultiScale(img, found_locations);
        }
    }

    SANITY_CHECK(found_locations);
}

typedef pair<string, string> pair_string;
DEF_PARAM_TEST_1(SoftCascade, pair_string);

PERF_TEST_P(SoftCascade, detect, Values<pair_string>(make_pair("cv/cascadeandhog/sc_cvpr_2012_to_opencv.xml",
                                                              "cv/cascadeandhog/bahnhof/image_00000000_0.png")))
{
    if (runOnGpu)
    {
        cv::Mat cpu = readImage(GetParam().second);
        ASSERT_FALSE(cpu.empty());
        cv::gpu::GpuMat colored(cpu);

        cv::gpu::SoftCascade cascade;
        ASSERT_TRUE(cascade.load(GetParam().first));

        cv::gpu::GpuMat rois, objectBoxes;
        cascade.detectMultiScale(colored, rois, objectBoxes);

        TEST_CYCLE()
        {
            cascade.detectMultiScale(colored, rois, objectBoxes);
        }
    } else
    {
        cv::Mat colored = readImage(GetParam().second);
        ASSERT_FALSE(colored.empty());

        cv::SoftCascade cascade;
        ASSERT_TRUE(cascade.load(GetParam().first));

        std::vector<cv::Rect> rois, objectBoxes;
        cascade.detectMultiScale(colored, rois, objectBoxes);

        TEST_CYCLE()
        {
            cascade.detectMultiScale(colored, rois, objectBoxes);
        }
    }
}

///////////////////////////////////////////////////////////////
// HaarClassifier

typedef pair<string, string> pair_string;<commit_msg>fix data paths in performance test<commit_after>#include "perf_precomp.hpp"

using namespace std;
using namespace testing;

namespace {

///////////////////////////////////////////////////////////////
// HOG

DEF_PARAM_TEST_1(Image, string);

PERF_TEST_P(Image, ObjDetect_HOG, Values<string>("gpu/hog/road.png"))
{
    cv::Mat img = readImage(GetParam(), cv::IMREAD_GRAYSCALE);
    ASSERT_FALSE(img.empty());

    std::vector<cv::Rect> found_locations;

    if (PERF_RUN_GPU())
    {
        cv::gpu::GpuMat d_img(img);

        cv::gpu::HOGDescriptor d_hog;
        d_hog.setSVMDetector(cv::gpu::HOGDescriptor::getDefaultPeopleDetector());

        d_hog.detectMultiScale(d_img, found_locations);

        TEST_CYCLE()
        {
            d_hog.detectMultiScale(d_img, found_locations);
        }
    }
    else
    {
        cv::HOGDescriptor hog;
        hog.setSVMDetector(cv::gpu::HOGDescriptor::getDefaultPeopleDetector());

        hog.detectMultiScale(img, found_locations);

        TEST_CYCLE()
        {
            hog.detectMultiScale(img, found_locations);
        }
    }

    SANITY_CHECK(found_locations);
}

//===========test for CalTech data =============//
DEF_PARAM_TEST_1(HOG, string);

PERF_TEST_P(HOG, CalTech, Values<string>("gpu/caltech/image_00000009_0.png", "gpu/caltech/image_00000032_0.png",
    "gpu/caltech/image_00000165_0.png", "gpu/caltech/image_00000261_0.png", "gpu/caltech/image_00000469_0.png",
    "gpu/caltech/image_00000527_0.png", "gpu/caltech/image_00000574_0.png"))
{
    cv::Mat img = readImage(GetParam(), cv::IMREAD_GRAYSCALE);
    ASSERT_FALSE(img.empty());

    std::vector<cv::Rect> found_locations;

    if (PERF_RUN_GPU())
    {
        cv::gpu::GpuMat d_img(img);

        cv::gpu::HOGDescriptor d_hog;
        d_hog.setSVMDetector(cv::gpu::HOGDescriptor::getDefaultPeopleDetector());

        d_hog.detectMultiScale(d_img, found_locations);

        TEST_CYCLE()
        {
            d_hog.detectMultiScale(d_img, found_locations);
        }
    }
    else
    {
        cv::HOGDescriptor hog;
        hog.setSVMDetector(cv::gpu::HOGDescriptor::getDefaultPeopleDetector());

        hog.detectMultiScale(img, found_locations);

        TEST_CYCLE()
        {
            hog.detectMultiScale(img, found_locations);
        }
    }

    SANITY_CHECK(found_locations);
}

typedef pair<string, string> pair_string;
DEF_PARAM_TEST_1(SoftCascade, pair_string);

PERF_TEST_P(SoftCascade, detect, Values<pair_string>(make_pair("cv/cascadeandhog/sc_cvpr_2012_to_opencv.xml",
                                                              "cv/cascadeandhog/bahnhof/image_00000000_0.png")))
{
    if (runOnGpu)
    {
        cv::Mat cpu = readImage (GetParam().second);
        ASSERT_FALSE(cpu.empty());
        cv::gpu::GpuMat colored(cpu);

        cv::gpu::SoftCascade cascade;
        ASSERT_TRUE(cascade.load(perf::TestBase::getDataPath(GetParam().first)));

        cv::gpu::GpuMat rois, objectBoxes;
        cascade.detectMultiScale(colored, rois, objectBoxes);

        TEST_CYCLE()
        {
            cascade.detectMultiScale(colored, rois, objectBoxes);
        }
    } else
    {
        cv::Mat colored = readImage(GetParam().second);
        ASSERT_FALSE(colored.empty());

        cv::SoftCascade cascade;
        ASSERT_TRUE(cascade.load(GetParam().first));

        std::vector<cv::Rect> rois, objectBoxes;
        cascade.detectMultiScale(colored, rois, objectBoxes);

        TEST_CYCLE()
        {
            cascade.detectMultiScale(colored, rois, objectBoxes);
        }
    }
}

///////////////////////////////////////////////////////////////
// HaarClassifier

typedef pair<string, string> pair_string;
{'fraction_non_alphanumeric': 0.16431603450636725, 'fraction_numerical': 0.021634944543338353, 'mean_word_length': 2.6104794859120117, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 4, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '505809', 'n_tokens_mistral': 2576, 'n_tokens_neox': 2341, 'n_words': 289}