From cb329400df0a3ed8b96397a74a967dc5add2615d Mon Sep 17 00:00:00 2001 From: "marina.kolpakova" Date: Wed, 30 Jan 2013 08:18:05 +0400 Subject: [PATCH] fix tests --- modules/gpu/perf/perf_softcascade.cpp | 51 +---------------- modules/gpu/src/cuda/icf-sc.cu | 2 +- modules/gpu/src/softcascade.cpp | 16 +----- modules/gpu/test/test_softcascade.cpp | 64 +++++++++------------- .../include/opencv2/objdetect/objdetect.hpp | 10 ---- 5 files changed, 29 insertions(+), 114 deletions(-) diff --git a/modules/gpu/perf/perf_softcascade.cpp b/modules/gpu/perf/perf_softcascade.cpp index 97ee9de..6cb3c63 100644 --- a/modules/gpu/perf/perf_softcascade.cpp +++ b/modules/gpu/perf/perf_softcascade.cpp @@ -194,52 +194,6 @@ RUN_GPU(SCascadeTestRoi, detectEachRoi) NO_CPU(SCascadeTestRoi, detectEachRoi) -SC_PERF_TEST_P(SCascadeTest, detectOnIntegral, - testing::Combine( - testing::Values(std::string("cv/cascadeandhog/cascades/inria_caltech-17.01.2013.xml"), - std::string("cv/cascadeandhog/cascades/sc_cvpr_2012_to_opencv_new_format.xml")), - testing::Values(std::string("cv/cascadeandhog/integrals.xml")))) - -static std::string itoa(long i) -{ - static char s[65]; - sprintf(s, "%ld", i); - return std::string(s); -} - -RUN_GPU(SCascadeTest, detectOnIntegral) -{ - cv::Mat cpu = readImage ("cv/cascadeandhog/images/image_00000000_0.png"); - ASSERT_FALSE(cpu.empty()); - - cv::ICFPreprocessor preprocessor; - cv::Mat test_res(cpu.rows / 4 * 10 + 1, cpu.cols / 4 + 1, CV_8UC1); - preprocessor.apply(cpu,test_res); - - cv::gpu::SCascade cascade; - - cv::FileStorage fs(perf::TestBase::getDataPath(GET_PARAM(0)), cv::FileStorage::READ); - ASSERT_TRUE(fs.isOpened()); - - ASSERT_TRUE(cascade.load(fs.getFirstTopLevelNode())); - - cv::gpu::GpuMat objectBoxes(1, 10000 * sizeof(cv::gpu::SCascade::Detection), CV_8UC1), rois(cv::Size(640, 480), CV_8UC1); - rois.setTo(1); - - cv::gpu::GpuMat hogluv(test_res); - - cascade.detect(hogluv, rois, objectBoxes); - - TEST_CYCLE() - { - cascade.detect(hogluv, rois, objectBoxes); - } - - SANITY_CHECK(sortDetections(objectBoxes)); -} - -NO_CPU(SCascadeTest, detectOnIntegral) - SC_PERF_TEST_P(SCascadeTest, detectStream, testing::Combine( testing::Values(std::string("cv/cascadeandhog/cascades/inria_caltech-17.01.2013.xml"), @@ -271,10 +225,7 @@ RUN_GPU(SCascadeTest, detectStream) cascade.detect(colored, rois, objectBoxes, s); } -#ifdef HAVE_CUDA - cudaDeviceSynchronize(); -#endif - + s.waitForCompletion(); SANITY_CHECK(sortDetections(objectBoxes)); } diff --git a/modules/gpu/src/cuda/icf-sc.cu b/modules/gpu/src/cuda/icf-sc.cu index 1894cd4..d64c7a8 100644 --- a/modules/gpu/src/cuda/icf-sc.cu +++ b/modules/gpu/src/cuda/icf-sc.cu @@ -547,7 +547,7 @@ void CascadeInvoker::operator()(const PtrStepSzb& roi, const PtrStepSzi& soft_cascade<<>>(inv, det, max_det, ctr, 0); cudaSafeCall( cudaGetLastError()); - grid = dim3(fw, fh / Policy::STA_Y, 38 - downscales); + grid = dim3(fw, fh / Policy::STA_Y, min(38, scales) - downscales); soft_cascade<<>>(inv, det, max_det, ctr, downscales); if (!stream) diff --git a/modules/gpu/src/softcascade.cpp b/modules/gpu/src/softcascade.cpp index 27c44d0..8840209 100644 --- a/modules/gpu/src/softcascade.cpp +++ b/modules/gpu/src/softcascade.cpp @@ -133,10 +133,6 @@ struct cv::gpu::SCascade::Fields std::string fformat = (string)root[SC_FEATURE_FORMAT]; bool useBoxes = (fformat == "BOX"); - - if(useBoxes) - std::cout << "use boxes!!!"; - ushort shrinkage = cv::saturate_cast((int)root[SC_SHRINKAGE]); FileNode fn = root[SC_OCTAVES]; @@ -154,13 +150,8 @@ struct cv::gpu::SCascade::Fields { FileNode fns = *it; float scale = powf(2.f,saturate_cast((int)fns[SC_OCT_SCALE])); - std::cout << "octave scale " << scale << std::endl; - bool isUPOctave = scale >= 1; - if (isUPOctave) - std::cout << "isUPOctave" << std::endl; - ushort nweaks = saturate_cast((int)fns[SC_OCT_WEAKS]); ushort2 size; @@ -225,11 +216,9 @@ struct cv::gpu::SCascade::Fields { inIt +=2; int featureIdx = (int)(*(inIt++)); - // std::cout << " featureIdx " << featureIdx << " " << feature_rects[featureIdx] << std::endl; float orig_threshold = (float)(*(inIt++)); unsigned int th = saturate_cast((int)orig_threshold); - // std::cout << "orig_threshold " << orig_threshold << " converted " << th << std::endl; cv::Rect& r = feature_rects[featureIdx]; uchar4 rect; rect.x = saturate_cast(r.x); @@ -248,7 +237,6 @@ struct cv::gpu::SCascade::Fields vleaves.push_back((float)(*inIt)); } } - std::cout << std::endl; } cv::Mat hoctaves(1, (int) (voctaves.size() * sizeof(Octave)), CV_8UC1, (uchar*)&(voctaves[0])); @@ -424,7 +412,7 @@ public: // 160x120x10 GpuMat shrunk; - // temporial mat for integrall + // temporal mat for integral GpuMat integralBuffer; // 161x121x10 @@ -591,7 +579,7 @@ private: cv::gpu::cartToPolar(dfdx, dfdy, mag, ang, true, s); - // normolize magnitude to uchar interval and angles to 6 bins + // normalize magnitude to uchar interval and angles to 6 bins GpuMat nmag(fplane, cv::Rect(0, 4 * fh, fw, fh)); GpuMat nang(fplane, cv::Rect(0, 5 * fh, fw, fh)); diff --git a/modules/gpu/test/test_softcascade.cpp b/modules/gpu/test/test_softcascade.cpp index 5b897a9..c08dc06 100644 --- a/modules/gpu/test/test_softcascade.cpp +++ b/modules/gpu/test/test_softcascade.cpp @@ -219,15 +219,30 @@ INSTANTIATE_TEST_CASE_P(GPU_SoftCascade, SCascadeTestRoi, testing::Combine( testing::Range(0, 5))); //////////////////////////////////////// -PARAM_TEST_CASE(SCascadeTestAll, cv::gpu::DeviceInfo, std::string) + +namespace { + +struct Fixture +{ + std::string path; + int expected; + + Fixture(){} + Fixture(std::string p, int e): path(p), expected(e) {} +}; +} + +PARAM_TEST_CASE(SCascadeTestAll, cv::gpu::DeviceInfo, Fixture) { std::string xml; + int expected; virtual void SetUp() { cv::gpu::setDevice(GET_PARAM(0).deviceID()); - xml = path(GET_PARAM(1)); + xml = path(GET_PARAM(1).path); + expected = GET_PARAM(1).expected; } }; @@ -265,34 +280,7 @@ GPU_TEST_P(SCascadeTestAll, detect) } SHOW(coloredCpu); - // ASSERT_EQ(count, 2448); -} - -GPU_TEST_P(SCascadeTestAll, detectOnIntegral) -{ - cv::gpu::SCascade cascade; - - cv::FileStorage fs(xml, cv::FileStorage::READ); - ASSERT_TRUE(fs.isOpened()); - - ASSERT_TRUE(cascade.load(fs.getFirstTopLevelNode())); - - cv::Mat coloredCpu = cv::imread(path("images/image_00000000_0.png")); - cv::ICFPreprocessor preprocessor; - cv::Mat integrals(coloredCpu.rows / 4 * 10 + 1, coloredCpu.cols / 4 + 1, CV_8UC1); - preprocessor.apply(coloredCpu, integrals); - GpuMat hogluv(integrals); - - GpuMat objectBoxes(1, 100000, CV_8UC1), rois(cv::Size(640, 480), CV_8UC1); - rois.setTo(1); - - objectBoxes.setTo(0); - cascade.detect(hogluv, rois, objectBoxes); - -// typedef cv::gpu::SCascade::Detection Detection; -// cv::Mat detections(objectBoxes); -// int a = *(detections.ptr(0)); -// ASSERT_EQ(a, 1024); + ASSERT_EQ(*count, expected); } GPU_TEST_P(SCascadeTestAll, detectStream) @@ -308,9 +296,7 @@ GPU_TEST_P(SCascadeTestAll, detectStream) ASSERT_FALSE(coloredCpu.empty()); GpuMat colored(coloredCpu), objectBoxes(1, 100000, CV_8UC1), rois(colored.size(), CV_8UC1); - rois.setTo(0); - GpuMat sub(rois, cv::Rect(rois.cols / 4, rois.rows / 4,rois.cols / 2, rois.rows / 2)); - sub.setTo(cv::Scalar::all(1)); + rois.setTo(cv::Scalar::all(1)); cv::gpu::Stream s; @@ -318,14 +304,14 @@ GPU_TEST_P(SCascadeTestAll, detectStream) cascade.detect(colored, rois, objectBoxes, s); s.waitForCompletion(); - // typedef cv::gpu::SCascade::Detection Detection; - // cv::Mat detections(objectBoxes); - // int a = *(detections.ptr(0)); - // ASSERT_EQ(a, 2448); + typedef cv::gpu::SCascade::Detection Detection; + cv::Mat detections(objectBoxes); + int a = *(detections.ptr(0)); + ASSERT_EQ(a, expected); } INSTANTIATE_TEST_CASE_P(GPU_SoftCascade, SCascadeTestAll, testing::Combine( ALL_DEVICES, - testing::Values(std::string("cascades/inria_caltech-17.01.2013.xml"), - std::string("cascades/sc_cvpr_2012_to_opencv_new_format.xml")))); + testing::Values(Fixture("cascades/inria_caltech-17.01.2013.xml", 7), + Fixture("cascades/sc_cvpr_2012_to_opencv_new_format.xml", 1291)))); #endif diff --git a/modules/objdetect/include/opencv2/objdetect/objdetect.hpp b/modules/objdetect/include/opencv2/objdetect/objdetect.hpp index 95300c4..8d39329 100644 --- a/modules/objdetect/include/opencv2/objdetect/objdetect.hpp +++ b/modules/objdetect/include/opencv2/objdetect/objdetect.hpp @@ -488,16 +488,6 @@ protected: Ptr maskGenerator; }; - -class CV_EXPORTS_W ICFPreprocessor -{ -public: - CV_WRAP ICFPreprocessor(); - CV_WRAP void apply(cv::InputArray _frame, cv::OutputArray _integrals) const; -protected: - enum {BINS = 10}; -}; - // Implementation of soft (stageless) cascaded detector. class CV_EXPORTS_W SCascade : public Algorithm { -- 2.7.4