I am new to OpenCV and trying to track a circular object using find contours on Android using 3.1.0. I am following the sample color blob detector to write the code, but the drawContours() function never draws anything when I run the application. Here is the onCameraFrame() function, which is doing all the processing. Can you tell me what I am doing wrong?
public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
Mat rgba = inputFrame.rgba();
List contours = new ArrayList();
Mat hierarchy = new Mat();
Mat grayMat = new Mat();
Imgproc.cvtColor(rgba, grayMat, Imgproc.COLOR_RGBA2GRAY);
Imgproc.findContours(grayMat, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);
double maxArea = 0;
Iterator each = contours.iterator();
while(each.hasNext()){
MatOfPoint wrapper = each.next();
double area = Imgproc.contourArea(wrapper);
if(area > maxArea){
maxArea = area;
}
}
List matchedContours = new ArrayList();
matchedContours.clear();
while(each.hasNext()){
MatOfPoint contour = each.next();
if(Imgproc.contourArea(contour) > .1*maxArea){
Core.multiply(contour, new Scalar(4,4), contour);
matchedContours.add(contour);
}
}
Imgproc.drawContours(rgba, matchedContours, -1, new Scalar(0,255,0));
return rgba;
}
↧