提交 f4f38fcc 编写于 作者: V Vladislav Vinogradov

fixed gpu test failure on empty test data

上级 a5f38806
......@@ -43,50 +43,35 @@
#ifdef HAVE_CUDA
struct StereoTest : testing::TestWithParam<cv::gpu::DeviceInfo>
{
static cv::Mat img_l;
static cv::Mat img_r;
static cv::Mat img_template;
static void TearDownTestCase()
{
img_l.release();
img_r.release();
img_template.release();
}
cv::gpu::DeviceInfo devInfo;
//////////////////////////////////////////////////////////////////////////
// BlockMatching
struct StereoBlockMatching : testing::TestWithParam<cv::gpu::DeviceInfo>
{
cv::Mat img_l;
cv::Mat img_r;
cv::Mat img_template;
cv::gpu::DeviceInfo devInfo;
virtual void SetUp()
{
devInfo = GetParam();
cv::gpu::setDevice(devInfo.deviceID());
}
};
cv::Mat StereoTest::img_l;
cv::Mat StereoTest::img_r;
cv::Mat StereoTest::img_template;
//////////////////////////////////////////////////////////////////////////
// BlockMatching
struct StereoBlockMatching : StereoTest
{
static void SetUpTestCase()
{
img_l = readImage("stereobm/aloe-L.png", CV_LOAD_IMAGE_GRAYSCALE);
img_r = readImage("stereobm/aloe-R.png", CV_LOAD_IMAGE_GRAYSCALE);
img_template = readImage("stereobm/aloe-disp.png", CV_LOAD_IMAGE_GRAYSCALE);
ASSERT_FALSE(img_l.empty());
ASSERT_FALSE(img_r.empty());
ASSERT_FALSE(img_template.empty());
}
};
TEST_P(StereoBlockMatching, Regression)
{
ASSERT_TRUE(!img_l.empty() && !img_r.empty() && !img_template.empty());
PRINT_PARAM(devInfo);
cv::Mat disp;
......@@ -110,20 +95,32 @@ INSTANTIATE_TEST_CASE_P(Calib3D, StereoBlockMatching, testing::ValuesIn(devices(
//////////////////////////////////////////////////////////////////////////
// BeliefPropagation
struct StereoBeliefPropagation : StereoTest
struct StereoBeliefPropagation : testing::TestWithParam<cv::gpu::DeviceInfo>
{
static void SetUpTestCase()
cv::Mat img_l;
cv::Mat img_r;
cv::Mat img_template;
cv::gpu::DeviceInfo devInfo;
virtual void SetUp()
{
devInfo = GetParam();
cv::gpu::setDevice(devInfo.deviceID());
img_l = readImage("stereobp/aloe-L.png");
img_r = readImage("stereobp/aloe-R.png");
img_template = readImage("stereobp/aloe-disp.png", CV_LOAD_IMAGE_GRAYSCALE);
ASSERT_FALSE(img_l.empty());
ASSERT_FALSE(img_r.empty());
ASSERT_FALSE(img_template.empty());
}
};
TEST_P(StereoBeliefPropagation, Regression)
{
ASSERT_TRUE(!img_l.empty() && !img_r.empty() && !img_template.empty());
PRINT_PARAM(devInfo);
cv::Mat disp;
......@@ -147,29 +144,36 @@ INSTANTIATE_TEST_CASE_P(Calib3D, StereoBeliefPropagation, testing::ValuesIn(devi
//////////////////////////////////////////////////////////////////////////
// ConstantSpaceBP
struct StereoConstantSpaceBP : StereoTest
struct StereoConstantSpaceBP : testing::TestWithParam<cv::gpu::DeviceInfo>
{
static void SetUpTestCase()
{
img_l = readImage("csstereobp/aloe-L.png");
img_r = readImage("csstereobp/aloe-R.png");
}
cv::Mat img_l;
cv::Mat img_r;
cv::Mat img_template;
cv::gpu::DeviceInfo devInfo;
virtual void SetUp()
{
StereoTest::SetUp();
devInfo = GetParam();
if (supportFeature(GetParam(), cv::gpu::FEATURE_SET_COMPUTE_20))
cv::gpu::setDevice(devInfo.deviceID());
img_l = readImage("csstereobp/aloe-L.png");
img_r = readImage("csstereobp/aloe-R.png");
if (supportFeature(devInfo, cv::gpu::FEATURE_SET_COMPUTE_20))
img_template = readImage("csstereobp/aloe-disp.png", CV_LOAD_IMAGE_GRAYSCALE);
else
img_template = readImage("csstereobp/aloe-disp_CC1X.png", CV_LOAD_IMAGE_GRAYSCALE);
ASSERT_FALSE(img_l.empty());
ASSERT_FALSE(img_r.empty());
ASSERT_FALSE(img_template.empty());
}
};
TEST_P(StereoConstantSpaceBP, Regression)
{
ASSERT_TRUE(!img_l.empty() && !img_r.empty() && !img_template.empty());
PRINT_PARAM(devInfo);
cv::Mat disp;
......
......@@ -48,29 +48,10 @@
struct SURF : testing::TestWithParam<cv::gpu::DeviceInfo>
{
static cv::Mat image;
static cv::Mat mask;
static std::vector<cv::KeyPoint> keypoints_gold;
static std::vector<float> descriptors_gold;
static void SetUpTestCase()
{
image = readImage("features2d/aloe.png", CV_LOAD_IMAGE_GRAYSCALE);
mask = cv::Mat(image.size(), CV_8UC1, cv::Scalar::all(1));
mask(cv::Range(0, image.rows / 2), cv::Range(0, image.cols / 2)).setTo(cv::Scalar::all(0));
cv::SURF fdetector_gold; fdetector_gold.extended = false;
fdetector_gold(image, mask, keypoints_gold, descriptors_gold);
}
static void TearDownTestCase()
{
image.release();
mask.release();
keypoints_gold.clear();
descriptors_gold.clear();
}
cv::Mat image;
cv::Mat mask;
std::vector<cv::KeyPoint> keypoints_gold;
std::vector<float> descriptors_gold;
cv::gpu::DeviceInfo devInfo;
......@@ -79,6 +60,15 @@ struct SURF : testing::TestWithParam<cv::gpu::DeviceInfo>
devInfo = GetParam();
cv::gpu::setDevice(devInfo.deviceID());
image = readImage("features2d/aloe.png", CV_LOAD_IMAGE_GRAYSCALE);
ASSERT_FALSE(image.empty());
mask = cv::Mat(image.size(), CV_8UC1, cv::Scalar::all(1));
mask(cv::Range(0, image.rows / 2), cv::Range(0, image.cols / 2)).setTo(cv::Scalar::all(0));
cv::SURF fdetector_gold; fdetector_gold.extended = false;
fdetector_gold(image, mask, keypoints_gold, descriptors_gold);
}
bool isSimilarKeypoints(const cv::KeyPoint& p1, const cv::KeyPoint& p2)
......@@ -98,11 +88,6 @@ struct SURF : testing::TestWithParam<cv::gpu::DeviceInfo>
}
};
cv::Mat SURF::image;
cv::Mat SURF::mask;
std::vector<cv::KeyPoint> SURF::keypoints_gold;
std::vector<float> SURF::descriptors_gold;
TEST_P(SURF, EmptyDataTest)
{
PRINT_PARAM(devInfo);
......@@ -123,8 +108,6 @@ TEST_P(SURF, EmptyDataTest)
TEST_P(SURF, Accuracy)
{
ASSERT_TRUE(!image.empty());
PRINT_PARAM(devInfo);
// Compute keypoints.
......@@ -161,11 +144,11 @@ TEST_P(SURF, Accuracy)
float dist = (float)cv::norm(p1.pt - p2.pt);
if (dist < maxPtDif &&
fabs(p1.size - p2.size) < maxSizeDif &&
abs(p1.angle - p2.angle) < maxAngleDif &&
abs(p1.response - p2.response) < maxResponseDif &&
p1.octave == p2.octave &&
p1.class_id == p2.class_id )
fabs(p1.size - p2.size) < maxSizeDif &&
abs(p1.angle - p2.angle) < maxAngleDif &&
abs(p1.response - p2.response) < maxResponseDif &&
p1.octave == p2.octave &&
p1.class_id == p2.class_id)
{
++validCount;
}
......
......@@ -43,39 +43,20 @@
#ifdef HAVE_CUDA
struct FilterTest
namespace
{
static cv::Mat img_rgba;
static cv::Mat img_gray;
static void SetUpTestCase()
double checkNorm(const cv::Mat& m1, const cv::Mat& m2, const cv::Size& ksize)
{
cv::Mat img = readImage("stereobp/aloe-L.png");
cv::cvtColor(img, img_rgba, CV_BGR2BGRA);
cv::cvtColor(img, img_gray, CV_BGR2GRAY);
cv::Rect roi(ksize.width, ksize.height, m1.cols - 2 * ksize.width, m1.rows - 2 * ksize.height);
cv::Mat m1ROI = m1(roi);
cv::Mat m2ROI = m2(roi);
return ::checkNorm(m1ROI, m2ROI);
}
static void TearDownTestCase()
double checkNorm(const cv::Mat& m1, const cv::Mat& m2, int ksize)
{
img_rgba.release();
img_gray.release();
return checkNorm(m1, m2, cv::Size(ksize, ksize));
}
};
cv::Mat FilterTest::img_rgba;
cv::Mat FilterTest::img_gray;
static double checkNorm(const cv::Mat& m1, const cv::Mat& m2, const cv::Size& ksize)
{
cv::Rect roi(ksize.width, ksize.height, m1.cols - 2 * ksize.width, m1.rows - 2 * ksize.height);
cv::Mat m1ROI = m1(roi);
cv::Mat m2ROI = m2(roi);
return checkNorm(m1ROI, m2ROI);
}
static double checkNorm(const cv::Mat& m1, const cv::Mat& m2, int ksize)
{
return checkNorm(m1, m2, cv::Size(ksize, ksize));
}
#define EXPECT_MAT_NEAR_KSIZE(mat1, mat2, ksize, eps) \
......@@ -88,16 +69,16 @@ static double checkNorm(const cv::Mat& m1, const cv::Mat& m2, int ksize)
/////////////////////////////////////////////////////////////////////////////////////////////////
// blur
struct Blur : FilterTest, testing::TestWithParam< std::tr1::tuple<cv::gpu::DeviceInfo, int, int> >
struct Blur : testing::TestWithParam< std::tr1::tuple<cv::gpu::DeviceInfo, int, int> >
{
cv::gpu::DeviceInfo devInfo;
cv::Size ksize;
cv::Mat img_rgba;
cv::Mat img_gray;
cv::Mat dst_gold_rgba;
cv::Mat dst_gold_gray;
using FilterTest::SetUpTestCase;
using FilterTest::TearDownTestCase;
virtual void SetUp()
{
......@@ -105,6 +86,12 @@ struct Blur : FilterTest, testing::TestWithParam< std::tr1::tuple<cv::gpu::Devic
ksize = cv::Size(std::tr1::get<1>(GetParam()), std::tr1::get<2>(GetParam()));
cv::gpu::setDevice(devInfo.deviceID());
cv::Mat img = readImage("stereobp/aloe-L.png");
ASSERT_FALSE(img.empty());
cv::cvtColor(img, img_rgba, CV_BGR2BGRA);
cv::cvtColor(img, img_gray, CV_BGR2GRAY);
cv::blur(img_rgba, dst_gold_rgba, ksize);
cv::blur(img_gray, dst_gold_gray, ksize);
......@@ -113,8 +100,6 @@ struct Blur : FilterTest, testing::TestWithParam< std::tr1::tuple<cv::gpu::Devic
TEST_P(Blur, Accuracy)
{
ASSERT_TRUE(!img_rgba.empty() && !img_gray.empty());
PRINT_PARAM(devInfo);
PRINT_PARAM(ksize);
......@@ -144,17 +129,17 @@ INSTANTIATE_TEST_CASE_P(Filter, Blur, testing::Combine(
/////////////////////////////////////////////////////////////////////////////////////////////////
// sobel
struct Sobel : FilterTest, testing::TestWithParam< std::tr1::tuple<cv::gpu::DeviceInfo, int, std::pair<int, int> > >
struct Sobel : testing::TestWithParam< std::tr1::tuple<cv::gpu::DeviceInfo, int, std::pair<int, int> > >
{
cv::gpu::DeviceInfo devInfo;
int ksize;
int dx, dy;
cv::Mat img_rgba;
cv::Mat img_gray;
cv::Mat dst_gold_rgba;
cv::Mat dst_gold_gray;
using FilterTest::SetUpTestCase;
using FilterTest::TearDownTestCase;
virtual void SetUp()
{
......@@ -165,6 +150,12 @@ struct Sobel : FilterTest, testing::TestWithParam< std::tr1::tuple<cv::gpu::Devi
cv::gpu::setDevice(devInfo.deviceID());
cv::Mat img = readImage("stereobp/aloe-L.png");
ASSERT_FALSE(img.empty());
cv::cvtColor(img, img_rgba, CV_BGR2BGRA);
cv::cvtColor(img, img_gray, CV_BGR2GRAY);
cv::Sobel(img_rgba, dst_gold_rgba, -1, dx, dy, ksize);
cv::Sobel(img_gray, dst_gold_gray, -1, dx, dy, ksize);
}
......@@ -172,8 +163,6 @@ struct Sobel : FilterTest, testing::TestWithParam< std::tr1::tuple<cv::gpu::Devi
TEST_P(Sobel, Accuracy)
{
ASSERT_TRUE(!img_rgba.empty() && !img_gray.empty());
PRINT_PARAM(devInfo);
PRINT_PARAM(ksize);
PRINT_PARAM(dx);
......@@ -205,16 +194,16 @@ INSTANTIATE_TEST_CASE_P(Filter, Sobel, testing::Combine(
/////////////////////////////////////////////////////////////////////////////////////////////////
// scharr
struct Scharr : FilterTest, testing::TestWithParam< std::tr1::tuple<cv::gpu::DeviceInfo, std::pair<int, int> > >
struct Scharr : testing::TestWithParam< std::tr1::tuple<cv::gpu::DeviceInfo, std::pair<int, int> > >
{
cv::gpu::DeviceInfo devInfo;
int dx, dy;
cv::Mat img_rgba;
cv::Mat img_gray;
cv::Mat dst_gold_rgba;
cv::Mat dst_gold_gray;
using FilterTest::SetUpTestCase;
using FilterTest::TearDownTestCase;
virtual void SetUp()
{
......@@ -223,6 +212,12 @@ struct Scharr : FilterTest, testing::TestWithParam< std::tr1::tuple<cv::gpu::Dev
dx = d.first; dy = d.second;
cv::gpu::setDevice(devInfo.deviceID());
cv::Mat img = readImage("stereobp/aloe-L.png");
ASSERT_FALSE(img.empty());
cv::cvtColor(img, img_rgba, CV_BGR2BGRA);
cv::cvtColor(img, img_gray, CV_BGR2GRAY);
cv::Scharr(img_rgba, dst_gold_rgba, -1, dx, dy);
cv::Scharr(img_gray, dst_gold_gray, -1, dx, dy);
......@@ -231,8 +226,6 @@ struct Scharr : FilterTest, testing::TestWithParam< std::tr1::tuple<cv::gpu::Dev
TEST_P(Scharr, Accuracy)
{
ASSERT_TRUE(!img_rgba.empty() && !img_gray.empty());
PRINT_PARAM(devInfo);
PRINT_PARAM(dx);
PRINT_PARAM(dy);
......@@ -262,18 +255,18 @@ INSTANTIATE_TEST_CASE_P(Filter, Scharr, testing::Combine(
/////////////////////////////////////////////////////////////////////////////////////////////////
// gaussianBlur
struct GaussianBlur : FilterTest, testing::TestWithParam< std::tr1::tuple<cv::gpu::DeviceInfo, int, int> >
struct GaussianBlur : testing::TestWithParam< std::tr1::tuple<cv::gpu::DeviceInfo, int, int> >
{
cv::gpu::DeviceInfo devInfo;
cv::Size ksize;
cv::Mat img_rgba;
cv::Mat img_gray;
double sigma1, sigma2;
cv::Mat dst_gold_rgba;
cv::Mat dst_gold_gray;
using FilterTest::SetUpTestCase;
using FilterTest::TearDownTestCase;
virtual void SetUp()
{
......@@ -282,6 +275,12 @@ struct GaussianBlur : FilterTest, testing::TestWithParam< std::tr1::tuple<cv::gp
cv::gpu::setDevice(devInfo.deviceID());
cv::Mat img = readImage("stereobp/aloe-L.png");
ASSERT_FALSE(img.empty());
cv::cvtColor(img, img_rgba, CV_BGR2BGRA);
cv::cvtColor(img, img_gray, CV_BGR2GRAY);
cv::RNG& rng = cvtest::TS::ptr()->get_rng();
sigma1 = rng.uniform(0.1, 1.0);
......@@ -294,8 +293,6 @@ struct GaussianBlur : FilterTest, testing::TestWithParam< std::tr1::tuple<cv::gp
TEST_P(GaussianBlur, Accuracy)
{
ASSERT_TRUE(!img_rgba.empty() && !img_gray.empty());
PRINT_PARAM(devInfo);
PRINT_PARAM(ksize);
PRINT_PARAM(sigma1);
......@@ -327,16 +324,16 @@ INSTANTIATE_TEST_CASE_P(Filter, GaussianBlur, testing::Combine(
/////////////////////////////////////////////////////////////////////////////////////////////////
// laplacian
struct Laplacian : FilterTest, testing::TestWithParam< std::tr1::tuple<cv::gpu::DeviceInfo, int> >
struct Laplacian : testing::TestWithParam< std::tr1::tuple<cv::gpu::DeviceInfo, int> >
{
cv::gpu::DeviceInfo devInfo;
int ksize;
cv::Mat img_rgba;
cv::Mat img_gray;
cv::Mat dst_gold_rgba;
cv::Mat dst_gold_gray;
using FilterTest::SetUpTestCase;
using FilterTest::TearDownTestCase;
virtual void SetUp()
{
......@@ -344,6 +341,12 @@ struct Laplacian : FilterTest, testing::TestWithParam< std::tr1::tuple<cv::gpu::
ksize = std::tr1::get<1>(GetParam());
cv::gpu::setDevice(devInfo.deviceID());
cv::Mat img = readImage("stereobp/aloe-L.png");
ASSERT_FALSE(img.empty());
cv::cvtColor(img, img_rgba, CV_BGR2BGRA);
cv::cvtColor(img, img_gray, CV_BGR2GRAY);
cv::Laplacian(img_rgba, dst_gold_rgba, -1, ksize);
cv::Laplacian(img_gray, dst_gold_gray, -1, ksize);
......@@ -352,8 +355,6 @@ struct Laplacian : FilterTest, testing::TestWithParam< std::tr1::tuple<cv::gpu::
TEST_P(Laplacian, Accuracy)
{
ASSERT_TRUE(!img_rgba.empty() && !img_gray.empty());
PRINT_PARAM(devInfo);
PRINT_PARAM(ksize);
......@@ -382,17 +383,17 @@ INSTANTIATE_TEST_CASE_P(Filter, Laplacian, testing::Combine(
/////////////////////////////////////////////////////////////////////////////////////////////////
// erode
struct Erode : FilterTest, testing::TestWithParam<cv::gpu::DeviceInfo>
struct Erode : testing::TestWithParam<cv::gpu::DeviceInfo>
{
cv::gpu::DeviceInfo devInfo;
cv::Mat img_rgba;
cv::Mat img_gray;
cv::Mat kernel;
cv::Mat dst_gold_rgba;
cv::Mat dst_gold_gray;
using FilterTest::SetUpTestCase;
using FilterTest::TearDownTestCase;
virtual void SetUp()
{
......@@ -401,6 +402,12 @@ struct Erode : FilterTest, testing::TestWithParam<cv::gpu::DeviceInfo>
cv::gpu::setDevice(devInfo.deviceID());
kernel = cv::Mat::ones(3, 3, CV_8U);
cv::Mat img = readImage("stereobp/aloe-L.png");
ASSERT_FALSE(img.empty());
cv::cvtColor(img, img_rgba, CV_BGR2BGRA);
cv::cvtColor(img, img_gray, CV_BGR2GRAY);
cv::erode(img_rgba, dst_gold_rgba, kernel);
cv::erode(img_gray, dst_gold_gray, kernel);
......@@ -409,8 +416,6 @@ struct Erode : FilterTest, testing::TestWithParam<cv::gpu::DeviceInfo>
TEST_P(Erode, Accuracy)
{
ASSERT_TRUE(!img_rgba.empty() && !img_gray.empty());
PRINT_PARAM(devInfo);
cv::Mat dst_rgba;
......@@ -436,17 +441,17 @@ INSTANTIATE_TEST_CASE_P(Filter, Erode, testing::ValuesIn(devices()));
/////////////////////////////////////////////////////////////////////////////////////////////////
// dilate
struct Dilate : FilterTest, testing::TestWithParam<cv::gpu::DeviceInfo>
struct Dilate : testing::TestWithParam<cv::gpu::DeviceInfo>
{
cv::gpu::DeviceInfo devInfo;
cv::Mat img_rgba;
cv::Mat img_gray;
cv::Mat kernel;
cv::Mat dst_gold_rgba;
cv::Mat dst_gold_gray;
using FilterTest::SetUpTestCase;
using FilterTest::TearDownTestCase;
virtual void SetUp()
{
......@@ -455,6 +460,12 @@ struct Dilate : FilterTest, testing::TestWithParam<cv::gpu::DeviceInfo>
cv::gpu::setDevice(devInfo.deviceID());
kernel = cv::Mat::ones(3, 3, CV_8U);
cv::Mat img = readImage("stereobp/aloe-L.png");
ASSERT_FALSE(img.empty());
cv::cvtColor(img, img_rgba, CV_BGR2BGRA);
cv::cvtColor(img, img_gray, CV_BGR2GRAY);
cv::dilate(img_rgba, dst_gold_rgba, kernel);
cv::dilate(img_gray, dst_gold_gray, kernel);
......@@ -463,8 +474,6 @@ struct Dilate : FilterTest, testing::TestWithParam<cv::gpu::DeviceInfo>
TEST_P(Dilate, Accuracy)
{
ASSERT_TRUE(!img_rgba.empty() && !img_gray.empty());
PRINT_PARAM(devInfo);
cv::Mat dst_rgba;
......@@ -493,18 +502,18 @@ INSTANTIATE_TEST_CASE_P(Filter, Dilate, testing::ValuesIn(devices()));
static const int morphOps[] = {cv::MORPH_OPEN, CV_MOP_CLOSE, CV_MOP_GRADIENT, CV_MOP_TOPHAT, CV_MOP_BLACKHAT};
static const char* morphOps_str[] = {"MORPH_OPEN", "MOP_CLOSE", "MOP_GRADIENT", "MOP_TOPHAT", "MOP_BLACKHAT"};
struct MorphEx : FilterTest, testing::TestWithParam< std::tr1::tuple<cv::gpu::DeviceInfo, int> >
struct MorphEx : testing::TestWithParam< std::tr1::tuple<cv::gpu::DeviceInfo, int> >
{
cv::gpu::DeviceInfo devInfo;
int morphOpsIdx;
cv::Mat img_rgba;
cv::Mat img_gray;
cv::Mat kernel;
cv::Mat dst_gold_rgba;
cv::Mat dst_gold_gray;
using FilterTest::SetUpTestCase;
using FilterTest::TearDownTestCase;
virtual void SetUp()
{
......@@ -512,9 +521,15 @@ struct MorphEx : FilterTest, testing::TestWithParam< std::tr1::tuple<cv::gpu::De
morphOpsIdx = std::tr1::get<1>(GetParam());
cv::gpu::setDevice(devInfo.deviceID());
cv::Mat img = readImage("stereobp/aloe-L.png");
ASSERT_FALSE(img.empty());
cv::cvtColor(img, img_rgba, CV_BGR2BGRA);
cv::cvtColor(img, img_gray, CV_BGR2GRAY);
kernel = cv::Mat::ones(3, 3, CV_8U);
cv::morphologyEx(img_rgba, dst_gold_rgba, morphOps[morphOpsIdx], kernel);
cv::morphologyEx(img_gray, dst_gold_gray, morphOps[morphOpsIdx], kernel);
}
......@@ -522,8 +537,6 @@ struct MorphEx : FilterTest, testing::TestWithParam< std::tr1::tuple<cv::gpu::De
TEST_P(MorphEx, Accuracy)
{
ASSERT_TRUE(!img_rgba.empty() && !img_gray.empty());
const char* morphOpStr = morphOps_str[morphOpsIdx];
PRINT_PARAM(devInfo);
......
......@@ -50,7 +50,7 @@ struct CV_GpuHogDetectTestRunner : cv::gpu::HOGDescriptor
void run()
{
cv::Mat img_rgb = readImage("hog/road.png");
ASSERT_TRUE(!img_rgb.empty());
ASSERT_FALSE(img_rgb.empty());
#ifdef DUMP
f.open((std::string(cvtest::TS::ptr()->get_data_path()) + "hog/expected_output.bin").c_str(), std::ios_base::binary);
......@@ -201,7 +201,7 @@ struct CV_GpuHogGetDescriptorsTestRunner : cv::gpu::HOGDescriptor
{
// Load image (e.g. train data, composed from windows)
cv::Mat img_rgb = readImage("hog/train_data.png");
ASSERT_TRUE(!img_rgb.empty());
ASSERT_FALSE(img_rgb.empty());
// Convert to C4
cv::Mat img;
......
......@@ -441,21 +441,9 @@ INSTANTIATE_TEST_CASE_P(ImgProc, Integral, testing::ValuesIn(devices()));
struct CvtColor : testing::TestWithParam< std::tr1::tuple<cv::gpu::DeviceInfo, int> >
{
static cv::Mat imgBase;
static void SetUpTestCase()
{
imgBase = readImage("stereobm/aloe-L.png");
}
static void TearDownTestCase()
{
imgBase.release();
}
cv::gpu::DeviceInfo devInfo;
int type;
cv::Mat img;
virtual void SetUp()
......@@ -463,18 +451,17 @@ struct CvtColor : testing::TestWithParam< std::tr1::tuple<cv::gpu::DeviceInfo, i
devInfo = std::tr1::get<0>(GetParam());
type = std::tr1::get<1>(GetParam());
cv::gpu::setDevice(devInfo.deviceID());
cv::gpu::setDevice(devInfo.deviceID());
cv::Mat imgBase = readImage("stereobm/aloe-L.png");
ASSERT_FALSE(imgBase.empty());
imgBase.convertTo(img, type, type == CV_32F ? 1.0 / 255.0 : 1.0);
}
};
cv::Mat CvtColor::imgBase;
TEST_P(CvtColor, BGR2RGB)
{
ASSERT_TRUE(!img.empty());
PRINT_PARAM(devInfo);
PRINT_TYPE(type);
......@@ -497,8 +484,6 @@ TEST_P(CvtColor, BGR2RGB)
TEST_P(CvtColor, BGR2RGBA)
{
ASSERT_TRUE(!img.empty());
PRINT_PARAM(devInfo);
PRINT_TYPE(type);
......@@ -521,8 +506,6 @@ TEST_P(CvtColor, BGR2RGBA)
TEST_P(CvtColor, BGRA2RGB)
{
ASSERT_TRUE(!img.empty());
PRINT_PARAM(devInfo);
PRINT_TYPE(type);
......@@ -546,8 +529,6 @@ TEST_P(CvtColor, BGRA2RGB)
TEST_P(CvtColor, BGR2YCrCb)
{
ASSERT_TRUE(!img.empty());
PRINT_PARAM(devInfo);
PRINT_TYPE(type);
......@@ -570,8 +551,6 @@ TEST_P(CvtColor, BGR2YCrCb)
TEST_P(CvtColor, YCrCb2RGB)
{
ASSERT_TRUE(!img.empty());
PRINT_PARAM(devInfo);
PRINT_TYPE(type);
......@@ -595,8 +574,6 @@ TEST_P(CvtColor, YCrCb2RGB)
TEST_P(CvtColor, BGR2YUV)
{
ASSERT_TRUE(!img.empty());
PRINT_PARAM(devInfo);
PRINT_TYPE(type);
......@@ -619,8 +596,6 @@ TEST_P(CvtColor, BGR2YUV)
TEST_P(CvtColor, YUV2BGR)
{
ASSERT_TRUE(!img.empty());
PRINT_PARAM(devInfo);
PRINT_TYPE(type);
......@@ -644,8 +619,6 @@ TEST_P(CvtColor, YUV2BGR)
TEST_P(CvtColor, BGR2XYZ)
{
ASSERT_TRUE(!img.empty());
PRINT_PARAM(devInfo);
PRINT_TYPE(type);
......@@ -668,8 +641,6 @@ TEST_P(CvtColor, BGR2XYZ)
TEST_P(CvtColor, XYZ2BGR)
{
ASSERT_TRUE(!img.empty());
PRINT_PARAM(devInfo);
PRINT_TYPE(type);
......@@ -696,8 +667,6 @@ TEST_P(CvtColor, BGR2HSV)
if (type == CV_16U)
return;
ASSERT_TRUE(!img.empty());
PRINT_PARAM(devInfo);
PRINT_TYPE(type);
......@@ -723,8 +692,6 @@ TEST_P(CvtColor, HSV2BGR)
if (type == CV_16U)
return;
ASSERT_TRUE(!img.empty());
PRINT_PARAM(devInfo);
PRINT_TYPE(type);
......@@ -751,8 +718,6 @@ TEST_P(CvtColor, BGR2HSV_FULL)
if (type == CV_16U)
return;
ASSERT_TRUE(!img.empty());
PRINT_PARAM(devInfo);
PRINT_TYPE(type);
......@@ -778,8 +743,6 @@ TEST_P(CvtColor, HSV2BGR_FULL)
if (type == CV_16U)
return;
ASSERT_TRUE(!img.empty());
PRINT_PARAM(devInfo);
PRINT_TYPE(type);
......@@ -806,8 +769,6 @@ TEST_P(CvtColor, BGR2HLS)
if (type == CV_16U)
return;
ASSERT_TRUE(!img.empty());
PRINT_PARAM(devInfo);
PRINT_TYPE(type);
......@@ -833,8 +794,6 @@ TEST_P(CvtColor, HLS2BGR)
if (type == CV_16U)
return;
ASSERT_TRUE(!img.empty());
PRINT_PARAM(devInfo);
PRINT_TYPE(type);
......@@ -861,8 +820,6 @@ TEST_P(CvtColor, BGR2HLS_FULL)
if (type == CV_16U)
return;
ASSERT_TRUE(!img.empty());
PRINT_PARAM(devInfo);
PRINT_TYPE(type);
......@@ -888,8 +845,6 @@ TEST_P(CvtColor, HLS2BGR_FULL)
if (type == CV_16U)
return;
ASSERT_TRUE(!img.empty());
PRINT_PARAM(devInfo);
PRINT_TYPE(type);
......@@ -913,8 +868,6 @@ TEST_P(CvtColor, HLS2BGR_FULL)
TEST_P(CvtColor, BGR2GRAY)
{
ASSERT_TRUE(!img.empty());
PRINT_PARAM(devInfo);
PRINT_TYPE(type);
......@@ -937,8 +890,6 @@ TEST_P(CvtColor, BGR2GRAY)
TEST_P(CvtColor, GRAY2RGB)
{
ASSERT_TRUE(!img.empty());
PRINT_PARAM(devInfo);
PRINT_TYPE(type);
......@@ -969,21 +920,10 @@ INSTANTIATE_TEST_CASE_P(ImgProc, CvtColor, testing::Combine(
struct HistEven : testing::TestWithParam<cv::gpu::DeviceInfo>
{
static cv::Mat hsv;
static void SetUpTestCase()
{
cv::Mat img = readImage("stereobm/aloe-L.png");
cv::cvtColor(img, hsv, CV_BGR2HSV);
}
static void TearDownTestCase()
{
hsv.release();
}
cv::gpu::DeviceInfo devInfo;
cv::Mat hsv;
int hbins;
float hranges[2];
......@@ -994,6 +934,11 @@ struct HistEven : testing::TestWithParam<cv::gpu::DeviceInfo>
devInfo = GetParam();
cv::gpu::setDevice(devInfo.deviceID());
cv::Mat img = readImage("stereobm/aloe-L.png");
ASSERT_FALSE(img.empty());
cv::cvtColor(img, hsv, CV_BGR2HSV);
hbins = 30;
......@@ -1014,8 +959,6 @@ struct HistEven : testing::TestWithParam<cv::gpu::DeviceInfo>
}
};
cv::Mat HistEven::hsv;
TEST_P(HistEven, Accuracy)
{
ASSERT_TRUE(!hsv.empty());
......@@ -1146,18 +1089,6 @@ static const char* borderTypes_str[] = {"BORDER_REPLICATE", "BORDER_CONSTANT", "
struct CornerHarris : testing::TestWithParam< std::tr1::tuple<cv::gpu::DeviceInfo, int, int> >
{
static cv::Mat img;
static void SetUpTestCase()
{
img = readImage("stereobm/aloe-L.png", CV_LOAD_IMAGE_GRAYSCALE);
}
static void TearDownTestCase()
{
img.release();
}
cv::gpu::DeviceInfo devInfo;
int type;
int borderTypeIdx;
......@@ -1179,6 +1110,9 @@ struct CornerHarris : testing::TestWithParam< std::tr1::tuple<cv::gpu::DeviceInf
cv::RNG& rng = cvtest::TS::ptr()->get_rng();
cv::Mat img = readImage("stereobm/aloe-L.png", CV_LOAD_IMAGE_GRAYSCALE);
ASSERT_FALSE(img.empty());
img.convertTo(src, type, type == CV_32F ? 1.0 / 255.0 : 1.0);
blockSize = 1 + rng.next() % 5;
......@@ -1189,8 +1123,6 @@ struct CornerHarris : testing::TestWithParam< std::tr1::tuple<cv::gpu::DeviceInf
}
};
cv::Mat CornerHarris::img;
TEST_P(CornerHarris, Accuracy)
{
const char* borderTypeStr = borderTypes_str[borderTypeIdx];
......@@ -1222,18 +1154,6 @@ INSTANTIATE_TEST_CASE_P(ImgProc, CornerHarris, testing::Combine(
struct CornerMinEigen : testing::TestWithParam< std::tr1::tuple<cv::gpu::DeviceInfo, int, int> >
{
static cv::Mat img;
static void SetUpTestCase()
{
img = readImage("stereobm/aloe-L.png", CV_LOAD_IMAGE_GRAYSCALE);
}
static void TearDownTestCase()
{
img.release();
}
cv::gpu::DeviceInfo devInfo;
int type;
int borderTypeIdx;
......@@ -1250,9 +1170,12 @@ struct CornerMinEigen : testing::TestWithParam< std::tr1::tuple<cv::gpu::DeviceI
type = std::tr1::get<1>(GetParam());
borderTypeIdx = std::tr1::get<2>(GetParam());
cv::gpu::setDevice(devInfo.deviceID());
cv::gpu::setDevice(devInfo.deviceID());
cv::RNG& rng = cvtest::TS::ptr()->get_rng();
cv::Mat img = readImage("stereobm/aloe-L.png", CV_LOAD_IMAGE_GRAYSCALE);
ASSERT_FALSE(img.empty());
img.convertTo(src, type, type == CV_32F ? 1.0 / 255.0 : 1.0);
......@@ -1263,8 +1186,6 @@ struct CornerMinEigen : testing::TestWithParam< std::tr1::tuple<cv::gpu::DeviceI
}
};
cv::Mat CornerMinEigen::img;
TEST_P(CornerMinEigen, Accuracy)
{
const char* borderTypeStr = borderTypes_str[borderTypeIdx];
......@@ -1475,20 +1396,9 @@ INSTANTIATE_TEST_CASE_P(ImgProc, ReprojectImageTo3D, testing::ValuesIn(devices()
struct MeanShift : testing::TestWithParam<cv::gpu::DeviceInfo>
{
static cv::Mat rgba;
static void SetUpTestCase()
{
cv::Mat img = readImage("meanshift/cones.png");
cv::cvtColor(img, rgba, CV_BGR2BGRA);
}
static void TearDownTestCase()
{
rgba.release();
}
cv::gpu::DeviceInfo devInfo;
cv::Mat rgba;
int spatialRad;
int colorRad;
......@@ -1498,14 +1408,17 @@ struct MeanShift : testing::TestWithParam<cv::gpu::DeviceInfo>
devInfo = GetParam();
cv::gpu::setDevice(devInfo.deviceID());
cv::Mat img = readImage("meanshift/cones.png");
ASSERT_FALSE(img.empty());
cv::cvtColor(img, rgba, CV_BGR2BGRA);
spatialRad = 30;
colorRad = 30;
}
};
cv::Mat MeanShift::rgba;
TEST_P(MeanShift, Filtering)
{
cv::Mat img_template;
......@@ -1515,7 +1428,7 @@ TEST_P(MeanShift, Filtering)
else
img_template = readImage("meanshift/con_result_CC1X.png");
ASSERT_TRUE(!rgba.empty() && !img_template.empty());
ASSERT_FALSE(img_template.empty());
PRINT_PARAM(devInfo);
......@@ -1580,21 +1493,10 @@ INSTANTIATE_TEST_CASE_P(ImgProc, MeanShift, testing::ValuesIn(devices()));
struct MeanShiftSegmentation : testing::TestWithParam< std::tr1::tuple<cv::gpu::DeviceInfo, int> >
{
static cv::Mat rgba;
static void SetUpTestCase()
{
cv::Mat img = readImage("meanshift/cones.png");
cv::cvtColor(img, rgba, CV_BGR2BGRA);
}
static void TearDownTestCase()
{
rgba.release();
}
cv::gpu::DeviceInfo devInfo;
int minsize;
cv::Mat rgba;
cv::Mat dst_gold;
......@@ -1604,6 +1506,11 @@ struct MeanShiftSegmentation : testing::TestWithParam< std::tr1::tuple<cv::gpu::
minsize = std::tr1::get<1>(GetParam());
cv::gpu::setDevice(devInfo.deviceID());
cv::Mat img = readImage("meanshift/cones.png");
ASSERT_FALSE(img.empty());
cv::cvtColor(img, rgba, CV_BGR2BGRA);
std::ostringstream path;
path << "meanshift/cones_segmented_sp10_sr10_minsize" << minsize;
......@@ -1613,15 +1520,12 @@ struct MeanShiftSegmentation : testing::TestWithParam< std::tr1::tuple<cv::gpu::
path << "_CC1X.png";
dst_gold = readImage(path.str());
ASSERT_FALSE(dst_gold.empty());
}
};
cv::Mat MeanShiftSegmentation::rgba;
TEST_P(MeanShiftSegmentation, Regression)
{
ASSERT_TRUE(!rgba.empty() && !dst_gold.empty());
PRINT_PARAM(devInfo);
PRINT_PARAM(minsize);
......@@ -1768,24 +1672,10 @@ INSTANTIATE_TEST_CASE_P(ImgProc, MatchTemplate32F, testing::Combine(
struct MatchTemplate : testing::TestWithParam< std::tr1::tuple<cv::gpu::DeviceInfo, int> >
{
static cv::Mat image;
static cv::Mat pattern;
static cv::Point maxLocGold;
static void SetUpTestCase()
{
image = readImage("matchtemplate/black.png");
pattern = readImage("matchtemplate/cat.png");
cv::Mat image;
cv::Mat pattern;
maxLocGold = cv::Point(284, 12);
}
static void TearDownTestCase()
{
image.release();
pattern.release();
}
cv::Point maxLocGold;
cv::gpu::DeviceInfo devInfo;
int method;
......@@ -1796,17 +1686,19 @@ struct MatchTemplate : testing::TestWithParam< std::tr1::tuple<cv::gpu::DeviceIn
method = std::tr1::get<1>(GetParam());
cv::gpu::setDevice(devInfo.deviceID());
image = readImage("matchtemplate/black.png");
ASSERT_FALSE(image.empty());
pattern = readImage("matchtemplate/cat.png");
ASSERT_FALSE(pattern.empty());
maxLocGold = cv::Point(284, 12);
}
};
cv::Mat MatchTemplate::image;
cv::Mat MatchTemplate::pattern;
cv::Point MatchTemplate::maxLocGold;
TEST_P(MatchTemplate, FindPatternInBlack)
{
ASSERT_TRUE(!image.empty() && !pattern.empty());
const char* matchTemplateMethodStr = matchTemplateMethods[method];
PRINT_PARAM(devInfo);
......@@ -1919,6 +1811,7 @@ struct Dft : testing::TestWithParam<cv::gpu::DeviceInfo>
}
};
static void testC2C(const std::string& hint, int cols, int rows, int flags, bool inplace)
{
PRINT_PARAM(hint);
......@@ -2143,36 +2036,47 @@ INSTANTIATE_TEST_CASE_P(ImgProc, Blend, testing::Combine(
// pyrDown
struct PyrDown : testing::TestWithParam<cv::gpu::DeviceInfo>
{
{
cv::gpu::DeviceInfo devInfo;
cv::Mat src;
cv::Mat dst_gold;
virtual void SetUp()
{
devInfo = GetParam();
cv::gpu::setDevice(devInfo.deviceID());
cv::Mat img = readImage("stereobm/aloe-L.png");
ASSERT_FALSE(img.empty());
img.convertTo(src, CV_16S);
cv::pyrDown(src, dst_gold);
}
};
TEST_P(PyrDown, Accuracy)
{
PRINT_PARAM(devInfo);
cv::Mat dst;
cv::Mat src;
readImage("stereobm/aloe-L.png").convertTo(src, CV_16S);
cv::Mat dst_gold;
cv::pyrDown(src, dst_gold);
cv::gpu::GpuMat d_dst;
cv::gpu::pyrDown(cv::gpu::GpuMat(src), d_dst);
cv::Mat dst_mine = d_dst;
ASSERT_NO_THROW(
cv::gpu::GpuMat d_dst;
cv::gpu::pyrDown(cv::gpu::GpuMat(src), d_dst);
d_dst.download(dst);
);
ASSERT_EQ(dst_gold.cols, dst_mine.cols);
ASSERT_EQ(dst_gold.rows, dst_mine.rows);
ASSERT_EQ(dst_gold.type(), dst_mine.type());
ASSERT_EQ(dst_gold.cols, dst.cols);
ASSERT_EQ(dst_gold.rows, dst.rows);
ASSERT_EQ(dst_gold.type(), dst.type());
double err = cvtest::crossCorr(dst_gold, dst_mine) /
(cv::norm(dst_gold,cv::NORM_L2)*cv::norm(dst_mine,cv::NORM_L2));
double err = cvtest::crossCorr(dst_gold, dst) /
(cv::norm(dst_gold,cv::NORM_L2)*cv::norm(dst,cv::NORM_L2));
ASSERT_NEAR(err, 1., 1e-2);
}
......@@ -2182,36 +2086,47 @@ INSTANTIATE_TEST_CASE_P(ImgProc, PyrDown, testing::ValuesIn(devices()));
// pyrUp
struct PyrUp: testing::TestWithParam<cv::gpu::DeviceInfo>
{
{
cv::gpu::DeviceInfo devInfo;
cv::Mat src;
cv::Mat dst_gold;
virtual void SetUp()
{
devInfo = GetParam();
cv::gpu::setDevice(devInfo.deviceID());
cv::Mat img = readImage("stereobm/aloe-L.png");
ASSERT_FALSE(img.empty());
img.convertTo(src, CV_16S);
cv::pyrUp(src, dst_gold);
}
};
TEST_P(PyrUp, Accuracy)
{
PRINT_PARAM(devInfo);
cv::Mat dst;
cv::Mat src;
readImage("stereobm/aloe-L.png").convertTo(src, CV_16S);
cv::Mat dst_gold;
cv::pyrUp(src, dst_gold);
cv::gpu::GpuMat d_dst;
cv::gpu::pyrUp(cv::gpu::GpuMat(src), d_dst);
cv::Mat dst_mine = d_dst;
ASSERT_NO_THROW(
cv::gpu::GpuMat d_dst;
cv::gpu::pyrUp(cv::gpu::GpuMat(src), d_dst);
d_dst.download(dst);
);
ASSERT_EQ(dst_gold.cols, dst_mine.cols);
ASSERT_EQ(dst_gold.rows, dst_mine.rows);
ASSERT_EQ(dst_gold.type(), dst_mine.type());
ASSERT_EQ(dst_gold.cols, dst.cols);
ASSERT_EQ(dst_gold.rows, dst.rows);
ASSERT_EQ(dst_gold.type(), dst.type());
double err = cvtest::crossCorr(dst_gold, dst_mine) /
(cv::norm(dst_gold,cv::NORM_L2)*cv::norm(dst_mine,cv::NORM_L2));
double err = cvtest::crossCorr(dst_gold, dst) /
(cv::norm(dst_gold,cv::NORM_L2)*cv::norm(dst,cv::NORM_L2));
ASSERT_NEAR(err, 1., 1e-2);
}
......@@ -2222,21 +2137,11 @@ INSTANTIATE_TEST_CASE_P(ImgProc, PyrUp, testing::ValuesIn(devices()));
struct Canny : testing::TestWithParam< std::tr1::tuple<cv::gpu::DeviceInfo, int, bool> >
{
static cv::Mat img;
static void SetUpTestCase()
{
img = readImage("stereobm/aloe-L.png", CV_LOAD_IMAGE_GRAYSCALE);
}
static void TearDownTestCase()
{
img.release();
}
cv::gpu::DeviceInfo devInfo;
int apperture_size;
bool L2gradient;
cv::Mat img;
double low_thresh;
double high_thresh;
......@@ -2250,6 +2155,9 @@ struct Canny : testing::TestWithParam< std::tr1::tuple<cv::gpu::DeviceInfo, int,
L2gradient = std::tr1::get<2>(GetParam());
cv::gpu::setDevice(devInfo.deviceID());
img = readImage("stereobm/aloe-L.png", CV_LOAD_IMAGE_GRAYSCALE);
ASSERT_FALSE(img.empty());
low_thresh = 50.0;
high_thresh = 100.0;
......@@ -2258,8 +2166,6 @@ struct Canny : testing::TestWithParam< std::tr1::tuple<cv::gpu::DeviceInfo, int,
}
};
cv::Mat Canny::img;
TEST_P(Canny, Accuracy)
{
PRINT_PARAM(devInfo);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册