Commit 1652540a authored by Vladislav Vinogradov's avatar Vladislav Vinogradov

refactored HoughLines (converted it into Algorithm)

parent 48fb8c4f
...@@ -86,13 +86,14 @@ PERF_TEST_P(Image, HoughLinesP, testing::Values(std::string("im1_1280x800.jpg")) ...@@ -86,13 +86,14 @@ PERF_TEST_P(Image, HoughLinesP, testing::Values(std::string("im1_1280x800.jpg"))
{ {
cv::gpu::GpuMat d_image(image); cv::gpu::GpuMat d_image(image);
cv::gpu::GpuMat d_lines; cv::gpu::GpuMat d_lines;
cv::gpu::HoughLinesBuf d_buf;
cv::gpu::HoughLinesP(d_image, d_lines, d_buf, rho, theta, minLineLenght, maxLineGap); cv::Ptr<cv::gpu::HoughSegmentDetector> hough = cv::gpu::createHoughSegmentDetector(rho, theta, minLineLenght, maxLineGap);
hough->detect(d_image, d_lines);
TEST_CYCLE() TEST_CYCLE()
{ {
cv::gpu::HoughLinesP(d_image, d_lines, d_buf, rho, theta, minLineLenght, maxLineGap); hough->detect(d_image, d_lines);
} }
} }
else else
......
...@@ -220,18 +220,82 @@ inline void Canny(InputArray dx, InputArray dy, OutputArray edges, double low_th ...@@ -220,18 +220,82 @@ inline void Canny(InputArray dx, InputArray dy, OutputArray edges, double low_th
/////////////////////////// Hough Transform //////////////////////////// /////////////////////////// Hough Transform ////////////////////////////
struct HoughLinesBuf //////////////////////////////////////
// HoughLines
class CV_EXPORTS HoughLinesDetector : public Algorithm
{ {
GpuMat accum; public:
GpuMat list; virtual void detect(InputArray src, OutputArray lines) = 0;
virtual void downloadResults(InputArray d_lines, OutputArray h_lines, OutputArray h_votes = noArray()) = 0;
virtual void setRho(float rho) = 0;
virtual float getRho() const = 0;
virtual void setTheta(float theta) = 0;
virtual float getTheta() const = 0;
virtual void setThreshold(int threshold) = 0;
virtual int getThreshold() const = 0;
virtual void setDoSort(bool doSort) = 0;
virtual bool getDoSort() const = 0;
virtual void setMaxLines(int maxLines) = 0;
virtual int getMaxLines() const = 0;
}; };
CV_EXPORTS void HoughLines(const GpuMat& src, GpuMat& lines, float rho, float theta, int threshold, bool doSort = false, int maxLines = 4096); CV_EXPORTS Ptr<HoughLinesDetector> createHoughLinesDetector(float rho, float theta, int threshold, bool doSort = false, int maxLines = 4096);
CV_EXPORTS void HoughLines(const GpuMat& src, GpuMat& lines, HoughLinesBuf& buf, float rho, float theta, int threshold, bool doSort = false, int maxLines = 4096);
CV_EXPORTS void HoughLinesDownload(const GpuMat& d_lines, OutputArray h_lines, OutputArray h_votes = noArray()); // obsolete
__OPENCV_GPUIMGPROC_DEPR_BEFORE__ void HoughLines(InputArray src, OutputArray lines, float rho, float theta, int threshold,
bool doSort = false, int maxLines = 4096) __OPENCV_GPUIMGPROC_DEPR_AFTER__;
inline void HoughLines(InputArray src, OutputArray lines, float rho, float theta, int threshold, bool doSort, int maxLines)
{
gpu::createHoughLinesDetector(rho, theta, threshold, doSort, maxLines)->detect(src, lines);
}
//////////////////////////////////////
// HoughLinesP
//! finds line segments in the black-n-white image using probabalistic Hough transform //! finds line segments in the black-n-white image using probabalistic Hough transform
CV_EXPORTS void HoughLinesP(const GpuMat& image, GpuMat& lines, HoughLinesBuf& buf, float rho, float theta, int minLineLength, int maxLineGap, int maxLines = 4096); class CV_EXPORTS HoughSegmentDetector : public Algorithm
{
public:
virtual void detect(InputArray src, OutputArray lines) = 0;
virtual void setRho(float rho) = 0;
virtual float getRho() const = 0;
virtual void setTheta(float theta) = 0;
virtual float getTheta() const = 0;
virtual void setMinLineLength(int minLineLength) = 0;
virtual int getMinLineLength() const = 0;
virtual void setMaxLineGap(int maxLineGap) = 0;
virtual int getMaxLineGap() const = 0;
virtual void setMaxLines(int maxLines) = 0;
virtual int getMaxLines() const = 0;
};
CV_EXPORTS Ptr<HoughSegmentDetector> createHoughSegmentDetector(float rho, float theta, int minLineLength, int maxLineGap, int maxLines = 4096);
// obsolete
__OPENCV_GPUIMGPROC_DEPR_BEFORE__ void HoughLinesP(InputArray src, OutputArray lines,
float rho, float theta, int minLineLength, int maxLineGap, int maxLines = 4096) __OPENCV_GPUIMGPROC_DEPR_AFTER__;
inline void HoughLinesP(InputArray src, OutputArray lines, float rho, float theta, int minLineLength, int maxLineGap, int maxLines)
{
gpu::createHoughSegmentDetector(rho, theta, minLineLength, maxLineGap, maxLines)->detect(src, lines);
}
//////////////////////////////////////
// HoughCircles
struct HoughCirclesBuf struct HoughCirclesBuf
{ {
...@@ -245,6 +309,9 @@ CV_EXPORTS void HoughCircles(const GpuMat& src, GpuMat& circles, int method, flo ...@@ -245,6 +309,9 @@ CV_EXPORTS void HoughCircles(const GpuMat& src, GpuMat& circles, int method, flo
CV_EXPORTS void HoughCircles(const GpuMat& src, GpuMat& circles, HoughCirclesBuf& buf, int method, float dp, float minDist, int cannyThreshold, int votesThreshold, int minRadius, int maxRadius, int maxCircles = 4096); CV_EXPORTS void HoughCircles(const GpuMat& src, GpuMat& 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 GpuMat& d_circles, OutputArray h_circles); CV_EXPORTS void HoughCirclesDownload(const GpuMat& d_circles, OutputArray h_circles);
//////////////////////////////////////
// GeneralizedHough
//! finds arbitrary template in the grayscale image using Generalized Hough Transform //! finds arbitrary template in the grayscale image using Generalized Hough Transform
//! Ballard, D.H. (1981). Generalizing the Hough transform to detect arbitrary shapes. Pattern Recognition 13 (2): 111-122. //! Ballard, D.H. (1981). Generalizing the Hough transform to detect arbitrary shapes. Pattern Recognition 13 (2): 111-122.
//! Guil, N., González-Linares, J.M. and Zapata, E.L. (1999). Bidimensional shape detection using an invariant approach. Pattern Recognition 32 (6): 1025-1038. //! Guil, N., González-Linares, J.M. and Zapata, E.L. (1999). Bidimensional shape detection using an invariant approach. Pattern Recognition 32 (6): 1025-1038.
......
...@@ -103,9 +103,10 @@ PERF_TEST_P(Sz, HoughLines, ...@@ -103,9 +103,10 @@ PERF_TEST_P(Sz, HoughLines,
{ {
const cv::gpu::GpuMat d_src(src); const cv::gpu::GpuMat d_src(src);
cv::gpu::GpuMat d_lines; cv::gpu::GpuMat d_lines;
cv::gpu::HoughLinesBuf d_buf;
TEST_CYCLE() cv::gpu::HoughLines(d_src, d_lines, d_buf, rho, theta, threshold); cv::Ptr<cv::gpu::HoughLinesDetector> hough = cv::gpu::createHoughLinesDetector(rho, theta, threshold);
TEST_CYCLE() hough->detect(d_src, d_lines);
cv::Mat gpu_lines(d_lines.row(0)); cv::Mat gpu_lines(d_lines.row(0));
cv::Vec2f* begin = gpu_lines.ptr<cv::Vec2f>(0); cv::Vec2f* begin = gpu_lines.ptr<cv::Vec2f>(0);
...@@ -151,9 +152,10 @@ PERF_TEST_P(Image, HoughLinesP, ...@@ -151,9 +152,10 @@ PERF_TEST_P(Image, HoughLinesP,
{ {
const cv::gpu::GpuMat d_mask(mask); const cv::gpu::GpuMat d_mask(mask);
cv::gpu::GpuMat d_lines; cv::gpu::GpuMat d_lines;
cv::gpu::HoughLinesBuf d_buf;
TEST_CYCLE() cv::gpu::HoughLinesP(d_mask, d_lines, d_buf, rho, theta, minLineLenght, maxLineGap); cv::Ptr<cv::gpu::HoughSegmentDetector> hough = cv::gpu::createHoughSegmentDetector(rho, theta, minLineLenght, maxLineGap);
TEST_CYCLE() hough->detect(d_mask, d_lines);
cv::Mat gpu_lines(d_lines); cv::Mat gpu_lines(d_lines);
cv::Vec4i* begin = gpu_lines.ptr<cv::Vec4i>(); cv::Vec4i* begin = gpu_lines.ptr<cv::Vec4i>();
......
This diff is collapsed.
...@@ -94,11 +94,13 @@ GPU_TEST_P(HoughLines, Accuracy) ...@@ -94,11 +94,13 @@ GPU_TEST_P(HoughLines, Accuracy)
cv::Mat src(size, CV_8UC1); cv::Mat src(size, CV_8UC1);
generateLines(src); generateLines(src);
cv::Ptr<cv::gpu::HoughLinesDetector> hough = cv::gpu::createHoughLinesDetector(rho, theta, threshold);
cv::gpu::GpuMat d_lines; cv::gpu::GpuMat d_lines;
cv::gpu::HoughLines(loadMat(src, useRoi), d_lines, rho, theta, threshold); hough->detect(loadMat(src, useRoi), d_lines);
std::vector<cv::Vec2f> lines; std::vector<cv::Vec2f> lines;
cv::gpu::HoughLinesDownload(d_lines, lines); hough->downloadResults(d_lines, lines);
cv::Mat dst(size, CV_8UC1); cv::Mat dst(size, CV_8UC1);
drawLines(dst, lines); drawLines(dst, lines);
......
...@@ -41,7 +41,7 @@ int main(int argc, const char* argv[]) ...@@ -41,7 +41,7 @@ int main(int argc, const char* argv[])
{ {
const int64 start = getTickCount(); const int64 start = getTickCount();
HoughLinesP(mask, lines_cpu, 1, CV_PI / 180, 50, 60, 5); cv::HoughLinesP(mask, lines_cpu, 1, CV_PI / 180, 50, 60, 5);
const double timeSec = (getTickCount() - start) / getTickFrequency(); const double timeSec = (getTickCount() - start) / getTickFrequency();
cout << "CPU Time : " << timeSec * 1000 << " ms" << endl; cout << "CPU Time : " << timeSec * 1000 << " ms" << endl;
...@@ -56,11 +56,12 @@ int main(int argc, const char* argv[]) ...@@ -56,11 +56,12 @@ int main(int argc, const char* argv[])
GpuMat d_src(mask); GpuMat d_src(mask);
GpuMat d_lines; GpuMat d_lines;
HoughLinesBuf d_buf;
{ {
const int64 start = getTickCount(); const int64 start = getTickCount();
gpu::HoughLinesP(d_src, d_lines, d_buf, 1.0f, (float) (CV_PI / 180.0f), 50, 5); Ptr<gpu::HoughSegmentDetector> hough = gpu::createHoughSegmentDetector(1.0f, (float) (CV_PI / 180.0f), 50, 5);
hough->detect(d_src, d_lines);
const double timeSec = (getTickCount() - start) / getTickFrequency(); const double timeSec = (getTickCount() - start) / getTickFrequency();
cout << "GPU Time : " << timeSec * 1000 << " ms" << endl; cout << "GPU Time : " << timeSec * 1000 << " ms" << endl;
......
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