2013-01-30 15:04:15 +08:00
|
|
|
/*M///////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
|
|
|
//
|
|
|
|
// By downloading, copying, installing or using the software you agree to this license.
|
|
|
|
// If you do not agree to this license, do not download, install,
|
|
|
|
// copy or use the software.
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// License Agreement
|
|
|
|
// For Open Source Computer Vision Library
|
|
|
|
//
|
|
|
|
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
|
|
|
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
2014-04-18 12:55:38 +08:00
|
|
|
// Copyright (C) 2014, Itseez, Inc, all rights reserved.
|
2013-01-30 15:04:15 +08:00
|
|
|
// Third party copyrights are property of their respective owners.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without modification,
|
|
|
|
// are permitted provided that the following conditions are met:
|
|
|
|
//
|
|
|
|
// * Redistribution's of source code must retain the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer.
|
|
|
|
//
|
|
|
|
// * Redistribution's in binary form must reproduce the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer in the documentation
|
|
|
|
// and/or other materials provided with the distribution.
|
|
|
|
//
|
|
|
|
// * The name of the copyright holders may not be used to endorse or promote products
|
|
|
|
// derived from this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// This software is provided by the copyright holders and contributors "as is" and
|
|
|
|
// any express or implied warranties, including, but not limited to, the implied
|
|
|
|
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
|
|
|
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
|
|
|
// indirect, incidental, special, exemplary, or consequential damages
|
|
|
|
// (including, but not limited to, procurement of substitute goods or services;
|
|
|
|
// loss of use, data, or profits; or business interruption) however caused
|
|
|
|
// and on any theory of liability, whether in contract, strict liability,
|
|
|
|
// or tort (including negligence or otherwise) arising in any way out of
|
|
|
|
// the use of this software, even if advised of the possibility of such damage.
|
|
|
|
//
|
|
|
|
//M*/
|
|
|
|
|
|
|
|
#include "test_precomp.hpp"
|
|
|
|
|
|
|
|
using namespace cv;
|
|
|
|
using namespace std;
|
|
|
|
|
2014-04-18 12:55:38 +08:00
|
|
|
template<typename T>
|
|
|
|
struct SimilarWith
|
2013-01-30 15:04:15 +08:00
|
|
|
{
|
2014-04-18 12:55:38 +08:00
|
|
|
T value;
|
2014-04-23 15:59:19 +08:00
|
|
|
float theta_eps;
|
|
|
|
float rho_eps;
|
|
|
|
SimilarWith<T>(T val, float e, float r_e): value(val), theta_eps(e), rho_eps(r_e) { };
|
2014-04-18 12:55:38 +08:00
|
|
|
bool operator()(T other);
|
2013-01-30 15:04:15 +08:00
|
|
|
};
|
|
|
|
|
2014-04-18 12:55:38 +08:00
|
|
|
template<>
|
|
|
|
bool SimilarWith<Vec2f>::operator()(Vec2f other)
|
2013-01-30 15:04:15 +08:00
|
|
|
{
|
2014-04-23 15:59:19 +08:00
|
|
|
return abs(other[0] - value[0]) < rho_eps && abs(other[1] - value[1]) < theta_eps;
|
2014-04-18 12:55:38 +08:00
|
|
|
}
|
2013-01-30 15:04:15 +08:00
|
|
|
|
2014-04-18 12:55:38 +08:00
|
|
|
template<>
|
|
|
|
bool SimilarWith<Vec4i>::operator()(Vec4i other)
|
2013-01-30 15:04:15 +08:00
|
|
|
{
|
2014-04-23 15:59:19 +08:00
|
|
|
return norm(value, other) < theta_eps;
|
2014-04-18 12:55:38 +08:00
|
|
|
}
|
2013-01-30 15:04:15 +08:00
|
|
|
|
2014-04-18 12:55:38 +08:00
|
|
|
template <typename T>
|
2014-04-23 15:59:19 +08:00
|
|
|
int countMatIntersection(Mat expect, Mat actual, float eps, float rho_eps)
|
2013-01-30 15:04:15 +08:00
|
|
|
{
|
2014-04-18 12:55:38 +08:00
|
|
|
int count = 0;
|
|
|
|
if (!expect.empty() && !actual.empty())
|
|
|
|
{
|
|
|
|
for (MatIterator_<T> it=expect.begin<T>(); it!=expect.end<T>(); it++)
|
|
|
|
{
|
|
|
|
MatIterator_<T> f = std::find_if(actual.begin<T>(), actual.end<T>(), SimilarWith<T>(*it, eps, rho_eps));
|
|
|
|
if (f != actual.end<T>())
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return count;
|
2013-01-30 15:04:15 +08:00
|
|
|
}
|
|
|
|
|
2014-04-18 12:55:38 +08:00
|
|
|
String getTestCaseName(String filename)
|
2013-01-30 15:04:15 +08:00
|
|
|
{
|
2014-04-18 12:55:38 +08:00
|
|
|
string temp(filename);
|
|
|
|
size_t pos = temp.find_first_of("\\/.");
|
|
|
|
while ( pos != string::npos ) {
|
|
|
|
temp.replace( pos, 1, "_" );
|
|
|
|
pos = temp.find_first_of("\\/.");
|
|
|
|
}
|
|
|
|
return String(temp);
|
2013-01-30 15:04:15 +08:00
|
|
|
}
|
|
|
|
|
2014-04-18 12:55:38 +08:00
|
|
|
class BaseHoughLineTest
|
2013-01-30 15:04:15 +08:00
|
|
|
{
|
2014-04-18 12:55:38 +08:00
|
|
|
public:
|
|
|
|
enum {STANDART = 0, PROBABILISTIC};
|
|
|
|
protected:
|
|
|
|
void run_test(int type);
|
|
|
|
|
|
|
|
string picture_name;
|
|
|
|
double rhoStep;
|
|
|
|
double thetaStep;
|
|
|
|
int threshold;
|
|
|
|
int minLineLength;
|
|
|
|
int maxGap;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::tr1::tuple<string, double, double, int> Image_RhoStep_ThetaStep_Threshold_t;
|
|
|
|
class StandartHoughLinesTest : public BaseHoughLineTest, public testing::TestWithParam<Image_RhoStep_ThetaStep_Threshold_t>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
StandartHoughLinesTest()
|
2013-01-30 15:04:15 +08:00
|
|
|
{
|
2014-04-23 15:59:19 +08:00
|
|
|
picture_name = std::tr1::get<0>(GetParam());
|
|
|
|
rhoStep = std::tr1::get<1>(GetParam());
|
|
|
|
thetaStep = std::tr1::get<2>(GetParam());
|
|
|
|
threshold = std::tr1::get<3>(GetParam());
|
2014-04-18 12:55:38 +08:00
|
|
|
minLineLength = 0;
|
|
|
|
maxGap = 0;
|
2013-01-30 15:04:15 +08:00
|
|
|
}
|
2014-04-18 12:55:38 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::tr1::tuple<string, double, double, int, int, int> Image_RhoStep_ThetaStep_Threshold_MinLine_MaxGap_t;
|
2014-04-23 15:59:19 +08:00
|
|
|
class ProbabilisticHoughLinesTest : public BaseHoughLineTest, public testing::TestWithParam<Image_RhoStep_ThetaStep_Threshold_MinLine_MaxGap_t>
|
2014-04-18 12:55:38 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
ProbabilisticHoughLinesTest()
|
|
|
|
{
|
2014-04-23 15:59:19 +08:00
|
|
|
picture_name = std::tr1::get<0>(GetParam());
|
|
|
|
rhoStep = std::tr1::get<1>(GetParam());
|
|
|
|
thetaStep = std::tr1::get<2>(GetParam());
|
|
|
|
threshold = std::tr1::get<3>(GetParam());
|
|
|
|
minLineLength = std::tr1::get<4>(GetParam());
|
|
|
|
maxGap = std::tr1::get<5>(GetParam());
|
2014-04-18 12:55:38 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void BaseHoughLineTest::run_test(int type)
|
|
|
|
{
|
|
|
|
string filename = cvtest::TS::ptr()->get_data_path() + picture_name;
|
|
|
|
Mat src = imread(filename, IMREAD_GRAYSCALE);
|
|
|
|
EXPECT_FALSE(src.empty()) << "Invalid test image: " << filename;
|
2013-01-30 15:04:15 +08:00
|
|
|
|
|
|
|
string xml;
|
|
|
|
if (type == STANDART)
|
2014-04-18 12:55:38 +08:00
|
|
|
xml = string(cvtest::TS::ptr()->get_data_path()) + "imgproc/HoughLines.xml";
|
2013-01-30 15:04:15 +08:00
|
|
|
else if (type == PROBABILISTIC)
|
2014-04-18 12:55:38 +08:00
|
|
|
xml = string(cvtest::TS::ptr()->get_data_path()) + "imgproc/HoughLinesP.xml";
|
2013-01-30 15:04:15 +08:00
|
|
|
|
|
|
|
Mat dst;
|
2014-04-23 15:59:19 +08:00
|
|
|
Canny(src, dst, 100, 150, 3);
|
2014-04-18 12:55:38 +08:00
|
|
|
EXPECT_FALSE(dst.empty()) << "Failed Canny edge detector";
|
2013-01-30 15:04:15 +08:00
|
|
|
|
|
|
|
Mat lines;
|
|
|
|
if (type == STANDART)
|
2014-04-18 12:55:38 +08:00
|
|
|
HoughLines(dst, lines, rhoStep, thetaStep, threshold, 0, 0);
|
2013-01-30 15:04:15 +08:00
|
|
|
else if (type == PROBABILISTIC)
|
2014-04-18 12:55:38 +08:00
|
|
|
HoughLinesP(dst, lines, rhoStep, thetaStep, threshold, minLineLength, maxGap);
|
|
|
|
|
2014-04-23 15:59:19 +08:00
|
|
|
String test_case_name = format("lines_%s_%.0f_%.2f_%d_%d_%d", picture_name.c_str(), rhoStep, thetaStep,
|
2014-04-18 12:55:38 +08:00
|
|
|
threshold, minLineLength, maxGap);
|
|
|
|
test_case_name = getTestCaseName(test_case_name);
|
2013-01-30 15:04:15 +08:00
|
|
|
|
|
|
|
FileStorage fs(xml, FileStorage::READ);
|
2014-04-18 12:55:38 +08:00
|
|
|
FileNode node = fs[test_case_name];
|
|
|
|
if (node.empty())
|
2013-01-30 15:04:15 +08:00
|
|
|
{
|
2014-04-18 12:55:38 +08:00
|
|
|
fs.release();
|
|
|
|
fs.open(xml, FileStorage::APPEND);
|
|
|
|
EXPECT_TRUE(fs.isOpened()) << "Cannot open sanity data file: " << xml;
|
|
|
|
fs << test_case_name << lines;
|
2013-01-30 15:04:15 +08:00
|
|
|
fs.release();
|
|
|
|
fs.open(xml, FileStorage::READ);
|
2014-04-18 12:55:38 +08:00
|
|
|
EXPECT_TRUE(fs.isOpened()) << "Cannot open sanity data file: " << xml;
|
2013-01-30 15:04:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Mat exp_lines;
|
2014-04-18 12:55:38 +08:00
|
|
|
read( fs[test_case_name], exp_lines, Mat() );
|
2013-01-30 15:04:15 +08:00
|
|
|
fs.release();
|
|
|
|
|
2014-04-18 12:55:38 +08:00
|
|
|
int count = -1;
|
|
|
|
if (type == STANDART)
|
2014-04-23 15:59:19 +08:00
|
|
|
count = countMatIntersection<Vec2f>(exp_lines, lines, (float) thetaStep + FLT_EPSILON, (float) rhoStep + FLT_EPSILON);
|
2014-04-18 12:55:38 +08:00
|
|
|
else if (type == PROBABILISTIC)
|
2014-04-23 15:59:19 +08:00
|
|
|
count = countMatIntersection<Vec4i>(exp_lines, lines, 1e-4f, 0.f);
|
2013-02-13 03:16:06 +08:00
|
|
|
|
2015-12-01 21:10:29 +08:00
|
|
|
#if defined HAVE_IPP && !defined(HAVE_IPP_ICV_ONLY) && IPP_VERSION_X100 >= 810 && IPP_DISABLE_BLOCK
|
2014-04-18 12:55:38 +08:00
|
|
|
EXPECT_GE( count, (int) (exp_lines.total() * 0.8) );
|
2014-05-06 18:24:49 +08:00
|
|
|
#else
|
|
|
|
EXPECT_EQ( count, (int) exp_lines.total());
|
|
|
|
#endif
|
2014-04-18 12:55:38 +08:00
|
|
|
}
|
2013-01-30 15:04:15 +08:00
|
|
|
|
2014-04-18 12:55:38 +08:00
|
|
|
TEST_P(StandartHoughLinesTest, regression)
|
|
|
|
{
|
|
|
|
run_test(STANDART);
|
2013-01-30 15:04:15 +08:00
|
|
|
}
|
|
|
|
|
2014-04-18 12:55:38 +08:00
|
|
|
TEST_P(ProbabilisticHoughLinesTest, regression)
|
|
|
|
{
|
|
|
|
run_test(PROBABILISTIC);
|
|
|
|
}
|
2013-01-30 15:04:15 +08:00
|
|
|
|
2014-04-18 12:55:38 +08:00
|
|
|
INSTANTIATE_TEST_CASE_P( ImgProc, StandartHoughLinesTest, testing::Combine(testing::Values( "shared/pic5.png", "../stitching/a1.png" ),
|
|
|
|
testing::Values( 1, 10 ),
|
2014-04-23 15:59:19 +08:00
|
|
|
testing::Values( 0.05, 0.1 ),
|
|
|
|
testing::Values( 80, 150 )
|
2014-04-18 12:55:38 +08:00
|
|
|
));
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P( ImgProc, ProbabilisticHoughLinesTest, testing::Combine(testing::Values( "shared/pic5.png", "shared/pic1.png" ),
|
|
|
|
testing::Values( 5, 10 ),
|
2014-04-23 15:59:19 +08:00
|
|
|
testing::Values( 0.05, 0.1 ),
|
2014-04-18 12:55:38 +08:00
|
|
|
testing::Values( 75, 150 ),
|
|
|
|
testing::Values( 0, 10 ),
|
|
|
|
testing::Values( 0, 4 )
|
|
|
|
));
|