parent
0966e5ffa1
commit
d64bea00b2
4 changed files with 466 additions and 0 deletions
@ -0,0 +1,133 @@ |
|||||||
|
// 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. |
||||||
|
// Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved. |
||||||
|
// Third party copyrights are property of their respective owners. |
||||||
|
// |
||||||
|
// @Authors |
||||||
|
// Niko Li, newlife20080214@gmail.com |
||||||
|
// Jia Haipeng, jiahaipeng95@gmail.com |
||||||
|
// Xu Pang, pangxu010@163.com |
||||||
|
// Wenju He, wenju@multicorewareinc.com |
||||||
|
// 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. |
||||||
|
// |
||||||
|
// |
||||||
|
|
||||||
|
#if histdims == 1 |
||||||
|
|
||||||
|
#define OUT_OF_RANGE -1 |
||||||
|
|
||||||
|
__kernel void calcLUT(__global const uchar * histptr, int hist_step, int hist_offset, int hist_bins, |
||||||
|
__global int * lut, float scale, __constant float * ranges) |
||||||
|
{ |
||||||
|
int x = get_global_id(0); |
||||||
|
float value = convert_float(x); |
||||||
|
|
||||||
|
if (value > ranges[1] || value < ranges[0]) |
||||||
|
lut[x] = OUT_OF_RANGE; |
||||||
|
else |
||||||
|
{ |
||||||
|
float lb = ranges[0], ub = ranges[1], gap = (ub - lb) / hist_bins; |
||||||
|
value -= lb; |
||||||
|
int bin = convert_int_sat_rtn(value / gap); |
||||||
|
|
||||||
|
if (bin >= hist_bins) |
||||||
|
lut[x] = OUT_OF_RANGE; |
||||||
|
else |
||||||
|
{ |
||||||
|
int hist_index = mad24(hist_step, bin, hist_offset); |
||||||
|
__global const float * hist = (__global const float *)(histptr + hist_index); |
||||||
|
|
||||||
|
lut[x] = (int)convert_uchar_sat_rte(hist[0] * scale); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
__kernel void LUT(__global const uchar * src, int src_step, int src_offset, |
||||||
|
__global const int * lut, |
||||||
|
__global uchar * dst, int dst_step, int dst_offset, int dst_rows, int dst_cols) |
||||||
|
{ |
||||||
|
int x = get_global_id(0); |
||||||
|
int y = get_global_id(1); |
||||||
|
|
||||||
|
if (x < dst_cols && y < dst_rows) |
||||||
|
{ |
||||||
|
int src_index = mad24(y, src_step, src_offset + x * scn); |
||||||
|
int dst_index = mad24(y, dst_step, dst_offset + x); |
||||||
|
|
||||||
|
int value = lut[src[src_index]]; |
||||||
|
dst[dst_index] = value == OUT_OF_RANGE ? 0 : convert_uchar(value); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
#elif histdims == 2 |
||||||
|
|
||||||
|
#define OUT_OF_RANGES(i) ( (value##i > ranges[(i<<1)+1]) || (value##i < ranges[i<<1]) ) |
||||||
|
#define CALCULATE_BIN(i) \ |
||||||
|
float lb##i = ranges[i<<1], ub##i = ranges[(i<<1)+1], gap##i = (ub##i - lb##i) / hist_bins##i; \ |
||||||
|
value##i -= ranges[i<<1]; \ |
||||||
|
int bin##i = convert_int_sat_rtn(value##i / gap##i) |
||||||
|
|
||||||
|
__kernel void calcBackProject(__global const uchar * src0, int src0_step, int src0_offset, |
||||||
|
__global const uchar * src1, int src1_step, int src1_offset, |
||||||
|
__global const uchar * histptr, int hist_step, int hist_offset, int hist_bins0, int hist_bins1, |
||||||
|
__global uchar * dst, int dst_step, int dst_offset, int dst_rows, int dst_cols, |
||||||
|
float scale, __constant float * ranges) |
||||||
|
{ |
||||||
|
int x = get_global_id(0); |
||||||
|
int y = get_global_id(1); |
||||||
|
|
||||||
|
if (x < dst_cols && y < dst_rows) |
||||||
|
{ |
||||||
|
int src0_index = mad24(src0_step, y, src0_offset + x * scn0); |
||||||
|
int src1_index = mad24(src1_step, y, src1_offset + x * scn1); |
||||||
|
int dst_index = mad24(dst_step, y, dst_offset + x); |
||||||
|
|
||||||
|
float value0 = convert_float(src0[src0_index]), value1 = convert_float(src1[src1_index]); |
||||||
|
if (OUT_OF_RANGES(0) || OUT_OF_RANGES(1)) |
||||||
|
dst[dst_index] = 0; |
||||||
|
else |
||||||
|
{ |
||||||
|
CALCULATE_BIN(0); |
||||||
|
CALCULATE_BIN(1); |
||||||
|
|
||||||
|
if (bin0 >= hist_bins0 || bin1 >= hist_bins1) |
||||||
|
dst[dst_index] = 0; |
||||||
|
else |
||||||
|
{ |
||||||
|
int hist_index = mad24(hist_step, bin0, hist_offset + bin1 * (int)sizeof(float)); |
||||||
|
__global const float * hist = (__global const float *)(histptr + hist_index); |
||||||
|
|
||||||
|
dst[dst_index] = convert_uchar_sat_rte(scale * hist[0]); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
#else |
||||||
|
#error "(nimages <= 2) should be true" |
||||||
|
#endif |
@ -0,0 +1,184 @@ |
|||||||
|
/*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.
|
||||||
|
// Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved.
|
||||||
|
// 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
|
||||||
|
// Sen Liu, swjtuls1987@126.com
|
||||||
|
//
|
||||||
|
// 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" |
||||||
|
#include "cvconfig.h" |
||||||
|
#include "opencv2/ts/ocl_test.hpp" |
||||||
|
|
||||||
|
#ifdef HAVE_OPENCL |
||||||
|
|
||||||
|
namespace cvtest { |
||||||
|
namespace ocl { |
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
PARAM_TEST_CASE(CalcBackProject, MatDepth, int, bool) |
||||||
|
{ |
||||||
|
int depth, N; |
||||||
|
bool useRoi; |
||||||
|
|
||||||
|
std::vector<float> ranges; |
||||||
|
std::vector<int> channels; |
||||||
|
double scale; |
||||||
|
|
||||||
|
std::vector<Mat> images; |
||||||
|
std::vector<Mat> images_roi; |
||||||
|
std::vector<UMat> uimages; |
||||||
|
std::vector<UMat> uimages_roi; |
||||||
|
|
||||||
|
TEST_DECLARE_INPUT_PARAMETER(hist) |
||||||
|
TEST_DECLARE_OUTPUT_PARAMETER(dst) |
||||||
|
|
||||||
|
virtual void SetUp() |
||||||
|
{ |
||||||
|
depth = GET_PARAM(0); |
||||||
|
N = GET_PARAM(1); |
||||||
|
useRoi = GET_PARAM(2); |
||||||
|
|
||||||
|
ASSERT_GE(2, N); |
||||||
|
|
||||||
|
images.resize(N); |
||||||
|
images_roi.resize(N); |
||||||
|
uimages.resize(N); |
||||||
|
uimages_roi.resize(N); |
||||||
|
} |
||||||
|
|
||||||
|
virtual void random_roi() |
||||||
|
{ |
||||||
|
Size roiSize = randomSize(1, MAX_VALUE); |
||||||
|
|
||||||
|
int totalChannels = 0; |
||||||
|
for (int i = 0; i < N; ++i) |
||||||
|
{ |
||||||
|
Border srcBorder = randomBorder(0, useRoi ? MAX_VALUE : 0); |
||||||
|
int cn = randomInt(1, 5); |
||||||
|
randomSubMat(images[i], images_roi[i], roiSize, srcBorder, CV_MAKE_TYPE(depth, cn), 0, 125); |
||||||
|
|
||||||
|
ranges.push_back(10); |
||||||
|
ranges.push_back(100); |
||||||
|
|
||||||
|
channels.push_back(randomInt(0, cn) + totalChannels); |
||||||
|
totalChannels += cn; |
||||||
|
} |
||||||
|
|
||||||
|
Mat tmpHist; |
||||||
|
{ |
||||||
|
std::vector<int> hist_size(N); |
||||||
|
for (int i = 0 ; i < N; ++i) |
||||||
|
hist_size[i] = randomInt(10, 50); |
||||||
|
|
||||||
|
cv::calcHist(images_roi, channels, noArray(), tmpHist, hist_size, ranges); |
||||||
|
ASSERT_EQ(CV_32FC1, tmpHist.type()); |
||||||
|
} |
||||||
|
|
||||||
|
Border histBorder = randomBorder(0, useRoi ? MAX_VALUE : 0); |
||||||
|
randomSubMat(hist, hist_roi, tmpHist.size(), histBorder, tmpHist.type(), 0, MAX_VALUE); |
||||||
|
tmpHist.copyTo(hist_roi); |
||||||
|
|
||||||
|
Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0); |
||||||
|
randomSubMat(dst, dst_roi, roiSize, dstBorder, CV_MAKE_TYPE(depth, 1), 5, 16); |
||||||
|
|
||||||
|
for (int i = 0; i < N; ++i) |
||||||
|
{ |
||||||
|
images[i].copyTo(uimages[i]); |
||||||
|
|
||||||
|
Size _wholeSize; |
||||||
|
Point ofs; |
||||||
|
images_roi[i].locateROI(_wholeSize, ofs); |
||||||
|
|
||||||
|
uimages_roi[i] = uimages[i](Rect(ofs.x, ofs.y, images_roi[i].cols, images_roi[i].rows)); |
||||||
|
} |
||||||
|
|
||||||
|
UMAT_UPLOAD_INPUT_PARAMETER(hist) |
||||||
|
UMAT_UPLOAD_OUTPUT_PARAMETER(dst) |
||||||
|
|
||||||
|
scale = randomDouble(0.1, 1); |
||||||
|
} |
||||||
|
|
||||||
|
void Near() |
||||||
|
{ |
||||||
|
// std::cout << "Src: " << std::endl << src_roi[0] << std::endl;
|
||||||
|
// std::cout << "Hist: " << std::endl << hist_roi << std::endl;
|
||||||
|
std::cout << "OpenCV: " << std::endl << dst_roi << std::endl; |
||||||
|
std::cout << "OpenCL: " << std::endl << udst_roi.getMat(ACCESS_READ) << std::endl; |
||||||
|
|
||||||
|
Mat diff; |
||||||
|
cv::absdiff(dst_roi, udst_roi, diff); |
||||||
|
std::cout << "Difference: " << std::endl << diff << std::endl; |
||||||
|
|
||||||
|
OCL_EXPECT_MATS_NEAR(dst, 0.0) |
||||||
|
} |
||||||
|
}; |
||||||
|
|
||||||
|
//////////////////////////////// CalcBackProject //////////////////////////////////////////////
|
||||||
|
|
||||||
|
OCL_TEST_P(CalcBackProject, Mat) |
||||||
|
{ |
||||||
|
for (int j = 0; j < test_loop_times; j++) |
||||||
|
{ |
||||||
|
random_roi(); |
||||||
|
|
||||||
|
OCL_OFF(cv::calcBackProject(images_roi, channels, hist_roi, dst_roi, ranges, scale)); |
||||||
|
OCL_ON(cv::calcBackProject(uimages_roi, channels, uhist_roi, udst_roi, ranges, scale)); |
||||||
|
|
||||||
|
Near(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
OCL_INSTANTIATE_TEST_CASE_P(Imgproc, CalcBackProject, Combine(Values((MatDepth)CV_8U), Values(1, 2), Bool())); |
||||||
|
|
||||||
|
} } // namespace cvtest::ocl
|
||||||
|
|
||||||
|
#endif // HAVE_OPENCL
|
Loading…
Reference in new issue