Commit f3f55b30 authored by Andrey Kamaev's avatar Andrey Kamaev Committed by OpenCV Buildbot

Merge pull request #267 from pclove1:ocl_hough

parents dc0788c8 06da75ff
......@@ -329,3 +329,38 @@ Interpolate frames (images) using provided optical flow (displacement field).
:param newFrame: Output image.
:param buf: Temporary buffer, will have width x 6*height size, CV_32FC1 type and contain 6 oclMat: occlusion masks for first frame, occlusion masks for second, interpolated forward horizontal flow, interpolated forward vertical flow, interpolated backward horizontal flow, interpolated backward vertical flow.
ocl::HoughCircles
-----------------
Finds circles in a grayscale image using the Hough transform.
.. ocv:function:: void ocl::HoughCircles(const oclMat& src, oclMat& circles, int method, float dp, float minDist, int cannyThreshold, int votesThreshold, int minRadius, int maxRadius, int maxCircles = 4096)
.. ocv:function:: void ocl::HoughCircles(const oclMat& src, oclMat& circles, HoughCirclesBuf& buf, int method, float dp, float minDist, int cannyThreshold, int votesThreshold, int minRadius, int maxRadius, int maxCircles = 4096)
:param src: 8-bit, single-channel grayscale input image.
:param circles: Output vector of found circles. Each vector is encoded as a 3-element floating-point vector :math:`(x, y, radius)` .
:param method: Detection method to use. Currently, the only implemented method is ``CV_HOUGH_GRADIENT`` , which is basically *21HT* , described in [Yuen90]_.
:param dp: Inverse ratio of the accumulator resolution to the image resolution. For example, if ``dp=1`` , the accumulator has the same resolution as the input image. If ``dp=2`` , the accumulator has half as big width and height.
:param minDist: Minimum distance between the centers of the detected circles. If the parameter is too small, multiple neighbor circles may be falsely detected in addition to a true one. If it is too large, some circles may be missed.
:param cannyThreshold: The higher threshold of the two passed to the :ocv:func:`ocl::Canny` edge detector (the lower one is twice smaller).
:param votesThreshold: The accumulator threshold for the circle centers at the detection stage. The smaller it is, the more false circles may be detected.
:param minRadius: Minimum circle radius.
:param maxRadius: Maximum circle radius.
:param maxCircles: Maximum number of output circles.
:param buf: Optional buffer to avoid extra memory allocations (for many calls with the same sizes).
.. note:: Currently only non-ROI oclMat is supported for src.
.. seealso:: :ocv:func:`HoughCircles`
......@@ -41,8 +41,8 @@
//
//M*/
#ifndef __OPENCV_GPU_HPP__
#define __OPENCV_GPU_HPP__
#ifndef __OPENCV_OCL_HPP__
#define __OPENCV_OCL_HPP__
#include <memory>
#include <vector>
......@@ -827,6 +827,22 @@ namespace cv
};
///////////////////////////////////////// Hough Transform /////////////////////////////////////////
//! HoughCircles
struct HoughCirclesBuf
{
oclMat edges;
oclMat accum;
oclMat srcPoints;
oclMat centers;
CannyBuf cannyBuf;
};
CV_EXPORTS void HoughCircles(const oclMat& src, oclMat& circles, int method, float dp, float minDist, int cannyThreshold, int votesThreshold, int minRadius, int maxRadius, int maxCircles = 4096);
CV_EXPORTS void HoughCircles(const oclMat& src, oclMat& circles, HoughCirclesBuf& buf, int method, float dp, float minDist, int cannyThreshold, int votesThreshold, int minRadius, int maxRadius, int maxCircles = 4096);
CV_EXPORTS void HoughCirclesDownload(const oclMat& d_circles, OutputArray h_circles);
///////////////////////////////////////// clAmdFft related /////////////////////////////////////////
//! Performs a forward or inverse discrete Fourier transform (1D or 2D) of floating point matrix.
//! Param dft_size is the size of DFT transform.
......@@ -1746,4 +1762,4 @@ namespace cv
#if _MSC_VER >= 1200
#pragma warning( pop)
#endif
#endif /* __OPENCV_GPU_HPP__ */
#endif /* __OPENCV_OCL_HPP__ */
/*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, Multicoreware, Inc., all rights reserved.
// Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
// 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 oclMaterials 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 "precomp.hpp"
#ifdef HAVE_OPENCL
using namespace cv;
using namespace perf;
//////////////////////////////////////////////////////////////////////
// HoughCircles
typedef std::tr1::tuple<cv::Size, float, float> Size_Dp_MinDist_t;
typedef perf::TestBaseWithParam<Size_Dp_MinDist_t> Size_Dp_MinDist;
PERF_TEST_P(Size_Dp_MinDist, OCL_HoughCircles,
testing::Combine(
testing::Values(perf::sz720p, perf::szSXGA, perf::sz1080p),
testing::Values(1.0f, 2.0f, 4.0f),
testing::Values(1.0f, 10.0f)))
{
const cv::Size size = std::tr1::get<0>(GetParam());
const float dp = std::tr1::get<1>(GetParam());
const float minDist = std::tr1::get<2>(GetParam());
const int minRadius = 10;
const int maxRadius = 30;
const int cannyThreshold = 100;
const int votesThreshold = 15;
cv::RNG rng(123456789);
cv::Mat src(size, CV_8UC1, cv::Scalar::all(0));
const int numCircles = rng.uniform(50, 100);
for (int i = 0; i < numCircles; ++i)
{
cv::Point center(rng.uniform(0, src.cols), rng.uniform(0, src.rows));
const int radius = rng.uniform(minRadius, maxRadius + 1);
cv::circle(src, center, radius, cv::Scalar::all(255), -1);
}
cv::ocl::oclMat ocl_src(src);
cv::ocl::oclMat ocl_circles;
declare.time(10.0).iterations(25);
TEST_CYCLE()
{
cv::ocl::HoughCircles(ocl_src, ocl_circles, CV_HOUGH_GRADIENT, dp, minDist, cannyThreshold, votesThreshold, minRadius, maxRadius);
}
cv::Mat circles(ocl_circles);
SANITY_CHECK(circles);
}
#endif // HAVE_OPENCL
This diff is collapsed.
This diff is collapsed.
/*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) 2008-2011, Willow Garage Inc., all rights reserved.
// 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 Intel Corporation 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 "precomp.hpp"
#ifdef HAVE_OPENCL
///////////////////////////////////////////////////////////////////////////////////////////////////////
// HoughCircles
PARAM_TEST_CASE(HoughCircles, cv::Size)
{
static void drawCircles(cv::Mat& dst, const std::vector<cv::Vec3f>& circles, bool fill)
{
dst.setTo(cv::Scalar::all(0));
for (size_t i = 0; i < circles.size(); ++i)
cv::circle(dst, cv::Point2f(circles[i][0], circles[i][1]), (int)circles[i][2], cv::Scalar::all(255), fill ? -1 : 1);
}
};
TEST_P(HoughCircles, Accuracy)
{
const cv::Size size = GET_PARAM(0);
const float dp = 2.0f;
const float minDist = 10.0f;
const int minRadius = 10;
const int maxRadius = 20;
const int cannyThreshold = 100;
const int votesThreshold = 15;
std::vector<cv::Vec3f> circles_gold(4);
circles_gold[0] = cv::Vec3i(20, 20, minRadius);
circles_gold[1] = cv::Vec3i(90, 87, minRadius + 3);
circles_gold[2] = cv::Vec3i(30, 70, minRadius + 8);
circles_gold[3] = cv::Vec3i(80, 10, maxRadius);
cv::Mat src(size, CV_8UC1);
drawCircles(src, circles_gold, true);
cv::ocl::oclMat d_src(src);
cv::ocl::oclMat d_circles;
cv::ocl::HoughCircles(d_src, d_circles, CV_HOUGH_GRADIENT, dp, minDist, cannyThreshold, votesThreshold, minRadius, maxRadius);
ASSERT_TRUE(d_circles.rows > 0);
cv::Mat circles;
d_circles.download(circles);
for (int i = 0; i < circles.cols; ++i)
{
cv::Vec3f cur = circles.at<cv::Vec3f>(i);
bool found = false;
for (size_t j = 0; j < circles_gold.size(); ++j)
{
cv::Vec3f gold = circles_gold[j];
if (std::fabs(cur[0] - gold[0]) < minDist && std::fabs(cur[1] - gold[1]) < minDist && std::fabs(cur[2] - gold[2]) < minDist)
{
found = true;
break;
}
}
ASSERT_TRUE(found);
}
}
INSTANTIATE_TEST_CASE_P(Hough, HoughCircles, DIFFERENT_SIZES);
#endif // HAVE_OPENCL
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment