Example usage for org.opencv.core Point Point

List of usage examples for org.opencv.core Point Point

Introduction

In this page you can find the example usage for org.opencv.core Point Point.

Prototype

public Point(double x, double y) 

Source Link

Usage

From source file:OCV_GetRotationMatrix2D.java

License:Open Source License

@Override
public void run(ImageProcessor ip) {
    Mat mat = Imgproc.getRotationMatrix2D(new Point(center_x, center_y), angle, scale);

    if (mat == null || mat.rows() <= 0 || mat.cols() <= 0) {
        IJ.showMessage("Output is null or error");
        return;/*from   w w  w. ja va 2 s  . c  om*/
    }

    ResultsTable rt = OCV__LoadLibrary.GetResultsTable(true);
    rt.incrementCounter();
    rt.addValue("Column01", String.valueOf(mat.get(0, 0)[0]));
    rt.addValue("Column02", String.valueOf(mat.get(0, 1)[0]));
    rt.addValue("Column03", String.valueOf(mat.get(0, 2)[0]));
    rt.incrementCounter();
    rt.addValue("Column01", String.valueOf(mat.get(1, 0)[0]));
    rt.addValue("Column02", String.valueOf(mat.get(1, 1)[0]));
    rt.addValue("Column03", String.valueOf(mat.get(1, 2)[0]));
    rt.show("Results");
}

From source file:ImageReade.java

public static void detectLetter(Mat img) {
    ArrayList<Rect> boundRect = new ArrayList<>();
    Mat img_gray, img_sobel, img_threshold, element;
    img_gray = new Mat();
    img_sobel = new Mat();
    img_threshold = new Mat();
    element = new Mat();
    Imgproc.cvtColor(img, img_gray, Imgproc.COLOR_BGRA2GRAY);
    imshow("Rec img_gray", img_gray);
    Imgproc.Sobel(img_gray, img_sobel, CvType.CV_8U, 1, 0, 3, 1, 0, Imgproc.BORDER_DEFAULT);
    imshow("Rec img_sobel", img_sobel);
    Imgproc.threshold(img_sobel, img_threshold, 0, 255, CV_THRESH_OTSU + CV_THRESH_BINARY);
    imshow("Rec img_threshold", img_threshold);

    element = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(16, 6));

    Imgproc.morphologyEx(img_threshold, img_threshold, CV_MOP_CLOSE, element);
    imshow("Rec img_threshold second", img_threshold);

    List<MatOfPoint> contours = new ArrayList<MatOfPoint>();

    //Imgproc.findContours(img_threshold, contours, new Mat(), Imgproc.RETR_LIST,Imgproc.CHAIN_APPROX_SIMPLE);
    Imgproc.findContours(img_threshold, contours, new Mat(), 0, 1);

    for (int i = 0; i < contours.size(); i++) {
        System.out.println(Imgproc.contourArea(contours.get(i)));
        //            if (Imgproc.contourArea(contours.get(i)) > 100) {
        //                //Imgproc.approxPolyDP( contours.get(i), contours_poly[i], 3, true );
        //                Rect rect = Imgproc.boundingRect(contours.get(i));
        //                System.out.println(rect.height);
        //                if (rect.width > rect.height) {
        //                    //System.out.println(rect.x +","+rect.y+","+rect.height+","+rect.width);
        //                    Core.rectangle(img, new Point(rect.x,rect.y), new Point(rect.x+rect.width,rect.y+rect.height),new Scalar(0,0,255));
        //                }
        //                    
        //                    
        //            }
        if (Imgproc.contourArea(contours.get(i)) > 100) {
            MatOfPoint2f mMOP2f1 = new MatOfPoint2f();
            MatOfPoint2f mMOP2f2 = new MatOfPoint2f();
            contours.get(i).convertTo(mMOP2f1, CvType.CV_32FC2);
            Imgproc.approxPolyDP(mMOP2f1, mMOP2f2, 3, true);
            mMOP2f2.convertTo(contours.get(i), CvType.CV_32S);
            Rect rect = Imgproc.boundingRect(contours.get(i));
            if (rect.width > rect.height) {
                Core.rectangle(img, new Point(rect.x, rect.y),
                        new Point(rect.x + rect.width, rect.y + rect.height), new Scalar(0, 0, 255));
            }//from w ww.j  a  va  2  s .  c  o  m
        }
    }
    imshow("Rec Detected", img);
}

