2012-07-17 01:08:14 +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) 2010-2012, Institute Of Software Chinese Academy Of Science, all rights reserved.
|
|
|
|
// Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
|
2013-05-08 15:21:53 +08:00
|
|
|
// Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved.
|
2012-07-17 01:08:14 +08:00
|
|
|
// Third party copyrights are property of their respective owners.
|
|
|
|
//
|
|
|
|
// @Authors
|
|
|
|
// Niko Li, newlife20080214@gmail.com
|
|
|
|
// Jia Haipeng, jiahaipeng95@gmail.com
|
|
|
|
// Shengen Yan, yanshengen@gmail.com
|
|
|
|
// Jiang Liyuan, lyuan001.good@163.com
|
|
|
|
// Rock Li, Rock.Li@amd.com
|
|
|
|
// Wu Zailong, bullet@yeah.net
|
|
|
|
// Xu Pang, pangxu010@163.com
|
2013-06-10 18:37:48 +08:00
|
|
|
// Sen Liu, swjtuls1987@126.com
|
2012-07-17 01:08:14 +08:00
|
|
|
//
|
|
|
|
// 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
|
2013-10-25 22:00:46 +08:00
|
|
|
// and/or other materials provided with the distribution.
|
2012-07-17 01:08:14 +08:00
|
|
|
//
|
|
|
|
// * 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*/
|
|
|
|
|
2013-08-08 22:18:54 +08:00
|
|
|
#include "test_precomp.hpp"
|
2012-07-17 01:08:14 +08:00
|
|
|
|
|
|
|
#ifdef HAVE_OPENCL
|
|
|
|
|
2013-10-14 18:45:15 +08:00
|
|
|
using namespace testing;
|
2013-10-18 20:29:10 +08:00
|
|
|
using namespace std;
|
|
|
|
using namespace cv;
|
2012-07-17 01:08:14 +08:00
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2012-07-17 01:08:14 +08:00
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
PARAM_TEST_CASE(ImgprocTestBase, MatType,
|
|
|
|
int, // blockSize
|
|
|
|
int, // border type
|
|
|
|
bool) // roi or not
|
2012-07-17 01:08:14 +08:00
|
|
|
{
|
2013-10-18 20:29:10 +08:00
|
|
|
int type, borderType, blockSize;
|
|
|
|
bool useRoi;
|
2012-07-17 01:08:14 +08:00
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
Mat src, dst_whole, src_roi, dst_roi;
|
|
|
|
ocl::oclMat gsrc_whole, gsrc_roi, gdst_whole, gdst_roi;
|
2012-07-17 01:08:14 +08:00
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
virtual void SetUp()
|
2012-07-17 01:08:14 +08:00
|
|
|
{
|
2013-10-18 20:29:10 +08:00
|
|
|
type = GET_PARAM(0);
|
|
|
|
blockSize = GET_PARAM(1);
|
|
|
|
borderType = GET_PARAM(2);
|
|
|
|
useRoi = GET_PARAM(3);
|
2012-07-17 01:08:14 +08:00
|
|
|
}
|
|
|
|
|
2013-10-29 16:10:20 +08:00
|
|
|
virtual void random_roi()
|
2012-07-17 01:08:14 +08:00
|
|
|
{
|
2013-10-18 20:29:10 +08:00
|
|
|
Size roiSize = randomSize(1, MAX_VALUE);
|
|
|
|
Border srcBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
|
|
|
|
randomSubMat(src, src_roi, roiSize, srcBorder, type, 5, 256);
|
2012-07-17 01:08:14 +08:00
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
|
|
|
|
randomSubMat(dst_whole, dst_roi, roiSize, dstBorder, type, 5, 16);
|
2012-07-17 01:08:14 +08:00
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
generateOclMat(gsrc_whole, gsrc_roi, src, roiSize, srcBorder);
|
|
|
|
generateOclMat(gdst_whole, gdst_roi, dst_whole, roiSize, dstBorder);
|
2012-07-17 01:08:14 +08:00
|
|
|
}
|
|
|
|
|
2013-11-01 20:38:04 +08:00
|
|
|
void Near(double threshold = 0.0, bool relative = false)
|
2012-10-11 16:22:47 +08:00
|
|
|
{
|
2013-11-01 20:38:04 +08:00
|
|
|
Mat roi, whole;
|
2013-10-18 20:29:10 +08:00
|
|
|
gdst_whole.download(whole);
|
|
|
|
gdst_roi.download(roi);
|
2013-05-08 17:07:44 +08:00
|
|
|
|
2013-11-01 20:38:04 +08:00
|
|
|
if (relative)
|
|
|
|
{
|
|
|
|
EXPECT_MAT_NEAR_RELATIVE(dst_whole, whole, threshold);
|
|
|
|
EXPECT_MAT_NEAR_RELATIVE(dst_roi, roi, threshold);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
EXPECT_MAT_NEAR(dst_whole, whole, threshold);
|
|
|
|
EXPECT_MAT_NEAR(dst_roi, roi, threshold);
|
|
|
|
}
|
2013-05-08 17:07:44 +08:00
|
|
|
}
|
2012-07-17 01:08:14 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
////////////////////////////////copyMakeBorder////////////////////////////////////////////
|
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
PARAM_TEST_CASE(CopyMakeBorder, MatDepth, // depth
|
|
|
|
Channels, // channels
|
|
|
|
bool, // isolated or not
|
|
|
|
Border, // border type
|
|
|
|
bool) // roi or not
|
2012-07-17 01:08:14 +08:00
|
|
|
{
|
2013-10-18 20:29:10 +08:00
|
|
|
int type, borderType;
|
|
|
|
bool useRoi;
|
2012-07-17 01:08:14 +08:00
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
Border border;
|
|
|
|
Scalar val;
|
2012-07-17 01:08:14 +08:00
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
Mat src, dst_whole, src_roi, dst_roi;
|
|
|
|
ocl::oclMat gsrc_whole, gsrc_roi, gdst_whole, gdst_roi;
|
2012-07-17 01:08:14 +08:00
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
virtual void SetUp()
|
2012-07-17 01:08:14 +08:00
|
|
|
{
|
2013-10-18 20:29:10 +08:00
|
|
|
type = CV_MAKE_TYPE(GET_PARAM(0), GET_PARAM(1));
|
|
|
|
borderType = GET_PARAM(3);
|
2012-07-17 01:08:14 +08:00
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
if (GET_PARAM(2))
|
|
|
|
borderType |= BORDER_ISOLATED;
|
2012-07-17 01:08:14 +08:00
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
useRoi = GET_PARAM(4);
|
2012-07-17 01:08:14 +08:00
|
|
|
}
|
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
void random_roi()
|
2013-10-03 23:17:54 +08:00
|
|
|
{
|
2013-11-01 23:06:42 +08:00
|
|
|
border = randomBorder(0, MAX_VALUE << 2);
|
|
|
|
val = randomScalar(-MAX_VALUE, MAX_VALUE);
|
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
Size roiSize = randomSize(1, MAX_VALUE);
|
|
|
|
Border srcBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
|
2013-11-01 23:06:42 +08:00
|
|
|
randomSubMat(src, src_roi, roiSize, srcBorder, type, -MAX_VALUE, MAX_VALUE);
|
2013-10-03 23:17:54 +08:00
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
|
2013-11-01 23:06:42 +08:00
|
|
|
dstBorder.top += border.top;
|
|
|
|
dstBorder.lef += border.lef;
|
|
|
|
dstBorder.rig += border.rig;
|
|
|
|
dstBorder.bot += border.bot;
|
|
|
|
|
|
|
|
randomSubMat(dst_whole, dst_roi, roiSize, dstBorder, type, -MAX_VALUE, MAX_VALUE);
|
2012-07-17 01:08:14 +08:00
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
generateOclMat(gsrc_whole, gsrc_roi, src, roiSize, srcBorder);
|
|
|
|
generateOclMat(gdst_whole, gdst_roi, dst_whole, roiSize, dstBorder);
|
2012-07-17 01:08:14 +08:00
|
|
|
}
|
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
void Near(double threshold = 0.0)
|
2012-07-17 01:08:14 +08:00
|
|
|
{
|
2013-10-18 20:29:10 +08:00
|
|
|
Mat whole, roi;
|
|
|
|
gdst_whole.download(whole);
|
|
|
|
gdst_roi.download(roi);
|
2012-07-17 01:08:14 +08:00
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
EXPECT_MAT_NEAR(dst_whole, whole, threshold);
|
|
|
|
EXPECT_MAT_NEAR(dst_roi, roi, threshold);
|
2012-07-17 01:08:14 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
OCL_TEST_P(CopyMakeBorder, Mat)
|
2012-07-17 01:08:14 +08:00
|
|
|
{
|
2013-10-18 20:29:10 +08:00
|
|
|
for (int i = 0; i < LOOP_TIMES; ++i)
|
2012-07-17 01:08:14 +08:00
|
|
|
{
|
|
|
|
random_roi();
|
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
cv::copyMakeBorder(src_roi, dst_roi, border.top, border.bot, border.lef, border.rig, borderType, val);
|
|
|
|
ocl::copyMakeBorder(gsrc_roi, gdst_roi, border.top, border.bot, border.lef, border.rig, borderType, val);
|
2012-07-17 01:08:14 +08:00
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
Near();
|
2012-07-17 01:08:14 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
////////////////////////////////equalizeHist//////////////////////////////////////////////
|
2012-07-17 01:08:14 +08:00
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
typedef ImgprocTestBase EqualizeHist;
|
2012-07-17 01:08:14 +08:00
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
OCL_TEST_P(EqualizeHist, Mat)
|
2012-07-17 01:08:14 +08:00
|
|
|
{
|
2013-10-18 20:29:10 +08:00
|
|
|
for (int j = 0; j < LOOP_TIMES; j++)
|
2012-07-17 01:08:14 +08:00
|
|
|
{
|
|
|
|
random_roi();
|
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
equalizeHist(src_roi, dst_roi);
|
|
|
|
ocl::equalizeHist(gsrc_roi, gdst_roi);
|
2012-07-17 01:08:14 +08:00
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
Near(1.1);
|
2012-07-17 01:08:14 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
////////////////////////////////cornerMinEigenVal//////////////////////////////////////////
|
2012-07-17 01:08:14 +08:00
|
|
|
|
2013-10-29 16:10:20 +08:00
|
|
|
struct CornerTestBase :
|
|
|
|
public ImgprocTestBase
|
|
|
|
{
|
|
|
|
virtual void random_roi()
|
|
|
|
{
|
|
|
|
Mat image = readImageType("gpu/stereobm/aloe-L.png", type);
|
|
|
|
ASSERT_FALSE(image.empty());
|
|
|
|
|
2013-11-04 19:09:58 +08:00
|
|
|
bool isFP = CV_MAT_DEPTH(type) >= CV_32F;
|
|
|
|
float val = 255.0f;
|
|
|
|
if (isFP)
|
|
|
|
{
|
|
|
|
image.convertTo(image, -1, 1.0 / 255);
|
|
|
|
val /= 255.0f;
|
|
|
|
}
|
|
|
|
|
2013-10-29 16:10:20 +08:00
|
|
|
Size roiSize = image.size();
|
|
|
|
Border srcBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
|
|
|
|
|
|
|
|
Size wholeSize = Size(roiSize.width + srcBorder.lef + srcBorder.rig, roiSize.height + srcBorder.top + srcBorder.bot);
|
2013-11-04 19:09:58 +08:00
|
|
|
src = randomMat(wholeSize, type, -val, val, false);
|
2013-10-29 16:10:20 +08:00
|
|
|
src_roi = src(Rect(srcBorder.lef, srcBorder.top, roiSize.width, roiSize.height));
|
|
|
|
image.copyTo(src_roi);
|
|
|
|
|
|
|
|
Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
|
|
|
|
randomSubMat(dst_whole, dst_roi, roiSize, dstBorder, CV_32FC1, 5, 16);
|
|
|
|
|
|
|
|
generateOclMat(gsrc_whole, gsrc_roi, src, roiSize, srcBorder);
|
|
|
|
generateOclMat(gdst_whole, gdst_roi, dst_whole, roiSize, dstBorder);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef CornerTestBase CornerMinEigenVal;
|
2012-09-03 18:07:31 +08:00
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
OCL_TEST_P(CornerMinEigenVal, Mat)
|
|
|
|
{
|
|
|
|
for (int j = 0; j < LOOP_TIMES; j++)
|
2012-07-17 01:08:14 +08:00
|
|
|
{
|
2013-10-18 20:29:10 +08:00
|
|
|
random_roi();
|
2012-07-17 01:08:14 +08:00
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
int apertureSize = 3;
|
2012-07-17 01:08:14 +08:00
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
cornerMinEigenVal(src_roi, dst_roi, blockSize, apertureSize, borderType);
|
|
|
|
ocl::cornerMinEigenVal(gsrc_roi, gdst_roi, blockSize, apertureSize, borderType);
|
2013-09-13 15:27:25 +08:00
|
|
|
|
2013-11-01 20:38:04 +08:00
|
|
|
Near(1e-5, true);
|
2012-07-17 01:08:14 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
////////////////////////////////cornerHarris//////////////////////////////////////////
|
2012-07-17 01:08:14 +08:00
|
|
|
|
2013-10-29 16:10:20 +08:00
|
|
|
typedef CornerTestBase CornerHarris;
|
2012-07-17 01:08:14 +08:00
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
OCL_TEST_P(CornerHarris, Mat)
|
2012-07-17 01:08:14 +08:00
|
|
|
{
|
2013-10-18 20:29:10 +08:00
|
|
|
for (int j = 0; j < LOOP_TIMES; j++)
|
2012-07-17 01:08:14 +08:00
|
|
|
{
|
2013-10-18 20:29:10 +08:00
|
|
|
random_roi();
|
2012-07-17 01:08:14 +08:00
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
int apertureSize = 3;
|
2013-10-29 16:10:20 +08:00
|
|
|
double k = randomDouble(0.01, 0.9);
|
2012-07-17 01:08:14 +08:00
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
cornerHarris(src_roi, dst_roi, blockSize, apertureSize, k, borderType);
|
|
|
|
ocl::cornerHarris(gsrc_roi, gdst_roi, blockSize, apertureSize, k, borderType);
|
2012-07-17 01:08:14 +08:00
|
|
|
|
2013-11-01 20:38:04 +08:00
|
|
|
Near(1e-5, true);
|
2012-07-17 01:08:14 +08:00
|
|
|
}
|
2013-10-18 20:29:10 +08:00
|
|
|
}
|
2012-07-17 01:08:14 +08:00
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
//////////////////////////////////integral/////////////////////////////////////////////////
|
2012-07-17 01:08:14 +08:00
|
|
|
|
2013-11-11 14:31:02 +08:00
|
|
|
struct Integral :
|
|
|
|
public ImgprocTestBase
|
|
|
|
{
|
|
|
|
int sdepth;
|
2012-07-17 01:08:14 +08:00
|
|
|
|
2013-11-11 14:31:02 +08:00
|
|
|
virtual void SetUp()
|
|
|
|
{
|
|
|
|
type = GET_PARAM(0);
|
|
|
|
blockSize = GET_PARAM(1);
|
|
|
|
sdepth = GET_PARAM(2);
|
|
|
|
useRoi = GET_PARAM(3);
|
|
|
|
}
|
|
|
|
};
|
2013-10-18 20:29:10 +08:00
|
|
|
OCL_TEST_P(Integral, Mat1)
|
2012-07-17 01:08:14 +08:00
|
|
|
{
|
2013-10-18 20:29:10 +08:00
|
|
|
for (int j = 0; j < LOOP_TIMES; j++)
|
2012-07-17 01:08:14 +08:00
|
|
|
{
|
|
|
|
random_roi();
|
|
|
|
|
2013-11-11 14:31:02 +08:00
|
|
|
ocl::integral(gsrc_roi, gdst_roi, sdepth);
|
|
|
|
integral(src_roi, dst_roi, sdepth);
|
2012-07-17 01:08:14 +08:00
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
Near();
|
2012-07-17 01:08:14 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-11 14:31:02 +08:00
|
|
|
OCL_TEST_P(Integral, Mat2)
|
2012-07-17 01:08:14 +08:00
|
|
|
{
|
2013-10-18 20:29:10 +08:00
|
|
|
Mat dst1;
|
|
|
|
ocl::oclMat gdst1;
|
2012-07-17 01:08:14 +08:00
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
for (int j = 0; j < LOOP_TIMES; j++)
|
2012-07-17 01:08:14 +08:00
|
|
|
{
|
|
|
|
random_roi();
|
|
|
|
|
2013-11-11 14:31:02 +08:00
|
|
|
integral(src_roi, dst_roi, dst1, sdepth);
|
|
|
|
ocl::integral(gsrc_roi, gdst_roi, gdst1, sdepth);
|
2012-07-17 01:08:14 +08:00
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
Near();
|
2013-11-11 14:31:02 +08:00
|
|
|
if(gdst1.clCxt->supportsFeature(ocl::FEATURE_CL_DOUBLE))
|
|
|
|
EXPECT_MAT_NEAR(dst1, Mat(gdst1), 0.);
|
2012-07-17 01:08:14 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//// threshold
|
|
|
|
|
|
|
|
struct Threshold :
|
|
|
|
public ImgprocTestBase
|
2012-07-17 01:08:14 +08:00
|
|
|
{
|
2013-10-18 20:29:10 +08:00
|
|
|
int thresholdType;
|
2012-07-17 01:08:14 +08:00
|
|
|
|
|
|
|
virtual void SetUp()
|
|
|
|
{
|
2013-10-18 20:29:10 +08:00
|
|
|
type = GET_PARAM(0);
|
|
|
|
blockSize = GET_PARAM(1);
|
|
|
|
thresholdType = GET_PARAM(2);
|
|
|
|
useRoi = GET_PARAM(3);
|
2012-07-17 01:08:14 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
OCL_TEST_P(Threshold, Mat)
|
2012-07-17 01:08:14 +08:00
|
|
|
{
|
2013-10-18 20:29:10 +08:00
|
|
|
for (int j = 0; j < LOOP_TIMES; j++)
|
2012-07-17 01:08:14 +08:00
|
|
|
{
|
|
|
|
random_roi();
|
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
double maxVal = randomDouble(20.0, 127.0);
|
|
|
|
double thresh = randomDouble(0.0, maxVal);
|
2012-07-17 01:08:14 +08:00
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
threshold(src_roi, dst_roi, thresh, maxVal, thresholdType);
|
|
|
|
ocl::threshold(gsrc_roi, gdst_roi, thresh, maxVal, thresholdType);
|
2012-07-17 01:08:14 +08:00
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
Near(1);
|
2012-07-17 01:08:14 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// calcHist
|
2013-10-14 18:45:15 +08:00
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
static void calcHistGold(const Mat &src, Mat &hist)
|
2012-09-03 18:07:31 +08:00
|
|
|
{
|
2013-10-18 20:29:10 +08:00
|
|
|
hist = Mat(1, 256, CV_32SC1, Scalar::all(0));
|
2012-09-03 18:07:31 +08:00
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
int * const hist_row = hist.ptr<int>();
|
2012-09-03 18:07:31 +08:00
|
|
|
for (int y = 0; y < src.rows; ++y)
|
|
|
|
{
|
2013-10-18 20:29:10 +08:00
|
|
|
const uchar * const src_row = src.ptr(y);
|
2012-09-03 18:07:31 +08:00
|
|
|
|
|
|
|
for (int x = 0; x < src.cols; ++x)
|
|
|
|
++hist_row[src_row[x]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
typedef ImgprocTestBase CalcHist;
|
2013-10-14 18:45:15 +08:00
|
|
|
|
|
|
|
OCL_TEST_P(CalcHist, Mat)
|
2012-09-03 18:07:31 +08:00
|
|
|
{
|
2013-10-18 20:29:10 +08:00
|
|
|
for (int j = 0; j < LOOP_TIMES; j++)
|
2012-09-03 18:07:31 +08:00
|
|
|
{
|
|
|
|
random_roi();
|
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
calcHistGold(src_roi, dst_roi);
|
|
|
|
ocl::calcHist(gsrc_roi, gdst_roi);
|
2012-09-03 18:07:31 +08:00
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
Near();
|
2012-09-03 18:07:31 +08:00
|
|
|
}
|
|
|
|
}
|
2013-10-14 18:45:15 +08:00
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//// CLAHE
|
2013-06-10 18:37:48 +08:00
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
PARAM_TEST_CASE(CLAHETest, Size, double, bool)
|
2013-06-10 18:37:48 +08:00
|
|
|
{
|
2013-10-14 18:45:15 +08:00
|
|
|
Size gridSize;
|
2013-06-10 18:37:48 +08:00
|
|
|
double clipLimit;
|
2013-10-18 20:29:10 +08:00
|
|
|
bool useRoi;
|
2013-06-10 18:37:48 +08:00
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
Mat src, dst_whole, src_roi, dst_roi;
|
|
|
|
ocl::oclMat gsrc_whole, gsrc_roi, gdst_whole, gdst_roi;
|
2013-06-10 18:37:48 +08:00
|
|
|
|
|
|
|
virtual void SetUp()
|
|
|
|
{
|
2013-09-03 15:02:18 +08:00
|
|
|
gridSize = GET_PARAM(0);
|
2013-06-10 18:37:48 +08:00
|
|
|
clipLimit = GET_PARAM(1);
|
2013-10-18 20:29:10 +08:00
|
|
|
useRoi = GET_PARAM(2);
|
2013-06-10 18:37:48 +08:00
|
|
|
}
|
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
void random_roi()
|
2012-09-12 10:20:04 +08:00
|
|
|
{
|
2013-10-18 20:29:10 +08:00
|
|
|
Size roiSize = randomSize(std::max(gridSize.height, gridSize.width), MAX_VALUE);
|
|
|
|
Border srcBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
|
|
|
|
randomSubMat(src, src_roi, roiSize, srcBorder, CV_8UC1, 5, 256);
|
2012-09-12 10:20:04 +08:00
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
|
|
|
|
randomSubMat(dst_whole, dst_roi, roiSize, dstBorder, CV_8UC1, 5, 16);
|
2012-09-12 10:20:04 +08:00
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
generateOclMat(gsrc_whole, gsrc_roi, src, roiSize, srcBorder);
|
|
|
|
generateOclMat(gdst_whole, gdst_roi, dst_whole, roiSize, dstBorder);
|
2012-09-12 10:20:04 +08:00
|
|
|
}
|
2013-10-18 20:29:10 +08:00
|
|
|
|
|
|
|
void Near(double threshold = 0.0)
|
2012-09-12 10:20:04 +08:00
|
|
|
{
|
2013-10-18 20:29:10 +08:00
|
|
|
Mat whole, roi;
|
|
|
|
gdst_whole.download(whole);
|
|
|
|
gdst_roi.download(roi);
|
2012-09-12 10:20:04 +08:00
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
EXPECT_MAT_NEAR(dst_whole, whole, threshold);
|
|
|
|
EXPECT_MAT_NEAR(dst_roi, roi, threshold);
|
|
|
|
}
|
2012-09-12 10:20:04 +08:00
|
|
|
};
|
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
OCL_TEST_P(CLAHETest, Accuracy)
|
2012-09-12 10:20:04 +08:00
|
|
|
{
|
2013-10-18 20:29:10 +08:00
|
|
|
for (int i = 0; i < LOOP_TIMES; ++i)
|
|
|
|
{
|
|
|
|
random_roi();
|
|
|
|
|
|
|
|
Ptr<CLAHE> clahe = ocl::createCLAHE(clipLimit, gridSize);
|
|
|
|
clahe->apply(gsrc_roi, gdst_roi);
|
2012-09-12 10:20:04 +08:00
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
Ptr<CLAHE> clahe_gold = createCLAHE(clipLimit, gridSize);
|
|
|
|
clahe_gold->apply(src_roi, dst_roi);
|
2012-10-11 16:22:47 +08:00
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
Near(1.0);
|
|
|
|
}
|
|
|
|
}
|
2012-09-12 10:20:04 +08:00
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
/////////////////////////////Convolve//////////////////////////////////
|
2012-09-12 10:20:04 +08:00
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
static void convolve_gold(const Mat & src, const Mat & kernel, Mat & dst)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < src.rows; i++)
|
|
|
|
{
|
|
|
|
float * const dstptr = dst.ptr<float>(i);
|
|
|
|
|
|
|
|
for (int j = 0; j < src.cols; j++)
|
2012-09-12 10:20:04 +08:00
|
|
|
{
|
2012-10-11 16:22:47 +08:00
|
|
|
float temp = 0;
|
2013-10-18 20:29:10 +08:00
|
|
|
|
|
|
|
for (int m = 0; m < kernel.rows; m++)
|
|
|
|
{
|
|
|
|
const float * const kptr = kernel.ptr<float>(m);
|
|
|
|
for (int n = 0; n < kernel.cols; n++)
|
2012-09-12 10:20:04 +08:00
|
|
|
{
|
2013-10-18 20:29:10 +08:00
|
|
|
int r = clipInt(i - kernel.rows / 2 + m, 0, src.rows - 1);
|
|
|
|
int c = clipInt(j - kernel.cols / 2 + n, 0, src.cols - 1);
|
|
|
|
|
|
|
|
temp += src.ptr<float>(r)[c] * kptr[n];
|
2012-09-12 10:20:04 +08:00
|
|
|
}
|
2013-10-18 20:29:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
dstptr[j] = temp;
|
2012-09-12 10:20:04 +08:00
|
|
|
}
|
2013-10-18 20:29:10 +08:00
|
|
|
}
|
2012-09-12 10:20:04 +08:00
|
|
|
}
|
2013-10-14 18:45:15 +08:00
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
typedef ImgprocTestBase Convolve;
|
|
|
|
|
2013-10-09 22:05:09 +08:00
|
|
|
OCL_TEST_P(Convolve, Mat)
|
2012-09-12 10:20:04 +08:00
|
|
|
{
|
2013-10-18 20:29:10 +08:00
|
|
|
Mat kernel, kernel_roi;
|
|
|
|
ocl::oclMat gkernel, gkernel_roi;
|
|
|
|
const Size roiSize(7, 7);
|
|
|
|
|
|
|
|
for (int j = 0; j < LOOP_TIMES; j++)
|
2012-09-12 10:20:04 +08:00
|
|
|
{
|
|
|
|
random_roi();
|
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
Border kernelBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
|
|
|
|
randomSubMat(kernel, kernel_roi, roiSize, kernelBorder, type, 5, 16);
|
|
|
|
generateOclMat(gkernel, gkernel_roi, kernel, roiSize, kernelBorder);
|
2012-10-11 16:22:47 +08:00
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
convolve_gold(src_roi, kernel_roi, dst_roi);
|
|
|
|
ocl::convolve(gsrc_roi, gkernel_roi, gdst_roi);
|
2012-09-12 10:20:04 +08:00
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
Near(1);
|
2012-09-12 10:20:04 +08:00
|
|
|
}
|
|
|
|
}
|
2012-09-03 18:07:31 +08:00
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
////////////////////////////////// ColumnSum //////////////////////////////////////
|
2013-10-14 18:45:15 +08:00
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
static void columnSum_gold(const Mat & src, Mat & dst)
|
2013-06-19 13:03:35 +08:00
|
|
|
{
|
2013-10-18 20:29:10 +08:00
|
|
|
float * prevdptr = dst.ptr<float>(0);
|
|
|
|
const float * sptr = src.ptr<float>(0);
|
2013-06-19 13:03:35 +08:00
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
for (int x = 0; x < src.cols; ++x)
|
|
|
|
prevdptr[x] = sptr[x];
|
|
|
|
|
|
|
|
for (int y = 1; y < src.rows; ++y)
|
2013-06-19 13:03:35 +08:00
|
|
|
{
|
2013-10-18 20:29:10 +08:00
|
|
|
sptr = src.ptr<float>(y);
|
|
|
|
float * const dptr = dst.ptr<float>(y);
|
2013-06-19 13:03:35 +08:00
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
for (int x = 0; x < src.cols; ++x)
|
|
|
|
dptr[x] = prevdptr[x] + sptr[x];
|
2013-06-19 13:03:35 +08:00
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
prevdptr = dptr;
|
|
|
|
}
|
|
|
|
}
|
2013-06-19 13:03:35 +08:00
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
typedef ImgprocTestBase ColumnSum;
|
2013-06-19 13:03:35 +08:00
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
OCL_TEST_P(ColumnSum, Accuracy)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < LOOP_TIMES; ++i)
|
2013-06-19 13:03:35 +08:00
|
|
|
{
|
2013-10-18 20:29:10 +08:00
|
|
|
random_roi();
|
2013-06-19 13:03:35 +08:00
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
columnSum_gold(src_roi, dst_roi);
|
|
|
|
ocl::columnSum(gsrc_roi, gdst_roi);
|
|
|
|
|
|
|
|
Near(1e-5);
|
2013-06-19 13:03:35 +08:00
|
|
|
}
|
|
|
|
}
|
2013-10-14 18:45:15 +08:00
|
|
|
|
2013-06-19 13:03:35 +08:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
INSTANTIATE_TEST_CASE_P(Imgproc, EqualizeHist, Combine(
|
|
|
|
Values((MatType)CV_8UC1),
|
|
|
|
Values(0), // not used
|
|
|
|
Values(0), // not used
|
|
|
|
Bool()));
|
2012-08-30 16:03:46 +08:00
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
INSTANTIATE_TEST_CASE_P(Imgproc, CornerMinEigenVal, Combine(
|
2013-10-29 16:10:20 +08:00
|
|
|
Values((MatType)CV_8UC1, (MatType)CV_32FC1),
|
|
|
|
Values(3, 5),
|
|
|
|
Values((int)BORDER_CONSTANT, (int)BORDER_REPLICATE, (int)BORDER_REFLECT, (int)BORDER_REFLECT101),
|
2013-10-18 20:29:10 +08:00
|
|
|
Bool()));
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(Imgproc, CornerHarris, Combine(
|
2013-11-04 19:09:58 +08:00
|
|
|
Values((MatType)CV_8UC1, CV_32FC1),
|
2013-10-18 20:29:10 +08:00
|
|
|
Values(3, 5),
|
2013-10-29 16:10:20 +08:00
|
|
|
Values( (int)BORDER_CONSTANT, (int)BORDER_REPLICATE, (int)BORDER_REFLECT, (int)BORDER_REFLECT_101),
|
2013-10-18 20:29:10 +08:00
|
|
|
Bool()));
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(Imgproc, Integral, Combine(
|
2013-10-29 16:10:20 +08:00
|
|
|
Values((MatType)CV_8UC1), // TODO does not work with CV_32F, CV_64F
|
2013-10-18 20:29:10 +08:00
|
|
|
Values(0), // not used
|
2013-11-11 14:31:02 +08:00
|
|
|
Values((MatType)CV_32SC1, (MatType)CV_32FC1),
|
2013-10-18 20:29:10 +08:00
|
|
|
Bool()));
|
2012-07-17 01:08:14 +08:00
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(Imgproc, Threshold, Combine(
|
2013-10-28 22:04:34 +08:00
|
|
|
Values(CV_8UC1, CV_8UC2, CV_8UC3, CV_8UC4,
|
|
|
|
CV_16SC1, CV_16SC2, CV_16SC3, CV_16SC4,
|
|
|
|
CV_32FC1, CV_32FC2, CV_32FC3, CV_32FC4),
|
2013-10-18 20:29:10 +08:00
|
|
|
Values(0),
|
|
|
|
Values(ThreshOp(THRESH_BINARY),
|
|
|
|
ThreshOp(THRESH_BINARY_INV), ThreshOp(THRESH_TRUNC),
|
|
|
|
ThreshOp(THRESH_TOZERO), ThreshOp(THRESH_TOZERO_INV)),
|
|
|
|
Bool()));
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(Imgproc, CalcHist, Combine(
|
|
|
|
Values((MatType)CV_8UC1),
|
|
|
|
Values(0), // not used
|
|
|
|
Values(0), // not used
|
|
|
|
Bool()));
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(Imgproc, CLAHETest, Combine(
|
|
|
|
Values(Size(4, 4), Size(32, 8), Size(8, 64)),
|
|
|
|
Values(0.0, 10.0, 62.0, 300.0),
|
|
|
|
Bool()));
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(Imgproc, Convolve, Combine(
|
|
|
|
Values((MatType)CV_32FC1),
|
|
|
|
Values(0), // not used
|
|
|
|
Values(0), // not used
|
|
|
|
Bool()));
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(Imgproc, ColumnSum, Combine(
|
|
|
|
Values(MatType(CV_32FC1)),
|
|
|
|
Values(0), // not used
|
|
|
|
Values(0), // not used
|
|
|
|
Bool()));
|
2013-06-10 18:37:48 +08:00
|
|
|
|
2013-10-18 20:29:10 +08:00
|
|
|
INSTANTIATE_TEST_CASE_P(ImgprocTestBase, CopyMakeBorder, Combine(
|
2013-11-01 23:06:42 +08:00
|
|
|
testing::Values((MatDepth)CV_8U, (MatDepth)CV_16S, (MatDepth)CV_32S, (MatDepth)CV_32F),
|
|
|
|
testing::Values(Channels(1), Channels(3), (Channels)4),
|
2013-10-18 20:29:10 +08:00
|
|
|
Bool(), // border isolated or not
|
2013-11-01 23:06:42 +08:00
|
|
|
Values((Border)BORDER_REPLICATE, (Border)BORDER_REFLECT,
|
|
|
|
(Border)BORDER_WRAP, (Border)BORDER_REFLECT_101),
|
2013-10-18 20:29:10 +08:00
|
|
|
Bool()));
|
2013-06-19 13:03:35 +08:00
|
|
|
|
2012-07-17 01:08:14 +08:00
|
|
|
#endif // HAVE_OPENCL
|