OpenCV offers two implementations of the Hough transform for line detection. The basic version is cv::HoughLines. Its input is a binary map that contains a set of points (represented by nonzero pixels), some of which are aligned to form lines. Usually, this is an edge map obtained, for example, from the Canny operator. The output of the cv::HoughLines function is a vector of the cv::Vec2f elements, each of them being a pair of floating point values, which represents the parameters of a detected line, (ρ, θ). The following is an example of using this function:
- First, apply the Canny operator to obtain the image contours:
// Apply Canny algorithm cv::Mat contours; cv::Canny(image,contours,125,350);
- Then, detect the lines ...