Commit d32a134b authored by Ana Huaman's avatar Ana Huaman

Added Hough Lines Tutorial in reST

parent 1d335bdd
......@@ -313,7 +313,10 @@ extlinks = {'cvt_color': ('http://opencv.willowgarage.com/documentation/cpp/imgp
'laplacian': ('http://opencv.willowgarage.com/documentation/cpp/image_filtering.html#cv-laplacian%s', None),
'canny': ('http://opencv.willowgarage.com/documentation/cpp/imgproc_feature_detection.html?#Canny%s', None),
'copy_to': ('http://opencv.willowgarage.com/documentation/cpp/core_basic_structures.html?#Mat::copyTo%s', None),
'opencv_group' : ('http://tech.groups.yahoo.com/group/OpenCV/%s', None)
'opencv_group' : ('http://tech.groups.yahoo.com/group/OpenCV/%s', None),
'hough_lines' : ('http://opencv.willowgarage.com/documentation/cpp/imgproc_feature_detection.html?#cv-houghlines%s', None),
'hough_lines_p' : ('http://opencv.willowgarage.com/documentation/cpp/imgproc_feature_detection.html?#cv-houghlinesp%s', None),
'hough_circles' : ('http://opencv.willowgarage.com/documentation/cpp/imgproc_feature_detection.html?#cv-houghcircles%s', None)
}
.. _hough_circle:
Hough Circle Transform
***********************
Goal
=====
In this tutorial you will learn how to:
* Use the OpenCV functions :hough_circles:`HoughCircles <>` to detect circles in an image.
Code
======
#. **What does this program do?**
* Loads an image and blur it to reduce the noise
* Applies the *Hough Circle Transform* to the blurred image .
* Display the detected circle in a window.
#. The sample code that we will explain can be downloaded from `here <https://code.ros.org/svn/opencv/trunk/opencv/samples/cpp/houghlines.cpp>`_. A slightly fancier version (which shows both Hough standard and probabilistic with trackbars for changing the threshold values) can be found `here <https://code.ros.org/svn/opencv/trunk/opencv/samples/cpp/tutorial_code/ImgTrans/HoughCircle_Demo.cpp>`_
.. code-block:: cpp
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <stdio.h>
using namespace cv;
/** @function main */
int main(int argc, char** argv)
{
Mat src, src_gray;
/// Read the image
src = imread( argv[1], 1 );
if( !src.data )
{ return -1; }
/// Convert it to gray
cvtColor( src, src_gray, CV_BGR2GRAY );
/// Reduce the noise so we avoid false circle detection
GaussianBlur( src_gray, src_gray, Size(9, 9), 2, 2 );
vector<Vec3f> circles;
/// Apply the Hough Transform to find the circles
HoughCircles( src_gray, circles, CV_HOUGH_GRADIENT, 1, src_gray.rows/8, 200, 100, 0, 0 );
/// Draw the circles detected
for( size_t i = 0; i < circles.size(); i++ )
{
Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
int radius = cvRound(circles[i][2]);
// circle center
circle( src, center, 3, Scalar(0,255,0), -1, 8, 0 );
// circle outline
circle( src, center, radius, Scalar(0,0,255), 3, 8, 0 );
}
/// Show your results
namedWindow( "Hough Circle Transform Demo", CV_WINDOW_AUTOSIZE );
imshow( "Hough Circle Transform Demo", src );
waitKey(0);
return 0;
}
Result
=======
.. image:: images/Hough_Circle_Tutorial_Result.jpg
:alt: Result of detecting circles with Hough Transform
:align: center
This diff is collapsed.
......@@ -10,8 +10,8 @@ In this tutorial you will learn how to:
* Use the OpenCV functions :pyr_up:`pyrUp <>` and :pyr_down:`pyrDown <>` to downsample or upsample a given image.
Cool Theory
============
Theory
=======
.. note::
The explanation below belongs to the book **Learning OpenCV** by Bradski and Kaehler.
......
......@@ -196,3 +196,39 @@ In this section you will learn about the image processing (manipulation) functio
:height: 100pt
:width: 100pt
* :ref:`hough_lines`
===================== ==============================================
|HoughLines| *Title:* **Hough Line Transform**
*Compatibility:* > OpenCV 2.0
*Author:* |Author_AnaH|
Where we learn how to detect lines
===================== ==============================================
.. |HoughLines| image:: images/imgtrans/Hough_Lines_Tutorial_Cover.jpg
:height: 100pt
:width: 100pt
* :ref:`hough_circle`
===================== ==============================================
|HoughCircle| *Title:* **Hough Circle Transform**
*Compatibility:* > OpenCV 2.0
*Author:* |Author_AnaH|
Where we learn how to detect circles
===================== ==============================================
.. |HoughCircle| image:: images/imgtrans/Hough_Circle_Tutorial_Cover.jpg
:height: 100pt
:width: 100pt
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