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 #if !defined (HAVE_CUDA)
47 void cv::gpu::HoughLinesTransform(const GpuMat&, GpuMat&, GpuMat&, float, float) { throw_nogpu(); }
48 void cv::gpu::HoughLinesGet(const GpuMat&, GpuMat&, float, float, int, bool, int) { throw_nogpu(); }
49 void cv::gpu::HoughLines(const GpuMat&, GpuMat&, float, float, int, bool, int) { throw_nogpu(); }
50 void cv::gpu::HoughLines(const GpuMat&, GpuMat&, GpuMat&, GpuMat&, float, float, int, bool, int) { throw_nogpu(); }
51 void cv::gpu::HoughLinesDownload(const GpuMat&, OutputArray, OutputArray) { throw_nogpu(); }
53 #else /* !defined (HAVE_CUDA) */
55 namespace cv { namespace gpu { namespace device
59 int buildPointList_gpu(DevMem2Db src, unsigned int* list);
61 void linesAccum_gpu(const unsigned int* list, int count, DevMem2Di accum, float rho, float theta, size_t sharedMemPerBlock, bool has20);
62 int linesGetResult_gpu(DevMem2Di accum, float2* out, int* votes, int maxSize, float rho, float theta, float threshold, bool doSort);
66 //////////////////////////////////////////////////////////
69 void cv::gpu::HoughLines(const GpuMat& src, GpuMat& lines, float rho, float theta, int threshold, bool doSort, int maxLines)
72 HoughLines(src, lines, accum, buf, rho, theta, threshold, doSort, maxLines);
75 void cv::gpu::HoughLines(const GpuMat& src, GpuMat& lines, GpuMat& accum, GpuMat& buf, float rho, float theta, int threshold, bool doSort, int maxLines)
77 HoughLinesTransform(src, accum, buf, rho, theta);
78 HoughLinesGet(accum, lines, rho, theta, threshold, doSort, maxLines);
81 void cv::gpu::HoughLinesTransform(const GpuMat& src, GpuMat& accum, GpuMat& buf, float rho, float theta)
83 using namespace cv::gpu::device::hough;
85 CV_Assert(src.type() == CV_8UC1);
86 CV_Assert(src.cols < std::numeric_limits<unsigned short>::max());
87 CV_Assert(src.rows < std::numeric_limits<unsigned short>::max());
89 ensureSizeIsEnough(1, src.size().area(), CV_32SC1, buf);
91 const int count = buildPointList_gpu(src, buf.ptr<unsigned int>());
93 const int numangle = cvRound(CV_PI / theta);
94 const int numrho = cvRound(((src.cols + src.rows) * 2 + 1) / rho);
96 CV_Assert(numangle > 0 && numrho > 0);
98 ensureSizeIsEnough(numangle + 2, numrho + 2, CV_32SC1, accum);
99 accum.setTo(Scalar::all(0));
104 linesAccum_gpu(buf.ptr<unsigned int>(), count, accum, rho, theta, devInfo.sharedMemPerBlock(), devInfo.supports(FEATURE_SET_COMPUTE_20));
107 void cv::gpu::HoughLinesGet(const GpuMat& accum, GpuMat& lines, float rho, float theta, int threshold, bool doSort, int maxLines)
109 using namespace cv::gpu::device::hough;
111 CV_Assert(accum.type() == CV_32SC1);
113 ensureSizeIsEnough(2, maxLines, CV_32FC2, lines);
115 int count = linesGetResult_gpu(accum, lines.ptr<float2>(0), lines.ptr<int>(1), maxLines, rho, theta, threshold, doSort);
123 void cv::gpu::HoughLinesDownload(const GpuMat& d_lines, OutputArray h_lines_, OutputArray h_votes_)
128 if (h_votes_.needed())
133 CV_Assert(d_lines.rows == 2 && d_lines.type() == CV_32FC2);
135 h_lines_.create(1, d_lines.cols, CV_32FC2);
136 Mat h_lines = h_lines_.getMat();
137 d_lines.row(0).download(h_lines);
139 if (h_votes_.needed())
141 h_votes_.create(1, d_lines.cols, CV_32SC1);
142 Mat h_votes = h_votes_.getMat();
143 GpuMat d_votes(1, d_lines.cols, CV_32SC1, const_cast<int*>(d_lines.ptr<int>(1)));
144 d_votes.download(h_votes);
148 #endif /* !defined (HAVE_CUDA) */