Detecting lines, circles, and other shapes
Detecting edges and finding contours are not only common and important tasks in their own right; they also form the basis of other complex operations. Line and shape detection walk hand-in-hand with edge and contour detection, so let's examine how OpenCV implements these.
The theory behind line and shape detection has its foundation in a technique called the Hough transform, invented by Richard Duda and Peter Hart, who extended and generalized the work that was done by Paul Hough in the early 1960s. Let's take a look at OpenCV's API for Hough transforms.
Detecting lines
First of all, let's detect some lines. We can do this with either the HoughLines
function or the HoughLinesP
function. The former uses the standard Hough transform, while the latter uses the probabilistic Hough transform (hence the P
in the name). The probabilistic version is so-called because it only analyzes a subset of the image's points and estimates...