/*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. // 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 "precomp.hpp" namespace cv { namespace gpu { namespace device { namespace hough { unsigned int buildPointList_gpu(DevMem2Db src, unsigned int* list); void linesAccum_gpu(const unsigned int* list, unsigned int count, DevMem2D_ accum, float rho, float theta); unsigned int linesGetResult_gpu(DevMem2D_ accum, float2* out, int* voices, unsigned int maxSize, float rho, float theta, float threshold, bool doSort); } }}} void cv::gpu::HoughLinesTransform(const GpuMat& src, GpuMat& accum, GpuMat& buf, float rho, float theta) { using namespace cv::gpu::device::hough; CV_Assert(src.type() == CV_8UC1); CV_Assert(src.cols < std::numeric_limits::max()); CV_Assert(src.rows < std::numeric_limits::max()); ensureSizeIsEnough(1, src.size().area(), CV_32SC1, buf); unsigned int count = buildPointList_gpu(src, buf.ptr()); // unsigned int count = 0; // { // cv::Mat h_src(src); // cv::Mat h_buf(1, src.size().area(), CV_32SC1); // for (int y = 0; y < h_src.rows; ++y) // { // for (int x = 0; x < h_src.cols; ++x) // { // if (h_src.at(y, x)) // { // const unsigned int val = (y << 16) | x; // h_buf.ptr()[count++] = val; // } // } // } // buf.upload(h_buf); // } const int numangle = cvRound(CV_PI / theta); const int numrho = cvRound(((src.cols + src.rows) * 2 + 1) / rho); ensureSizeIsEnough(numangle + 2, numrho + 2, CV_32SC1, accum); accum.setTo(cv::Scalar::all(0)); if (count > 0) linesAccum_gpu(buf.ptr(), count, accum, rho, theta); } void cv::gpu::HoughLinesGet(const GpuMat& accum, GpuMat& lines, float rho, float theta, int threshold, bool doSort, int maxLines) { using namespace cv::gpu::device; CV_Assert(accum.type() == CV_32SC1); ensureSizeIsEnough(2, maxLines, CV_32FC2, lines); unsigned int count = hough::linesGetResult_gpu(accum, lines.ptr(0), lines.ptr(1), maxLines, rho, theta, threshold, doSort); if (count > 0) lines.cols = count; else lines.release(); } void cv::gpu::HoughLines(const GpuMat& src, GpuMat& lines, float rho, float theta, int threshold, bool doSort, int maxLines) { cv::gpu::GpuMat accum, buf; HoughLines(src, lines, accum, buf, rho, theta, threshold, doSort, maxLines); } void cv::gpu::HoughLines(const GpuMat& src, GpuMat& lines, GpuMat& accum, GpuMat& buf, float rho, float theta, int threshold, bool doSort, int maxLines) { HoughLinesTransform(src, accum, buf, rho, theta); HoughLinesGet(accum, lines, rho, theta, threshold, doSort, maxLines); } void cv::gpu::HoughLinesDownload(const GpuMat& d_lines, OutputArray h_lines_, OutputArray h_voices_) { if (d_lines.empty()) { h_lines_.release(); if (h_voices_.needed()) h_voices_.release(); return; } CV_Assert(d_lines.rows == 2 && d_lines.type() == CV_32FC2); h_lines_.create(1, d_lines.cols, CV_32FC2); cv::Mat h_lines = h_lines_.getMat(); d_lines.row(0).download(h_lines); if (h_voices_.needed()) { h_voices_.create(1, d_lines.cols, CV_32SC1); cv::Mat h_voices = h_voices_.getMat(); cv::gpu::GpuMat d_voices(1, d_lines.cols, CV_32SC1, const_cast(d_lines.ptr(1))); d_voices.download(h_voices); } }