fix tests for gpu HOG
initialize HOG after CUDA device switch (cherry picked from commit c849492dfa07c6a35dfbd3c44a42c1c6a4fc0d60)
This commit is contained in:
parent
bea98bd22a
commit
6d0f8aa893
@ -48,9 +48,24 @@ using namespace cvtest;
|
|||||||
|
|
||||||
//#define DUMP
|
//#define DUMP
|
||||||
|
|
||||||
struct HOG : testing::TestWithParam<cv::gpu::DeviceInfo>, 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>
|
||||||
{
|
{
|
||||||
cv::gpu::DeviceInfo devInfo;
|
cv::gpu::DeviceInfo devInfo;
|
||||||
|
cv::Ptr<HogForTest> hog;
|
||||||
|
|
||||||
#ifdef DUMP
|
#ifdef DUMP
|
||||||
std::ofstream f;
|
std::ofstream f;
|
||||||
@ -69,6 +84,8 @@ struct HOG : testing::TestWithParam<cv::gpu::DeviceInfo>, cv::gpu::HOGDescriptor
|
|||||||
devInfo = GetParam();
|
devInfo = GetParam();
|
||||||
|
|
||||||
cv::gpu::setDevice(devInfo.deviceID());
|
cv::gpu::setDevice(devInfo.deviceID());
|
||||||
|
|
||||||
|
hog = new HogForTest;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DUMP
|
#ifdef DUMP
|
||||||
@ -126,39 +143,39 @@ struct HOG : testing::TestWithParam<cv::gpu::DeviceInfo>, cv::gpu::HOGDescriptor
|
|||||||
|
|
||||||
void testDetect(const cv::Mat& img)
|
void testDetect(const cv::Mat& img)
|
||||||
{
|
{
|
||||||
gamma_correction = false;
|
hog->gamma_correction = false;
|
||||||
setSVMDetector(cv::gpu::HOGDescriptor::getDefaultPeopleDetector());
|
hog->setSVMDetector(cv::gpu::HOGDescriptor::getDefaultPeopleDetector());
|
||||||
|
|
||||||
std::vector<cv::Point> locations;
|
std::vector<cv::Point> locations;
|
||||||
|
|
||||||
// Test detect
|
// Test detect
|
||||||
detect(loadMat(img), locations, 0);
|
hog->detect(loadMat(img), locations, 0);
|
||||||
|
|
||||||
#ifdef DUMP
|
#ifdef DUMP
|
||||||
dump(cv::Mat(block_hists), locations);
|
dump(cv::Mat(hog->getBlockHist()), locations);
|
||||||
#else
|
#else
|
||||||
compare(cv::Mat(block_hists), locations);
|
compare(cv::Mat(hog->getBlockHists()), locations);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Test detect on smaller image
|
// Test detect on smaller image
|
||||||
cv::Mat img2;
|
cv::Mat img2;
|
||||||
cv::resize(img, img2, cv::Size(img.cols / 2, img.rows / 2));
|
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
|
#ifdef DUMP
|
||||||
dump(cv::Mat(block_hists), locations);
|
dump(cv::Mat(hog->getBlockHist()), locations);
|
||||||
#else
|
#else
|
||||||
compare(cv::Mat(block_hists), locations);
|
compare(cv::Mat(hog->getBlockHists()), locations);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Test detect on greater image
|
// Test detect on greater image
|
||||||
cv::resize(img, img2, cv::Size(img.cols * 2, img.rows * 2));
|
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
|
#ifdef DUMP
|
||||||
dump(cv::Mat(block_hists), locations);
|
dump(cv::Mat(hog->getBlockHist()), locations);
|
||||||
#else
|
#else
|
||||||
compare(cv::Mat(block_hists), locations);
|
compare(cv::Mat(hog->getBlockHists()), locations);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -216,8 +233,8 @@ GPU_TEST_P(HOG, GetDescriptors)
|
|||||||
|
|
||||||
// Convert train images into feature vectors (train table)
|
// Convert train images into feature vectors (train table)
|
||||||
cv::gpu::GpuMat descriptors, descriptors_by_cols;
|
cv::gpu::GpuMat descriptors, descriptors_by_cols;
|
||||||
getDescriptors(d_img, win_size, descriptors, DESCR_FORMAT_ROW_BY_ROW);
|
hog->getDescriptors(d_img, hog->win_size, descriptors, cv::gpu::HOGDescriptor::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_by_cols, cv::gpu::HOGDescriptor::DESCR_FORMAT_COL_BY_COL);
|
||||||
|
|
||||||
// Check size of the result train table
|
// Check size of the result train table
|
||||||
wins_per_img_x = 3;
|
wins_per_img_x = 3;
|
||||||
@ -251,39 +268,39 @@ GPU_TEST_P(HOG, GetDescriptors)
|
|||||||
img_rgb = readImage("hog/positive1.png");
|
img_rgb = readImage("hog/positive1.png");
|
||||||
ASSERT_TRUE(!img_rgb.empty());
|
ASSERT_TRUE(!img_rgb.empty());
|
||||||
cv::cvtColor(img_rgb, img, CV_BGR2BGRA);
|
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
|
// 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");
|
img_rgb = readImage("hog/positive2.png");
|
||||||
ASSERT_TRUE(!img_rgb.empty());
|
ASSERT_TRUE(!img_rgb.empty());
|
||||||
cv::cvtColor(img_rgb, img, CV_BGR2BGRA);
|
cv::cvtColor(img_rgb, img, CV_BGR2BGRA);
|
||||||
computeBlockHistograms(cv::gpu::GpuMat(img));
|
hog->computeBlockHistograms(cv::gpu::GpuMat(img));
|
||||||
compare_inner_parts(cv::Mat(block_hists), cv::Mat(descriptors.rowRange(1, 2)));
|
compare_inner_parts(cv::Mat(hog->getBlockHists()), cv::Mat(descriptors.rowRange(1, 2)));
|
||||||
|
|
||||||
img_rgb = readImage("hog/negative1.png");
|
img_rgb = readImage("hog/negative1.png");
|
||||||
ASSERT_TRUE(!img_rgb.empty());
|
ASSERT_TRUE(!img_rgb.empty());
|
||||||
cv::cvtColor(img_rgb, img, CV_BGR2BGRA);
|
cv::cvtColor(img_rgb, img, CV_BGR2BGRA);
|
||||||
computeBlockHistograms(cv::gpu::GpuMat(img));
|
hog->computeBlockHistograms(cv::gpu::GpuMat(img));
|
||||||
compare_inner_parts(cv::Mat(block_hists), cv::Mat(descriptors.rowRange(2, 3)));
|
compare_inner_parts(cv::Mat(hog->getBlockHists()), cv::Mat(descriptors.rowRange(2, 3)));
|
||||||
|
|
||||||
img_rgb = readImage("hog/negative2.png");
|
img_rgb = readImage("hog/negative2.png");
|
||||||
ASSERT_TRUE(!img_rgb.empty());
|
ASSERT_TRUE(!img_rgb.empty());
|
||||||
cv::cvtColor(img_rgb, img, CV_BGR2BGRA);
|
cv::cvtColor(img_rgb, img, CV_BGR2BGRA);
|
||||||
computeBlockHistograms(cv::gpu::GpuMat(img));
|
hog->computeBlockHistograms(cv::gpu::GpuMat(img));
|
||||||
compare_inner_parts(cv::Mat(block_hists), cv::Mat(descriptors.rowRange(3, 4)));
|
compare_inner_parts(cv::Mat(hog->getBlockHists()), cv::Mat(descriptors.rowRange(3, 4)));
|
||||||
|
|
||||||
img_rgb = readImage("hog/positive3.png");
|
img_rgb = readImage("hog/positive3.png");
|
||||||
ASSERT_TRUE(!img_rgb.empty());
|
ASSERT_TRUE(!img_rgb.empty());
|
||||||
cv::cvtColor(img_rgb, img, CV_BGR2BGRA);
|
cv::cvtColor(img_rgb, img, CV_BGR2BGRA);
|
||||||
computeBlockHistograms(cv::gpu::GpuMat(img));
|
hog->computeBlockHistograms(cv::gpu::GpuMat(img));
|
||||||
compare_inner_parts(cv::Mat(block_hists), cv::Mat(descriptors.rowRange(4, 5)));
|
compare_inner_parts(cv::Mat(hog->getBlockHists()), cv::Mat(descriptors.rowRange(4, 5)));
|
||||||
|
|
||||||
img_rgb = readImage("hog/negative3.png");
|
img_rgb = readImage("hog/negative3.png");
|
||||||
ASSERT_TRUE(!img_rgb.empty());
|
ASSERT_TRUE(!img_rgb.empty());
|
||||||
cv::cvtColor(img_rgb, img, CV_BGR2BGRA);
|
cv::cvtColor(img_rgb, img, CV_BGR2BGRA);
|
||||||
computeBlockHistograms(cv::gpu::GpuMat(img));
|
hog->computeBlockHistograms(cv::gpu::GpuMat(img));
|
||||||
compare_inner_parts(cv::Mat(block_hists), cv::Mat(descriptors.rowRange(5, 6)));
|
compare_inner_parts(cv::Mat(hog->getBlockHists()), cv::Mat(descriptors.rowRange(5, 6)));
|
||||||
}
|
}
|
||||||
|
|
||||||
INSTANTIATE_TEST_CASE_P(GPU_ObjDetect, HOG, ALL_DEVICES);
|
INSTANTIATE_TEST_CASE_P(GPU_ObjDetect, HOG, ALL_DEVICES);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user