Hi,
Ok, my code is very similar only I didn't had the size and type of your matObject set. But how to use that matObject, how can I see if a contour is a child of an other contour or if a contour has a child?
My current code:
[code]
Imgproc.threshold(mGray, mExtra, 100, 255, Imgproc.THRESH_BINARY);
List<Mat> contours = new ArrayList<Mat>();
Mat hierarchy = new Mat(new Size(320,240),CvType.CV_8UC1,new Scalar(0));
Imgproc.findContours(mExtra, contours, hierarchy, 3, 2);
Imgproc.cvtColor(mExtra, mRgba, Imgproc.COLOR_GRAY2RGBA, 4);
if (contours.size() > 2 && contours.size() < 20)
{
for (int i = 0; i < contours.size(); i++)
{
Mat c = contours.get(i);
int num = (int) c.total();
int buff[] = new int[num*2]; // [x1, y1, x2, y2, ...]
c.get(0, 0, buff);
List<Point> points = new ArrayList<Point>(num);
for (int p = 0; p < num*2; p+=2)
{
points.add(new Point(buff[p], buff[p+1]));
}
Rect rect = Imgproc.boundingRect(points);
Scalar lcolor;
//if (hierarchy == -1)
// lcolor = new Scalar(255,0,0);
//else
lcolor = new Scalar(0,0,255);
Core.line(mRgba, new Point(rect.x, rect.y), new Point(rect.x+rect.width, rect.y+rect.height), lcolor);
Log.i("vision", "draw line through contour: "+num+" points, ("+rect.x+","+rect.y+"), "+rect.width+"x"+rect.height);
}
}
[/code]
Joram