From source file:OCV_LinearPolar.java

License:Open Source License

@Override
public void run(ImageProcessor ip) {
    // srcdst/*w  ww.j  a v a2s.c  om*/
    int imw = ip.getWidth();
    int imh = ip.getHeight();
    byte[] srcdst_ar = (byte[]) ip.getPixels();

    // mat
    Mat src_mat = new Mat(imh, imw, CvType.CV_8UC1);
    Mat dst_mat = new Mat(imh, imw, CvType.CV_8UC1);

    // run
    src_mat.put(0, 0, srcdst_ar);
    Imgproc.linearPolar(src_mat, dst_mat, new Point(cx, cy), (double) rmax, TYPE_INT[type_ind]);
    dst_mat.get(0, 0, srcdst_ar);
}

From source file:WK_RoiMan_DisplayedInTheCenter.java

License:Open Source License

/**
 * get the coordinates of the roi(ref:XYCoordinates.saveSelectionCoordinates())
 * @param roi//from  w w w .ja v  a 2 s  .c  om
 * @param lstPt 
 */
private void getCoordinates(Roi roi, ArrayList<Point> lstPt) {
    ImageProcessor mask = roi.getMask();
    Rectangle r = roi.getBounds();
    int pos_x = 0;
    int pos_y = 0;

    for (int y = 0; y < r.height; y++) {
        for (int x = 0; x < r.width; x++) {
            if (mask == null || mask.getPixel(x, y) != 0) {
                pos_x = r.x + x;
                pos_y = r.y + y;
                lstPt.add(new Point(pos_x, pos_y));
            }
        }
    }
}

From source file:Fiji_OpenCV.java

License:Creative Commons License

public void process(int[] pixels) {
    int channels = 3;
    byte[] buf = new byte[pixels.length * channels];
    for (int i = 0; i < pixels.length; i++) {
        buf[i * channels] = (byte) (0x000000ff & (pixels[i]));
        buf[i * channels + 1] = (byte) (0x000000ff & (pixels[i] >>> 8));
        buf[i * channels + 2] = (byte) (0x000000ff & (pixels[i] >>> 16));
    }/*ww w  .  j a  v  a  2  s .c om*/

    Mat image = new Mat(width, height, CvType.CV_8UC3);
    image.put(0, 0, buf);

    // Create a face detector from the cascade file in the resources
    // directory.
    CascadeClassifier faceDetector = new CascadeClassifier(
            getClass().getResource("/opencv/data/haarcascades/haarcascade_frontalface_alt2.xml").getPath());

    // Detect faces in the image.
    // MatOfRect is a special container class for Rect.
    MatOfRect faceDetections = new MatOfRect();
    faceDetector.detectMultiScale(image, faceDetections);

    System.out.println(String.format("Detected %s faces", faceDetections.toArray().length));

    // Draw a bounding box around each face.
    for (Rect rect : faceDetections.toArray()) {
        Core.rectangle(image, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height),
                new Scalar(0, 255, 0));
    }

    image.get(0, 0, buf);
    for (int i = 0; i < pixels.length; i++) {
        pixels[i] = 0x80000000 + ((int) (buf[i * channels + 2]) << 16) + ((int) (buf[i * channels + 1]) << 8)
                + ((int) (buf[i * channels + 0]));
    }
    this.ip = new ColorProcessor(width, height, pixels);
}

From source file:KoTrendline.java

License:Open Source License

/**
 * @return a Point containing the coordinates of the bottom-most (or leftmost)
 *          stone in this trendline.// w ww. j  a  v a2s  .c  o m
 */
