public static EllipseLocationResult locateEllipses(Mat grayImage){
  Mat gray=grayImage.clone();
  Filter.downsample(gray,2);
  Filter.upsample(gray,2);
  Imgproc.Canny(gray,gray,5,75,3,true);
  Filter.dilate(gray,2);
  Mat cacheHierarchy=new Mat();
  List<MatOfPoint> contoursTemp=new ArrayList<>();
  Imgproc.findContours(gray,contoursTemp,cacheHierarchy,Imgproc.CV_RETR_TREE,Imgproc.CHAIN_APPROX_TC89_KCOS);
  List<Contour> contours=new ArrayList<>();
  for (  MatOfPoint co : contoursTemp) {
    contours.add(new Contour(co));
  }
  List<Ellipse> ellipses=new ArrayList<>();
  for (  MatOfPoint co : contoursTemp) {
    contours.add(new Contour(co));
    if (co.toArray().length < 6)     continue;
    MatOfPoint2f matOfPoint2f=new MatOfPoint2f(co.toArray());
    Ellipse ellipse=new Ellipse(Imgproc.fitEllipse(matOfPoint2f));
    ellipses.add(ellipse);
  }
  return new EllipseLocationResult(contours,ellipses);
}

public static EllipseLocationResult locateEllipses ( Mat grayImage ) { Mat gray = grayImage . clone ( ) ; Filter . downsample ( gray , 2 ) ; Filter . upsample ( gray , 2 ) ; Imgproc . Canny ( gray , gray , 5 , 75 , 3 , true ) ; Filter . dilate ( gray , 2 ) ; Mat cacheHierarchy = new Mat ( ) ; List < MatOfPoint > contoursTemp = new ArrayList < > ( ) ; Imgproc . findContours ( gray , contoursTemp , cacheHierarchy , Imgproc . CV_RETR_TREE , Imgproc . CHAIN_APPROX_TC89_KCOS ) ; List < Contour > contours = new ArrayList < > ( ) ; for ( MatOfPoint co : contoursTemp ) { contours . add ( new Contour ( co ) ) ; } List < Ellipse > ellipses = new ArrayList < > ( ) ; for ( MatOfPoint co : contoursTemp ) { contours . add ( new Contour ( co ) ) ; if ( co . toArray ( ) . length < 6 ) continue ; MatOfPoint2f matOfPoint2f = new MatOfPoint2f ( co . toArray ( ) ) ; Ellipse ellipse = new Ellipse ( Imgproc . fitEllipse ( matOfPoint2f ) ) ; ellipses . add ( ellipse ) ; } return new EllipseLocationResult ( contours , ellipses ) ; }
locate ellipses within an image
