Extracting Lines from a Blob with Emgu CV

37 views Asked by At

Processed Image:

Processed Image

Problem: Fitting the edges of an unclosed rectangular shape

Description: I need to fit lines to the inner perimeter of the larger rectangle shape shown in the image. The issue I am seeing is that because the contour is not closed by the corner, when using the bounding rectangle method the rectangle fits to the thin line sticking out on the bottom right corner. This leads to incorrect sizing.

Important Condition: it is not important that the lines start and end in the corners of the rectangle. I need to get the rightmost point on the left edge, and the leftmost point on the right edge. The same rules apply to the top/bottom except except I need the lowest point of the top edge and the highest point of the bottom edge

Here is an image of what I am looking for (lines drawn in light blue and yellow):

Desired Processing

Tried:

CvInvoke.FindContours(workingImage, contours, m, Emgu.CV.CvEnum.RetrType.List, Emgu.CV.CvEnum.ChainApproxMethod.ChainApproxSimple);

CvInvoke.ApproxPolyDP(contours[i], approx, precision * perimeter, true);`

CvInvoke.BoundingRectangle(contours[i]);

I hoped ApproxPolyDP would attempt to close the contour, but this did not help the problem.

Questions:

  • Now that I have processed the image, I am wondering how I should approach extracting the geometry of this shape in the case that I don't have sharp corners, my edges have slight curvature, and the rectangular shape is not closed.
  1. Does it make more sense to try and fit lines to the edges, then construct a rectangle from those lines?
  2. If fitting lines is the correct approach, how would I ensure the lines are drawn on the interior of the shape?
  3. Is there a way to force the shape to be closed?
0

There are 0 answers