Learning OpenCV---() opencv Hough Transform: Hough line transformation, Hough Circle transformation

Source: Internet
Author: User
Tags image line

Tag: ble init IDT process ogr expression direction requires har

In This article, we will study the knowledge points related to Hough transform in OpenCV, and understand the use of HOUGHLINES,HOUGHLINESP functions to realize the OPENCV transformation in the The method of using the Houghcircles function of the Huffman Circle transform is realized.

Let's have a taste of it. One of the sample programs runs:

First, Introduction

In the field of image processing and computer vision, how to extract the required feature information from the current image is the key of image recognition. In many applications, straight lines or circles need to be detected quickly and accurately. One of the most effective methods to solve the problem is the Hough (Hough) transformation, which is one of the basic methods of image recognition from image processing, which is widely used and has many improved algorithms. The most basic Hough transform is to detect straight lines (line segments) from black and white images, this article will introduce the use of Hough Transform in OPENCV and related knowledge.

ii. Overview of Hough Transform

Hough Transform (Hough Transform) is a feature extraction technique in image processing, in which a set of matching shapes is obtained by calculating the local maximum value of the accumulated results in a parameter space as the result of Hough transform.

The Hough transform was first proposed by Paulhough in 1962 and the original Hough transformation was designed to detect lines and curves , and the initial method required to know the analytic equation of the boundary of the object, but did not require prior knowledge of the location of the area. One of the outstanding advantages of this method is the robustness of the segmentation result, which is not very sensitive to the incomplete or noisy data. However, it is often impossible to obtain the analytic representation of the boundary.

Later in 1972 by Richard Duda & Peter Hart, the classic Hough transform was used to detect straight lines in the image, and later the Hough transform was extended to the recognition of any Shape object , many circles and ellipses. The Hough transform uses the transformation between two coordinate spaces to form a peak at a point in a space with the same shape in a curve or line mapped to another coordinate space, thus transforming the problem of detecting arbitrary shape into a statistical peak problem.

The Hough transform is divided into Hough-line transformation and Huo-yuan transformation in OpenCV, and the following will be introduced respectively.

three, Hough line transformationThe Hough Line transformation in 3.1 OpenCV

we know that Hough line transformation is a method to find a straight line, before using Hough transform, the first thing to do the edge detection of the image processing, that is, the direct input of the Hough Line transformation can only be the edge binary image.

The OPENCV supports three different Huffman transformation lines, namely the standard Hough transform (standardized hough Transform,sht) and Multiscale Hough transform (multi-scale hough Transform,msht), Cumulative probability Hough Transform (Progressive probablilistic Hough transform,ppht)

Among them, the Multiscale Hough transform (Msht) is a variant of the classical Hough transform (SHT) in multi-scale. The cumulative Probabilistic Hough transform (PPHT) algorithm is an improvement of the standard Hough transform (SHT) algorithm.

It carries out the Huffman transformation within a certain range, calculates the direction and the range of individual segments, thus reducing the computational amount and shortening the calculation time. The reason why PPHT is "probability" is that it does not accumulate all the possible points in the accumulator plane, but adds up to some of it, and the idea is that if the peaks are high enough, only a fraction of the time to find them is enough. This conjecture can substantially reduce the computational time.

In OpenCV, we can use the Houghlines function to invoke the standard Hough transform Sht and the Multiscale Hough transform Msht.

The HOUGHLINESP function is used to invoke the PPHT of the cumulative probability Hough transform. The cumulative probability of the Hough transform is highly efficient, and we prefer to use the HOUGHLINESP function compared to the Houghlines function.

to summarize, there are three types of Hough line transformations in OpenCV:  

<1> Standard Hough transform (Standardhough Transform,sht), called by the Houghlines function.

<2> multiscale Hough Transform (Multi-scalehough Transform,msht), called by the Houghlines function.

<3> cumulative probability Hough transform (progressiveprobabilistic Hough transform,ppht), called by the HOUGHLINESP function.

3.2 The principle of Hough line transformation

"1" It is known that a straight line in the image two-dimensional space can be represented by two variables, such as:

(1) in Cartesian coordinate system: can be represented by parameters: slope and intercept (M,B)

(2) in polar coordinate system: can be represented by parameters: polar diameter and polar angle

For the Hough transform, we will use the second polar coordinate system to represent the line, so the line expression can be:

Easy to get:

"2" in general, for points, we can define a family line through this point uniformly as:

This means that each pair represents a straight line through the point.

"3" if for a given point we draw all straight lines through it in polar coordinates to the polar angle plane, we will get a sine curve. For example, for a given point x_0= 8 and y_0= 6 we can draw (in the plane):

Only points that meet the following conditions are plotted.

"4" We can do this for all the points in the image. If the curve obtained after the above operation of two different points intersects the plane, this means that it we go through the same line. For example, after the example above we continue to plot points and points, get:

The three curves intersect at the point (0.925, 9.6) in the plane, and the coordinates represent the straight lines within the plane of the parameter pair or point, point, and Point.

"5" above indicates that, in general, a straight line can be detected by looking at the number of curves in the plane. And the more the curve is at a point, the more points the line is represented by the intersection. In general, we can define how many curves to turn at a point by setting a threshold on a line. We thought we had detected a straight line.

"6" This is what the Hough line transforms to do. It tracks the intersection of each point in the image that corresponds to the curve. If the number of curves that have been crossed to a point exceeds the threshold, then you can assume that the argument represented by this intersection is a straight line in the original image.

3.3 houghlines () function

This function can take a standard Hough transform two-value image line. In OpenCV, we can invoke the OPENCV built-in algorithm of standard Hough transform Sht and Multiscale Hough transform Msht.

1 void Double Double int Double srn=0double stn=0 );

    • The first parameter, the Inputarray type of image, the input images, that is, the source image, a 8-bit single-channel binary image, you can load any of the source map into the function after the change to this format, and then fill in here.
    • The second parameter, the Inputarray type of lines, stores the output vectors of the line transformation detected by the Hough line transform after calling the Houghlines function. Each line is represented by a vector of two elements

      , which is the distance from the origin of the coordinates ((0,0) (that is, the upper-left corner of the image). is the Radian line rotation angle (0~ vertical, π/2~ horizontal).

    • The third argument, the double type of rho, is the distance precision in pixels. Another way to describe this is the unit radius of the progressive dimension when searching straight lines. Ps:latex in the/rho is said.
    • The fourth argument, the theta of the double type, the angular precision in radians. Another way to describe this is the unit angle of the progressive dimension when searching straight lines.
    • The fifth parameter, the threshold of the int type, is the threshold parameter of the cumulative plane, which is the value that must be reached in the accumulation plane when a part is divided into a straight line in the graph. Segments greater than the threshold threshold can be detected and returned to the results.
    • The sixth argument, a double of type SRN, has a default value of 0. For multi-scale Hough transforms, this is the third parameter of progressive size Rho's divisor distance. The rough accumulator progression dimension is directly the third parameter rho, while the precise accumulator progressive size is RHO/SRN.
    • The seventh parameter, STN of type double, has a default value of 0, and for Multiscale Hough Transforms, SRN represents the divisor distance of the unit angle theta for the fourth parameter progression dimension. And if the SRN and STN are 0 simultaneously, the classical Hough transform is used. Otherwise, both of these parameters should be positive.

After the completion of the function analysis, to see the light ink for everyone to prepare the houghlines as the core of the sample program, you can fully understand the use of the Houghlines function method:

Learning OpenCV---() opencv Hough Transform: Hough line transformation, Hough Circle transformation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.