Work with connected components - hierarchy

157 views
Skip to first unread message

Roman

unread,
Mar 26, 2012, 4:12:19 PM3/26/12
to android...@googlegroups.com
Hi,
Im trying to get eyes from absdiff mat - two connected components and filter them with conditions:
  1. The width of the components are about the same.
  2. The height of the components are about the same.
  3. Vertical distance is small.
  4. Reasonable horizontal distance, based on the components’ width.
    List<Mat> contours = new ArrayList<Mat>(10);
    Mat hierarchy = new Mat(200, 200, CvType.CV_32FC1, new Scalar(0));
    Imgproc.findContours(mDiff.submat(eyearea),contours, hierarchy, Imgproc.RETR_CCOMP,Imgproc.CHAIN_APPROX_SIMPLE);
    Is there any example how handle with connected components (.RETR_CCOMP) and filter them?
    Is it over double contourarea =Imgproc.contourArea(contour); - for comparing size and Imgproc.boundingRect(goodpoints).br() / tl() for getting the with and height? Or there is another solution?

Thanks for any hint!

Roman


Rui Marques

unread,
Mar 26, 2012, 6:45:32 PM3/26/12
to android...@googlegroups.com
You should probably browse for how to find the centroid and perimeter of a blob/contour.
Those two parameters will help you figuring out your conditions.
Might also help to take a look at opencv's approxPolyDP function.
It returns a polygon geometrically close to your contour and might be nicer to extract measures of it.
Message has been deleted

Roman

unread,
Mar 30, 2012, 9:58:47 AM3/30/12
to android...@googlegroups.com
So finaly I use bounding boxes for filtering, but still many countours pass - Im not sure how get only countour with two child countours - holes (eyes) to eliminate others.


List<Mat> contours = new ArrayList<Mat>(10);
Mat hierarchy = new Mat(20,20,CvType.CV_32SC2, new Scalar(0));
Imgproc.findContours(mDiff.submat(eyearea),contours, hierarchy, Imgproc.RETR_CCOMP,Imgproc.CHAIN_APPROX_SIMPLE);
int hierarchy_buff_size = (int) (hierarchy.total() * hierarchy.channels());
int iBuff[] = new int[hierarchy_buff_size];
hierarchy.get(0, 0, iBuff);

dump is eg.
Hierarchy = [1, -1, -1, -1, 2, 0, -1, -1, 3, 1, -1, -1, 4, 2, -1, -1, 5, 3, -1, -1, 6, 4, -1, -1, 7, 5, -1, -1, -1, 6, -1, -1]

So contoure in index 4 has 2 holes - childs?
And I could get it via contours.get(4) is the index same? How to get the holes?
hierarchy.get(0, 0, iBuff); - this is for top levels contours right? and for second level hierarchy.get(0,1, iBuff); ?

Thanks
Roman







Dne úterý, 27. března 2012 0:45:32 UTC+2 Rui Marques napsal(a):
Reply all
Reply to author
Forward
0 new messages