c# - Ignore external points when finding rectangles -
i have images need find central rectangle
im using variation of emgucv examples find rectangles , came this
using (memstorage storage = new memstorage()) { //allocate storage contour approximation //contour<point> contours = gray.findcontours() contour<point> contours = gray.findcontours(emgu.cv.cvenum.chain_approx_method.cv_chain_approx_simple, emgu.cv.cvenum.retr_type.cv_retr_list, storage); (; contours != null; contours = contours.hnext) { contour<point> currentcontour = contours.approxpoly(contours.perimeter * 0.05, storage); //seq<point> currentcontour = contours.getconvexhull(emgu.cv.cvenum.orientation.cv_clockwise); if (contours.area > minrectanglearea) //only consider contours area greater 20000 { if (currentcontour.total == 4) //the contour has 4 vertices. { bool isrectangle = true; point[] pts = currentcontour.toarray(); linesegment2d[] edges = pointcollection.polyline(pts, true); (int = 0; < edges.length; i++) { double angle = math.abs(edges[(i + 1) % edges.length].getexteriorangledegree(edges[i])); if (angle < 90 - rectangleanglemargin || angle > rectangleanglemargin + 90) { isrectangle = false; break; } } if (isrectangle) { boxlist.add(currentcontour.getminarearect()); } } } }
}
and result of executing on images finds 2 rectangles:
the orange rectangle ok, thats need. dont want blue. 4 vertex in border of image, 1 of them out.
changing retr_type of findcontours function cv_retr_external, blue rectangle, wonder if there option of not getting contours external points.
the real image can have smaller rectangles inside orange (or line appears splitting rectangle), after i´m selecting bigger rectangle 1 want, cant way blue one.
taking @ sample image choose approach.
instead of classical contour detection, if perform hough line detection , peform intersections of line found, find 4 vertices of rectangle searching for...
if need in coding let me know , edit answer.
Comments
Post a Comment