Example usage for org.opencv.imgproc Imgproc minEnclosingCircle

List of usage examples for org.opencv.imgproc Imgproc minEnclosingCircle

Introduction

In this page you can find the example usage for org.opencv.imgproc Imgproc minEnclosingCircle.

Prototype

public static void minEnclosingCircle(MatOfPoint2f points, Point center, float[] radius) 

Source Link

Usage

From source file:OCV_MinEnclosingCircle.java

License:Open Source License

@Override
public void run(ImageProcessor ip) {
    byte[] byteArray = (byte[]) ip.getPixels();
    int w = ip.getWidth();
    int h = ip.getHeight();
    int num_slice = ip.getSliceNumber();

    ArrayList<Point> lstPt = new ArrayList<Point>();
    MatOfPoint2f pts = new MatOfPoint2f();

    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {
            if (byteArray[x + w * y] != 0) {
                lstPt.add(new Point((double) x, (double) y));
            }//from w  w w  .  jav a2 s .c  om
        }
    }

    if (lstPt.isEmpty()) {
        return;
    }

    pts.fromList(lstPt);
    float[] radius = new float[1];
    Point center = new Point();
    Imgproc.minEnclosingCircle(pts, center, radius);
    showData(center.x, center.y, (double) radius[0], num_slice);
}

From source file:simeav.filtros.instanciaciones.SeparadorTextoEstandar.java

@Override
public void separarTexto(Mat origin, int umbral_radio) {
    Mat original = origin.clone();//  ww  w.  ja v a 2  s .  c  o  m
    imagenSinTexto = original.clone();
    imagenTexto = Mat.zeros(original.size(), CvType.CV_8U);
    imagenTexto = imagenTexto.setTo(new Scalar(255, 255, 255));
    Mat imGrises = new Mat();
    Mat bw = new Mat();
    Imgproc.cvtColor(original, imGrises, Imgproc.COLOR_BGR2GRAY);
    Imgproc.GaussianBlur(imGrises, bw, new Size(1, 1), 0);
    Imgproc.threshold(bw, bw, 200, 250, Imgproc.THRESH_BINARY_INV);
    ArrayList<MatOfPoint> contornos = Utils.detectarContornos(bw);
    for (int i = 0; i < contornos.size(); i++) {
        MatOfPoint2f contorno2f = new MatOfPoint2f();
        contorno2f.fromList(contornos.get(i).toList());
        float[] radius = new float[1];
        Point centro = new Point();
        Imgproc.minEnclosingCircle(contorno2f, centro, radius);
        double a = Imgproc.contourArea(contornos.get(i));
        if (radius[0] <= umbral_radio) {
            Imgproc.drawContours(imagenSinTexto, contornos, i, new Scalar(255, 255, 255), -1);
            Imgproc.drawContours(imagenTexto, contornos, i, new Scalar(0, 0, 0), -1);
        }
    }
}