Ask Your Question

Revision history [back]

How to detect unclosed hexagon?

Hi all

During my studies I worked with matlab so I'm new to opencv…

I would like to detect an unclosed Hexagon in a given BW Image. After some reading tutorials I found the Hough-Line detection as possible solution. But I'm still strugling. I have the Feeling that the opencv is mutch more not userfrendly than matlab. there the same Code workes fine, but the opencv implementation of hough-line detection is strange.

This is the original Image:

Original Image

With the Standard hough line function I got this result (the lines are extrapolated).

Standard HoughLine Detection with extrapolated lines

I found no way to check if the dominant line (first in resulting Vector) is realy part of the inner Hexagon or not. and next there is no possibility to average the found lines so there is only one per Edge. Next I tried to detect if the angels are as expected (the angel difference to the first dominant Hexagon line is Always 120° or even 60° if you look to the oposite direction).

Any succestion, how I could solve this Problem?

Btw. I try to do this in C# so the Code is as following:

double dCannyThreshold = 10;
UMat oCannyEdges = new UMat();
p__oImage.Save("Orig.png");
CvInvoke.Canny(p__oImage, oCannyEdges, dCannyThreshold, dCannyThreshold * 2);

/////////////////////////////////////////////////////
// Hough Line detection
/*
LineSegment2D[] aoLines = CvInvoke.HoughLinesP(
    oCannyEdges, 
    10,                              // Distance resolution of the accumulator in pixels (rho)
    Math.PI / 180,                  // 1° Angle resolution of the accumulator in radians (theta)
    150,                            // Accumulator threshold parameter. Only those lines are returned that get enough votes 
    100,                            // Minimum line length. Line segments shorter than that are rejected.
    10);                            // Maximum allowed gap between points on the same line to link them.
*/            

LineSegment2D[] aoLines;
using (var aoVector = new Emgu.CV.Util.VectorOfPointF())
{
    CvInvoke.HoughLines(
        oCannyEdges, 
        aoVector,
        1,                          // Distance resolution of the accumulator in pixels (rho)
        Math.PI / 180.0,            // 1° Angle resolution of the accumulator in radians
        100);                       // Accumulator threshold parameter. Only those lines are returned that get enough votes
}

Best regards

P51D