public Point getBottomPoint() {
    double origin = getOrigin();
    double max = 0;
    for (KoCircle current : this.constituents) {
        if (orientation == X_ORIENTATION) {
            if (current.getImgX() > max) {
                max = current.getImgX();
            }
        }
        if (orientation == Y_ORIENTATION) {
            if (current.getImgY() > max) {
                max = current.getImgY();
            }
        }
    }
    if (orientation == X_ORIENTATION) {
        return new Point(max, origin);
    } else {
        return new Point(origin, max);
    }
}

From source file:KoTrendline.java

License:Open Source License

/**
 * @return a Point containing the coordinates of the topmost (or rightmost)
 *          stone in this trendline.// ww w .  j a v a2  s  . c o m
 */
public Point getTopPoint() {
    double origin = getOrigin();
    double min = Double.MAX_VALUE;
    for (KoCircle current : this.constituents) {
        if (orientation == X_ORIENTATION) {
            if (current.getImgX() < min) {
                min = current.getImgX();
            }
        }
        if (orientation == Y_ORIENTATION) {
            if (current.getImgY() < min) {
                min = current.getImgY();
            }
        }
    }
    if (orientation == X_ORIENTATION) {
        return new Point(min, origin);
    } else {
        return new Point(origin, min);
    }
}

From source file:ThirdTry.java

public static void detectLetter(Mat img, Mat m2) {
    ArrayList<Rect> boundRect = new ArrayList<>();
    Mat img_gray, img_sobel, img_threshold, element;
    img_gray = new Mat();
    img_sobel = new Mat();
    img_threshold = new Mat();
    element = new Mat();
    Imgproc.cvtColor(img, img_gray, Imgproc.COLOR_BGRA2GRAY);
    //imshow("Rec img_gray", img_gray);
    Imgproc.Sobel(img_gray, img_sobel, CvType.CV_8UC1, 1, 0, 3, 1, 0, Imgproc.BORDER_DEFAULT);
    //imshow("Rec img_sobel", img_sobel);
    Imgproc.threshold(m2, img_threshold, 0, 255, CV_THRESH_OTSU + CV_THRESH_BINARY);
    //imshow("Rec img_threshold", img_threshold);

    element = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(3, 2));

    Imgproc.morphologyEx(m2, img_threshold, CV_MOP_CLOSE, element);
    imshow("Rec img_threshold second", img_threshold);

    element = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(12, 12));
    Imgproc.morphologyEx(img_threshold, img_threshold, CV_MOP_CLOSE, element);
    //imshow("Rec img_threshold second", img_threshold);

    List<MatOfPoint> contours = new ArrayList<MatOfPoint>();

    //Imgproc.findContours(img_threshold, contours, new Mat(), Imgproc.RETR_LIST,Imgproc.CHAIN_APPROX_SIMPLE);
    Imgproc.findContours(img_threshold, contours, new Mat(), 0, 1);

    for (int i = 0; i < contours.size(); i++) {
        System.out.println(Imgproc.contourArea(contours.get(i)));
        //            if (Imgproc.contourArea(contours.get(i)) > 100) {
        //                //Imgproc.approxPolyDP( contours.get(i), contours_poly[i], 3, true );
        //                Rect rect = Imgproc.boundingRect(contours.get(i));
        //                System.out.println(rect.height);
        //                if (rect.width > rect.height) {
        //                    //System.out.println(rect.x +","+rect.y+","+rect.height+","+rect.width);
        //                    Core.rectangle(img, new Point(rect.x,rect.y), new Point(rect.x+rect.width,rect.y+rect.height),new Scalar(0,0,255));
        //                }
        //                    
        //                    
        //            }
        if (Imgproc.contourArea(contours.get(i)) > 100) {
            MatOfPoint2f mMOP2f1 = new MatOfPoint2f();
            MatOfPoint2f mMOP2f2 = new MatOfPoint2f();
            contours.get(i).convertTo(mMOP2f1, CvType.CV_32FC2);
            Imgproc.approxPolyDP(mMOP2f1, mMOP2f2, 3, true);
            mMOP2f2.convertTo(contours.get(i), CvType.CV_32S);
            Rect rect = Imgproc.boundingRect(contours.get(i));
            if (rect.width > rect.height) {
                Core.rectangle(img, new Point(rect.x, rect.y),
                        new Point(rect.x + rect.width, rect.y + rect.height), new Scalar(0, 0, 255));
            }//from  w w  w . ja va2  s .  c o  m
        }
    }
    //imshow("Rec Detected", img);
}

