1 /*M///////////////////////////////////////////////////////////////////////////////////////
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install,
7 // copy or use the software.
11 // For Open Source Computer Vision Library
13 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
15 // Third party copyrights are property of their respective owners.
17 // Redistribution and use in source and binary forms, with or without modification,
18 // are permitted provided that the following conditions are met:
20 // * Redistribution's of source code must retain the above copyright notice,
21 // this list of conditions and the following disclaimer.
23 // * Redistribution's in binary form must reproduce the above copyright notice,
24 // this list of conditions and the following disclaimer in the documentation
25 // and/or other materials provided with the distribution.
27 // * The name of the copyright holders may not be used to endorse or promote products
28 // derived from this software without specific prior written permission.
30 // This software is provided by the copyright holders and contributors "as is" and
31 // any express or implied warranties, including, but not limited to, the implied
32 // warranties of merchantability and fitness for a particular purpose are disclaimed.
33 // In no event shall the Intel Corporation or contributors be liable for any direct,
34 // indirect, incidental, special, exemplary, or consequential damages
35 // (including, but not limited to, procurement of substitute goods or services;
36 // loss of use, data, or profits; or business interruption) however caused
37 // and on any theory of liability, whether in contract, strict liability,
38 // or tort (including negligence or otherwise) arising in any way out of
39 // the use of this software, even if advised of the possibility of such damage.
43 #include "precomp.hpp"
45 namespace cv { namespace gpu { namespace device
49 unsigned int buildPointList_gpu(DevMem2Db src, unsigned int* list);
50 void linesAccum_gpu(const unsigned int* list, unsigned int count, DevMem2D_<unsigned int> accum, float rho, float theta);
51 unsigned int linesGetResult_gpu(DevMem2D_<uint> accum, float2* out, int* voices, unsigned int maxSize, float rho, float theta, float threshold, bool doSort);
55 void cv::gpu::HoughLinesTransform(const GpuMat& src, GpuMat& accum, GpuMat& buf, float rho, float theta)
57 using namespace cv::gpu::device::hough;
59 CV_Assert(src.type() == CV_8UC1);
60 CV_Assert(src.cols < std::numeric_limits<unsigned short>::max());
61 CV_Assert(src.rows < std::numeric_limits<unsigned short>::max());
63 ensureSizeIsEnough(1, src.size().area(), CV_32SC1, buf);
65 unsigned int count = buildPointList_gpu(src, buf.ptr<unsigned int>());
67 const int numangle = cvRound(CV_PI / theta);
68 const int numrho = cvRound(((src.cols + src.rows) * 2 + 1) / rho);
70 ensureSizeIsEnough(numangle + 2, numrho + 2, CV_32SC1, accum);
71 accum.setTo(cv::Scalar::all(0));
73 linesAccum_gpu(buf.ptr<unsigned int>(), count, accum, rho, theta);
76 void cv::gpu::HoughLinesGet(const GpuMat& accum, GpuMat& lines, float rho, float theta, int threshold, bool doSort, int maxLines)
78 using namespace cv::gpu::device;
80 CV_Assert(accum.type() == CV_32SC1);
82 ensureSizeIsEnough(2, maxLines, CV_32FC2, lines);
83 unsigned int count = hough::linesGetResult_gpu(accum, lines.ptr<float2>(0), lines.ptr<int>(1), maxLines, rho, theta, threshold, doSort);
91 void cv::gpu::HoughLines(const GpuMat& src, GpuMat& lines, float rho, float theta, int threshold, bool doSort, int maxLines)
93 cv::gpu::GpuMat accum, buf;
94 HoughLines(src, lines, accum, buf, rho, theta, threshold, doSort, maxLines);
97 void cv::gpu::HoughLines(const GpuMat& src, GpuMat& lines, GpuMat& accum, GpuMat& buf, float rho, float theta, int threshold, bool doSort, int maxLines)
99 HoughLinesTransform(src, accum, buf, rho, theta);
100 HoughLinesGet(accum, lines, rho, theta, threshold, doSort, maxLines);
103 void cv::gpu::HoughLinesDownload(const GpuMat& d_lines, OutputArray h_lines_, OutputArray h_voices_)
108 if (h_voices_.needed())
113 CV_Assert(d_lines.rows == 2 && d_lines.type() == CV_32FC2);
115 h_lines_.create(1, d_lines.cols, CV_32FC2);
116 cv::Mat h_lines = h_lines_.getMat();
117 d_lines.row(0).download(h_lines);
119 if (h_voices_.needed())
121 h_voices_.create(1, d_lines.cols, CV_32SC1);
122 cv::Mat h_voices = h_voices_.getMat();
123 cv::gpu::GpuMat d_voices(1, d_lines.cols, CV_32SC1, const_cast<int*>(d_lines.ptr<int>(1)));
124 d_voices.download(h_voices);