From 6d0f8aa893e5541a9895fd856a6bca41ace55adf Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Mon, 2 Mar 2015 11:02:47 +0300 Subject: [PATCH] fix tests for gpu HOG initialize HOG after CUDA device switch (cherry picked from commit c849492dfa07c6a35dfbd3c44a42c1c6a4fc0d60) --- modules/gpu/test/test_objdetect.cpp | 69 +++++++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 26 deletions(-) diff --git a/modules/gpu/test/test_objdetect.cpp b/modules/gpu/test/test_objdetect.cpp index f5c4e16..e08715d 100644 --- a/modules/gpu/test/test_objdetect.cpp +++ b/modules/gpu/test/test_objdetect.cpp @@ -48,9 +48,24 @@ using namespace cvtest; //#define DUMP -struct HOG : testing::TestWithParam, cv::gpu::HOGDescriptor +class HogForTest : public cv::gpu::HOGDescriptor +{ +public: + cv::gpu::GpuMat getBlockHists() const + { + return block_hists; + } + + void computeBlockHistograms(const cv::gpu::GpuMat& img) + { + cv::gpu::HOGDescriptor::computeBlockHistograms(img); + } +}; + +struct HOG : testing::TestWithParam { cv::gpu::DeviceInfo devInfo; + cv::Ptr hog; #ifdef DUMP std::ofstream f; @@ -69,6 +84,8 @@ struct HOG : testing::TestWithParam, cv::gpu::HOGDescriptor devInfo = GetParam(); cv::gpu::setDevice(devInfo.deviceID()); + + hog = new HogForTest; } #ifdef DUMP @@ -126,39 +143,39 @@ struct HOG : testing::TestWithParam, cv::gpu::HOGDescriptor void testDetect(const cv::Mat& img) { - gamma_correction = false; - setSVMDetector(cv::gpu::HOGDescriptor::getDefaultPeopleDetector()); + hog->gamma_correction = false; + hog->setSVMDetector(cv::gpu::HOGDescriptor::getDefaultPeopleDetector()); std::vector locations; // Test detect - detect(loadMat(img), locations, 0); + hog->detect(loadMat(img), locations, 0); #ifdef DUMP - dump(cv::Mat(block_hists), locations); + dump(cv::Mat(hog->getBlockHist()), locations); #else - compare(cv::Mat(block_hists), locations); + compare(cv::Mat(hog->getBlockHists()), locations); #endif // Test detect on smaller image cv::Mat img2; cv::resize(img, img2, cv::Size(img.cols / 2, img.rows / 2)); - detect(loadMat(img2), locations, 0); + hog->detect(loadMat(img2), locations, 0); #ifdef DUMP - dump(cv::Mat(block_hists), locations); + dump(cv::Mat(hog->getBlockHist()), locations); #else - compare(cv::Mat(block_hists), locations); + compare(cv::Mat(hog->getBlockHists()), locations); #endif // Test detect on greater image cv::resize(img, img2, cv::Size(img.cols * 2, img.rows * 2)); - detect(loadMat(img2), locations, 0); + hog->detect(loadMat(img2), locations, 0); #ifdef DUMP - dump(cv::Mat(block_hists), locations); + dump(cv::Mat(hog->getBlockHist()), locations); #else - compare(cv::Mat(block_hists), locations); + compare(cv::Mat(hog->getBlockHists()), locations); #endif } @@ -216,8 +233,8 @@ GPU_TEST_P(HOG, GetDescriptors) // Convert train images into feature vectors (train table) cv::gpu::GpuMat descriptors, descriptors_by_cols; - getDescriptors(d_img, win_size, descriptors, DESCR_FORMAT_ROW_BY_ROW); - getDescriptors(d_img, win_size, descriptors_by_cols, DESCR_FORMAT_COL_BY_COL); + hog->getDescriptors(d_img, hog->win_size, descriptors, cv::gpu::HOGDescriptor::DESCR_FORMAT_ROW_BY_ROW); + hog->getDescriptors(d_img, hog->win_size, descriptors_by_cols, cv::gpu::HOGDescriptor::DESCR_FORMAT_COL_BY_COL); // Check size of the result train table wins_per_img_x = 3; @@ -251,39 +268,39 @@ GPU_TEST_P(HOG, GetDescriptors) img_rgb = readImage("hog/positive1.png"); ASSERT_TRUE(!img_rgb.empty()); cv::cvtColor(img_rgb, img, CV_BGR2BGRA); - computeBlockHistograms(cv::gpu::GpuMat(img)); + hog->computeBlockHistograms(cv::gpu::GpuMat(img)); // Everything is fine with interpolation for left top subimage - ASSERT_EQ(0.0, cv::norm((cv::Mat)block_hists, (cv::Mat)descriptors.rowRange(0, 1))); + ASSERT_EQ(0.0, cv::norm(cv::Mat(hog->getBlockHists()), (cv::Mat)descriptors.rowRange(0, 1))); img_rgb = readImage("hog/positive2.png"); ASSERT_TRUE(!img_rgb.empty()); cv::cvtColor(img_rgb, img, CV_BGR2BGRA); - computeBlockHistograms(cv::gpu::GpuMat(img)); - compare_inner_parts(cv::Mat(block_hists), cv::Mat(descriptors.rowRange(1, 2))); + hog->computeBlockHistograms(cv::gpu::GpuMat(img)); + compare_inner_parts(cv::Mat(hog->getBlockHists()), cv::Mat(descriptors.rowRange(1, 2))); img_rgb = readImage("hog/negative1.png"); ASSERT_TRUE(!img_rgb.empty()); cv::cvtColor(img_rgb, img, CV_BGR2BGRA); - computeBlockHistograms(cv::gpu::GpuMat(img)); - compare_inner_parts(cv::Mat(block_hists), cv::Mat(descriptors.rowRange(2, 3))); + hog->computeBlockHistograms(cv::gpu::GpuMat(img)); + compare_inner_parts(cv::Mat(hog->getBlockHists()), cv::Mat(descriptors.rowRange(2, 3))); img_rgb = readImage("hog/negative2.png"); ASSERT_TRUE(!img_rgb.empty()); cv::cvtColor(img_rgb, img, CV_BGR2BGRA); - computeBlockHistograms(cv::gpu::GpuMat(img)); - compare_inner_parts(cv::Mat(block_hists), cv::Mat(descriptors.rowRange(3, 4))); + hog->computeBlockHistograms(cv::gpu::GpuMat(img)); + compare_inner_parts(cv::Mat(hog->getBlockHists()), cv::Mat(descriptors.rowRange(3, 4))); img_rgb = readImage("hog/positive3.png"); ASSERT_TRUE(!img_rgb.empty()); cv::cvtColor(img_rgb, img, CV_BGR2BGRA); - computeBlockHistograms(cv::gpu::GpuMat(img)); - compare_inner_parts(cv::Mat(block_hists), cv::Mat(descriptors.rowRange(4, 5))); + hog->computeBlockHistograms(cv::gpu::GpuMat(img)); + compare_inner_parts(cv::Mat(hog->getBlockHists()), cv::Mat(descriptors.rowRange(4, 5))); img_rgb = readImage("hog/negative3.png"); ASSERT_TRUE(!img_rgb.empty()); cv::cvtColor(img_rgb, img, CV_BGR2BGRA); - computeBlockHistograms(cv::gpu::GpuMat(img)); - compare_inner_parts(cv::Mat(block_hists), cv::Mat(descriptors.rowRange(5, 6))); + hog->computeBlockHistograms(cv::gpu::GpuMat(img)); + compare_inner_parts(cv::Mat(hog->getBlockHists()), cv::Mat(descriptors.rowRange(5, 6))); } INSTANTIATE_TEST_CASE_P(GPU_ObjDetect, HOG, ALL_DEVICES); -- 2.7.4