From source file:OCV_Blur.java

License:Open Source License

@Override
public void run(ImageProcessor ip) {
    if (ip.getBitDepth() == 8) {
        // srcdst
        int imw = ip.getWidth();
        int imh = ip.getHeight();
        byte[] srcdst_bytes = (byte[]) ip.getPixels();

        // mat// w  w w. j  a  va  2s  . co  m
        Mat src_mat = new Mat(imh, imw, CvType.CV_8UC1);
        Mat dst_mat = new Mat(imh, imw, CvType.CV_8UC1);

        // run
        src_mat.put(0, 0, srcdst_bytes);
        Imgproc.blur(src_mat, dst_mat, ksize, new Point(-1, -1), INT_BORDERTYPE[indBorderType]);
        dst_mat.get(0, 0, srcdst_bytes);
    } else if (ip.getBitDepth() == 16) {
        // srcdst
        int imw = ip.getWidth();
        int imh = ip.getHeight();
        short[] srcdst_shorts = (short[]) ip.getPixels();

        // mat
        Mat src_mat = new Mat(imh, imw, CvType.CV_16S);
        Mat dst_mat = new Mat(imh, imw, CvType.CV_16S);

        // run
        src_mat.put(0, 0, srcdst_shorts);
        Imgproc.blur(src_mat, dst_mat, ksize, new Point(-1, -1), INT_BORDERTYPE[indBorderType]);
        dst_mat.get(0, 0, srcdst_shorts);
    } else if (ip.getBitDepth() == 24) {
        // dst
        int imw = ip.getWidth();
        int imh = ip.getHeight();
        int[] srcdst_ints = (int[]) ip.getPixels();

        // mat
        Mat src_mat = new Mat(imh, imw, CvType.CV_8UC3);
        Mat dst_mat = new Mat(imh, imw, CvType.CV_8UC3);

        // run
        OCV__LoadLibrary.intarray2mat(srcdst_ints, src_mat, imw, imh);
        Imgproc.blur(src_mat, dst_mat, ksize, new Point(-1, -1), INT_BORDERTYPE[indBorderType]);
        OCV__LoadLibrary.mat2intarray(dst_mat, srcdst_ints, imw, imh);
    } else if (ip.getBitDepth() == 32) {
        // srcdst
        int imw = ip.getWidth();
        int imh = ip.getHeight();
        float[] srcdst_floats = (float[]) ip.getPixels();

        // mat
        Mat src_mat = new Mat(imh, imw, CvType.CV_32F);
        Mat dst_mat = new Mat(imh, imw, CvType.CV_32F);

        // run
        src_mat.put(0, 0, srcdst_floats);
        Imgproc.blur(src_mat, dst_mat, ksize, new Point(-1, -1), INT_BORDERTYPE[indBorderType]);
        dst_mat.get(0, 0, srcdst_floats);
    } else {
        IJ.error("Wrong image format");
    }
}

From source file:OctoEye.java

License:Open Source License

private void detectPupil() {
    // min and max pupil radius
    int r_min = 2;
    int r_max = 45;

    // min and max pupil diameter
    int d_min = 2 * r_min;
    int d_max = 2 * r_max;

    // min and max pupil area
    double area;// w ww.  ja  va2s.  c  o m
    double a_min = Math.PI * r_min * r_min;
    double a_max = Math.PI * r_max * r_max;

    // histogram stuff
    List<Mat> images;
    MatOfInt channels;
    Mat mask;
    Mat hist;
    MatOfInt mHistSize;
    MatOfFloat mRanges;

    // contour and circle stuff
    Rect rect = null;
    Rect rectMin;
    Rect rectMax;
    List<MatOfPoint> contours;
    MatOfPoint3 circles;

    // pupil center
    Point p;

    // ellipse test points
    Point v;
    Point r;
    Point s;

    // rect points
    Point tl;
    Point br;

    // pupil edge detection
    Vector<Point> pointsTest;
    Vector<Point> pointsEllipse;
    Vector<Point> pointsRemoved;

    // temporary variables
    double distance;
    double rad;
    double length;
    int x;
    int y;
    int tmp;
    byte buff[];

    // -------------------------------------------------------------------------------------------------------------
    // step 1
    // blur the image to reduce noise

    Imgproc.medianBlur(src, tmp1, 25);

    // -------------------------------------------------------------------------------------------------------------
    // step 2
    // locate the pupil with feature detection and compute a histogram for each,
    // the best feature will be used as rough pupil location (rectMin)

    int score = 0;
    int winner = 0;

    // feature detection
    MatOfKeyPoint matOfKeyPoints = new MatOfKeyPoint();
    FeatureDetector blobDetector = FeatureDetector.create(FeatureDetector.MSER); // Maximal Stable Extremal Regions
    blobDetector.detect(tmp1, matOfKeyPoints);
    List<KeyPoint> keyPoints = matOfKeyPoints.toList();

    // histogram calculation
    for (int i = 0; i < keyPoints.size(); i++) {
        x = (int) keyPoints.get(i).pt.x;
        y = (int) keyPoints.get(i).pt.y;
        tl = new Point(x - 5 >= 0 ? x - 5 : 0, y - 5 >= 0 ? y - 5 : 0);
        br = new Point(x + 5 < WIDTH ? x + 5 : WIDTH - 1, y + 5 < HEIGHT ? y + 5 : HEIGHT - 1);

        images = new ArrayList<Mat>();
        images.add(tmp1.submat(new Rect(tl, br)));
        channels = new MatOfInt(0);
        mask = new Mat();
        hist = new Mat();
        mHistSize = new MatOfInt(256);
        mRanges = new MatOfFloat(0f, 256f);
        Imgproc.calcHist(images, channels, mask, hist, mHistSize, mRanges);

        tmp = 0;
        for (int j = 0; j < 256 / 3; j++) {
            tmp += (256 / 3 - j) * (int) hist.get(j, 0)[0];
        }
        if (tmp >= score) {
            score = tmp;
            winner = i;
            rect = new Rect(tl, br);
        }

        if (debug) {
            // show features (orange)
            Core.circle(dbg, new Point(x, y), 3, ORANGE);
        }
    }
    if (rect == null) {
        return;
    }
    rectMin = rect.clone();

    if (debug) {
        // show rectMin (red)
        Core.rectangle(dbg, rectMin.tl(), rect.br(), RED, 1);
    }

    // -------------------------------------------------------------------------------------------------------------
    // step 3
    // compute a rectMax (blue) which is larger than the pupil

    int margin = 32;

    rect.x = rect.x - margin;
    rect.y = rect.y - margin;
    rect.width = rect.width + 2 * margin;
    rect.height = rect.height + 2 * margin;

    rectMax = rect.clone();

    if (debug) {
        // show features (orange)
        Core.rectangle(dbg, rectMax.tl(), rectMax.br(), BLUE);
    }

    // -------------------------------------------------------------------------------------------------------------
    // step 4
    // blur the image again

    Imgproc.medianBlur(src, tmp1, 7);
    Imgproc.medianBlur(tmp1, tmp1, 3);
    Imgproc.medianBlur(tmp1, tmp1, 3);
    Imgproc.medianBlur(tmp1, tmp1, 3);

    // -------------------------------------------------------------------------------------------------------------
    // step 5
    // detect edges

    Imgproc.Canny(tmp1, tmp2, 40, 50);

    // -------------------------------------------------------------------------------------------------------------
    // step 6
    // from pupil center to maxRect borders, find all edge points, compute a first ellipse

    p = new Point(rectMin.x + rectMin.width / 2, rectMin.y + rectMin.height / 2);
    pointsTest = new Vector<Point>();
    pointsEllipse = new Vector<Point>();
    pointsRemoved = new Vector<Point>();
    buff = new byte[tmp2.rows() * tmp2.cols()];
    tmp2.get(0, 0, buff);

    length = Math.min(p.x - rectMax.x - 3, p.y - rectMax.y - 3);
    length = Math.sqrt(2 * Math.pow(length, 2));
    Point z = new Point(p.x, p.y - length);
    for (int i = 0; i < 360; i += 15) {
        rad = Math.toRadians(i);
        x = (int) (p.x + Math.cos(rad) * (z.x - p.x) - Math.sin(rad) * (z.y - p.y));
        y = (int) (p.y + Math.sin(rad) * (z.x - p.x) - Math.cos(rad) * (z.y - p.y));
        pointsTest.add(new Point(x, y));
    }

    if (debug) {
        for (int i = 0; i < pointsTest.size(); i++) {
            Core.line(dbg, p, pointsTest.get(i), GRAY, 1);
            Core.rectangle(dbg, rectMin.tl(), rectMin.br(), GREEN, 1);
            Core.rectangle(dbg, rectMax.tl(), rectMax.br(), BLUE, 1);
        }
        Core.rectangle(dbg, rectMin.tl(), rectMin.br(), BLACK, -1);
        Core.rectangle(dbg, rectMin.tl(), rectMin.br(), RED, 1);
        Core.rectangle(dbg, rectMax.tl(), rectMax.br(), BLUE);
    }

    // p: Ursprung ("Mittelpunkt" der Ellipse)
    // v: Zielpunkt (Testpunkt)
    // r: Richtungsvektor PV
    for (int i = 0; i < pointsTest.size(); i++) {
        v = new Point(pointsTest.get(i).x, pointsTest.get(i).y);
        r = new Point(v.x - p.x, v.y - p.y);
        length = Math.sqrt(Math.pow(p.x - v.x, 2) + Math.pow(p.y - v.y, 2));
        boolean found = false;
        for (int j = 0; j < Math.round(length); j++) {
            s = new Point(Math.rint(p.x + (double) j / length * r.x),
                    Math.rint(p.y + (double) j / length * r.y));
            s.x = Math.max(1, Math.min(s.x, WIDTH - 2));
            s.y = Math.max(1, Math.min(s.y, HEIGHT - 2));
            tl = new Point(s.x - 1, s.y - 1);
            br = new Point(s.x + 1, s.y + 1);
            buff = new byte[3 * 3];
            rect = new Rect(tl, br);
            try {
                (tmp2.submat(rect)).get(0, 0, buff);
                for (int k = 0; k < 3 * 3; k++) {
                    if (Math.abs(buff[k]) == 1) {
                        pointsEllipse.add(s);
                        found = true;
                        break;
                    }
                }
            } catch (Exception e) {
                break;
            }
            if (found) {
                break;
            }
        }
    }

    double e_min = Double.POSITIVE_INFINITY;
    double e_max = 0;
    double e_med = 0;
    for (int i = 0; i < pointsEllipse.size(); i++) {
        v = pointsEllipse.get(i);
        length = Math.sqrt(Math.pow(p.x - v.x, 2) + Math.pow(p.y - v.y, 2));
        e_min = (length < e_min) ? length : e_min;
        e_max = (length > e_max) ? length : e_max;
        e_med = e_med + length;
    }
    e_med = e_med / pointsEllipse.size();
    if (pointsEllipse.size() >= 5) {
        Point[] points1 = new Point[pointsEllipse.size()];
        for (int i = 0; i < pointsEllipse.size(); i++) {
            points1[i] = pointsEllipse.get(i);
        }
        MatOfPoint2f points2 = new MatOfPoint2f();
        points2.fromArray(points1);
        pupil = Imgproc.fitEllipse(points2);
    }
    if (pupil.center.x == 0 && pupil.center.y == 0) {
        // something went wrong, return null
        reset();
        return;
    }

    if (debug) {
        Core.ellipse(dbg, pupil, PURPLE, 2);
    }

    // -------------------------------------------------------------------------------------------------------------
    // step 7
    // remove some outlier points and compute the ellipse again

    try {
        for (int i = 1; i <= 4; i++) {
            distance = 0;
            int remove = 0;
            for (int j = pointsEllipse.size() - 1; j >= 0; j--) {
                v = pointsEllipse.get(j);
                length = Math.sqrt(Math.pow(v.x - pupil.center.x, 2) + Math.pow(v.y - pupil.center.y, 2));
                if (length > distance) {
                    distance = length;
                    remove = j;
                }
            }
            v = pointsEllipse.get(remove);
            pointsEllipse.removeElementAt(remove);
            pointsRemoved.add(v);
        }
    } catch (Exception e) {
        // something went wrong, return null
        reset();
        return;
    }
    if (pointsEllipse.size() >= 5) {
        Point[] points1 = new Point[pointsEllipse.size()];
        for (int i = 0; i < pointsEllipse.size(); i++) {
            points1[i] = pointsEllipse.get(i);
        }
        MatOfPoint2f points2 = new MatOfPoint2f();
        points2.fromArray(points1);
        pupil = Imgproc.fitEllipse(points2);

        Point[] vertices = new Point[4];
        pupil.points(vertices);
        double d1 = Math
                .sqrt(Math.pow(vertices[1].x - vertices[0].x, 2) + Math.pow(vertices[1].y - vertices[0].y, 2));
        double d2 = Math
                .sqrt(Math.pow(vertices[2].x - vertices[1].x, 2) + Math.pow(vertices[2].y - vertices[1].y, 2));

        if (d1 >= d2) {
            pupilMajorAxis = (int) (d1 / 2);
            pupilMinorAxis = (int) (d2 / 2);
            axisA = new Point(vertices[1].x + (vertices[2].x - vertices[1].x) / 2,
                    vertices[1].y + (vertices[2].y - vertices[1].y) / 2);
            axisB = new Point(vertices[0].x + (vertices[1].x - vertices[0].x) / 2,
                    vertices[0].y + (vertices[1].y - vertices[0].y) / 2);
        } else {
            pupilMajorAxis = (int) (d2 / 2);
            pupilMinorAxis = (int) (d1 / 2);
            axisB = new Point(vertices[1].x + (vertices[2].x - vertices[1].x) / 2,
                    vertices[1].y + (vertices[2].y - vertices[1].y) / 2);
            axisA = new Point(vertices[0].x + (vertices[1].x - vertices[0].x) / 2,
                    vertices[0].y + (vertices[1].y - vertices[0].y) / 2);
        }
    }

    double ratio = (double) pupilMinorAxis / (double) pupilMajorAxis;
    if (ratio < 0.75 || 2 * pupilMinorAxis <= d_min || 2 * pupilMajorAxis >= d_max) {
        // something went wrong, return null
        reset();
        return;
    }

    // pupil found
    if (debug) {
        Core.ellipse(dbg, pupil, GREEN, 2);
        Core.line(dbg, pupil.center, axisA, RED, 2);
        Core.line(dbg, pupil.center, axisB, BLUE, 2);
        Core.circle(dbg, pupil.center, 1, GREEN, 0);

        x = 5;
        y = 5;
        Core.rectangle(dbg, new Point(x, y), new Point(x + 80 + 4, y + 10), BLACK, -1);
        Core.rectangle(dbg, new Point(x + 2, y + 2), new Point(x + 2 + pupilMajorAxis, y + 4), RED, -1);
        Core.rectangle(dbg, new Point(x + 2, y + 6), new Point(x + 2 + pupilMinorAxis, y + 8), BLUE, -1);

        for (int i = pointsEllipse.size() - 1; i >= 0; i--) {
            Core.circle(dbg, pointsEllipse.get(i), 2, ORANGE, -1);
        }
        for (int i = pointsRemoved.size() - 1; i >= 0; i--) {
            Core.circle(dbg, pointsRemoved.get(i), 2, PURPLE, -1);
        }
    }
    Core.ellipse(dst, pupil, GREEN, 2);
    Core.circle(dst, pupil.center, 1, GREEN, 0);
}