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:emotion.StaticFunctions.java

static void drawCross(Mat img, Point pt, Features feat) {
    Scalar col;/*from   w ww .ja  va2  s  . c  om*/
    switch (feat) {
    case EYEBROWS_ENDS:
        col = new Scalar(0, 255, 0);
        break;
    case EYELIDS:
        col = new Scalar(100, 210, 255);
        break;
    case EYE_CORNERS:
        col = new Scalar(220, 180, 30);
        break;
    case WHITE_MARK:
        col = new Scalar(255, 255, 255);
    default:
        col = new Scalar(255, 255, 255);

    }
    Imgproc.line(img, new Point(pt.x, pt.y - 5), new Point(pt.x, pt.y + 5), col, 1);

    Imgproc.line(img, new Point(pt.x - 5, pt.y), new Point(pt.x + 5, pt.y), col, 1);
}

From source file:eu.fpetersen.robobrain.behavior.followobject.ColorBlobDetector.java

License:Open Source License

public void process(Mat rgbaImage) {
    Imgproc.pyrDown(rgbaImage, mPyrDownMat);
    Imgproc.pyrDown(mPyrDownMat, mPyrDownMat);

    Imgproc.cvtColor(mPyrDownMat, mHsvMat, Imgproc.COLOR_RGB2HSV_FULL);

    Core.inRange(mHsvMat, mLowerBound, mUpperBound, mMask);
    Imgproc.dilate(mMask, mDilatedMask, new Mat());

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

    Imgproc.findContours(mDilatedMask, contours, mHierarchy, Imgproc.RETR_EXTERNAL,
            Imgproc.CHAIN_APPROX_SIMPLE);

    // Find max contour area
    maxArea = 0;/*from  ww w  . j  ava2  s.c o m*/
    Iterator<MatOfPoint> each = contours.iterator();
    Mat biggestContour = null;
    while (each.hasNext()) {
        MatOfPoint wrapper = each.next();
        double area = Imgproc.contourArea(wrapper);
        if (area > maxArea) {
            maxArea = area;
            biggestContour = wrapper.clone();
        }
    }
    if (biggestContour != null) {
        Core.multiply(biggestContour, new Scalar(4, 4), biggestContour);
        Moments mo = Imgproc.moments(biggestContour);
        centroidOfMaxArea = new Point(mo.get_m10() / mo.get_m00(), mo.get_m01() / mo.get_m00());
    } else {
        centroidOfMaxArea = null;
    }

    // Filter contours by area and resize to fit the original image size
    mContours.clear();
    each = contours.iterator();
    while (each.hasNext()) {
        MatOfPoint contour = each.next();
        if (Imgproc.contourArea(contour) > mMinContourArea * maxArea) {
            Core.multiply(contour, new Scalar(4, 4), contour);
            mContours.add(contour);
        }
    }

    Imgproc.drawContours(rgbaImage, mContours, -1, CONTOUR_COLOR);
}

From source file:eu.fpetersen.robobrain.behavior.followobject.OrbObjectDetector.java

License:Open Source License

public void process(Mat image) {
    Mat tempImage = new Mat();
    Imgproc.cvtColor(image, tempImage, Imgproc.COLOR_RGBA2RGB);
    MatOfKeyPoint keypoints = detectInImage(tempImage);
    Mat descriptors = extractDescriptors(keypoints, tempImage);
    MatOfDMatch matches = new MatOfDMatch();
    matcher.match(descriptors, originalDescriptors, matches);

    KeyPoint[] keypointArray = keypoints.toArray();
    KeyPoint[] originalKeypointArray = originalKeypoints.toArray();

    float min = 40.0f;
    float max = 1000.0f;
    for (DMatch match : matches.toList()) {
        if (match.distance < min) {
            min = match.distance;/*from  ww  w .  ja  va2 s. c  o  m*/
        } else if (match.distance > max) {
            max = match.distance;
        }
    }

    float threshold = 1.5f * min;
    List<KeyPoint> matchedKeyPoints = new ArrayList<KeyPoint>();
    List<Point> matchedPoints = new ArrayList<Point>();
    List<Point> matchedOriginalPoints = new ArrayList<Point>();
    for (DMatch match : matches.toList()) {
        if (match.distance < threshold) {
            KeyPoint matchedKeypoint = keypointArray[match.queryIdx];
            matchedKeyPoints.add(matchedKeypoint);
            matchedPoints.add(matchedKeypoint.pt);

            KeyPoint matchedOriginalKeypoint = originalKeypointArray[match.trainIdx];
            matchedOriginalPoints.add(matchedOriginalKeypoint.pt);
        }
    }

    if (matchedKeyPoints.size() > 10) {

        Mat H = Calib3d.findHomography(
                new MatOfPoint2f(matchedOriginalPoints.toArray(new Point[matchedOriginalPoints.size()])),
                new MatOfPoint2f(matchedPoints.toArray(new Point[matchedPoints.size()])), Calib3d.RANSAC, 10);

        List<Point> originalCorners = new ArrayList<Point>();
        originalCorners.add(new Point(0, 0));
        originalCorners.add(new Point(originalImage.cols(), 0));
        originalCorners.add(new Point(originalImage.cols(), originalImage.rows()));
        originalCorners.add(new Point(0, originalImage.rows()));

        List<Point> corners = new ArrayList<Point>();
        for (int i = 0; i < 4; i++) {
            corners.add(new Point(0, 0));
        }
        Mat objectCorners = Converters.vector_Point2f_to_Mat(corners);

        Core.perspectiveTransform(Converters.vector_Point2f_to_Mat(originalCorners), objectCorners, H);
        corners.clear();
        Converters.Mat_to_vector_Point2f(objectCorners, corners);

        Core.line(tempImage, corners.get(0), corners.get(1), new Scalar(0, 255, 0), 4);
        Core.line(tempImage, corners.get(1), corners.get(2), new Scalar(0, 255, 0), 4);
        Core.line(tempImage, corners.get(2), corners.get(3), new Scalar(0, 255, 0), 4);
        Core.line(tempImage, corners.get(3), corners.get(0), new Scalar(0, 255, 0), 4);
    }

    Features2d.drawKeypoints(tempImage,
            new MatOfKeyPoint(matchedKeyPoints.toArray(new KeyPoint[matchedKeyPoints.size()])), tempImage);
    Imgproc.cvtColor(tempImage, image, Imgproc.COLOR_RGB2RGBA);

}

From source file:facedetection.FaceDetector.java

public void findFaces() {
    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
    CascadeClassifier faceDetector = new CascadeClassifier(
            "D:\\opencv\\sources\\data\\lbpcascades\\lbpcascade_frontalface.xml");
    MatOfRect faceDetections = new MatOfRect();
    faceDetector.detectMultiScale(img, faceDetections);

    System.out.println(faceDetections);

    for (Rect rect : faceDetections.toArray()) {
        faceList.add(rect);/* w w  w . ja v a2s.c  om*/
        Imgproc.rectangle(img, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height),
                new Scalar(0, 255, 0));
    }
}

From source file:faceDetectionV1.FaceDetection.java

public void detectFaces(File file, ImagePanel imagePanel) {
    Mat image = Imgcodecs.imread(file.getAbsolutePath(), Imgcodecs.CV_LOAD_IMAGE_COLOR);

    MatOfRect facedetections = new MatOfRect();
    cascadeClassifier.detectMultiScale(image, facedetections);

    for (Rect rect : facedetections.toArray()) {
        Imgproc.rectangle(image, new Point(rect.x, rect.y),
                new Point(rect.x + rect.width, rect.y + rect.height), new Scalar(100, 100, 250), 10);
    }/*w  ww.j a  v a  2s. c o  m*/

    BufferedImage bufferedImage = convertMatToImage(image);
    imagePanel.updateImage(bufferedImage);

}

From source file:facerecognition.sample1.java

private static Rect find_enclosing_rectangle(double[][] puntos, File image_file) {

    Mat image = Imgcodecs.imread(image_file.getAbsolutePath());
    int i = 0;//from w w  w.  j  av a  2  s.  c  om
    Mat img2 = image.clone();
    for (CascadeClassifier faceDetector : faceDetectors) {

        // 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.
        //            double percent = 0.4;
        for (Rect rect : faceDetections.toArray()) {
            Rect piv = rect.clone();
            //  falta expandir
            int h = piv.height, w = piv.width;
            piv.x -= w * percent / 2;
            piv.y -= h * percent / 2;
            piv.height *= (1 + percent);
            piv.width *= (1 + percent);

            //            Mat croped = new Mat(image, rect);
            //             Imgcodecs.imwrite("face"+(++i)+".png", croped);
            Imgproc.rectangle(img2, new Point(rect.x, rect.y),
                    new Point(rect.x + rect.width, rect.y + rect.height), new Scalar(0, 255, 0));

            int r = 10;
            boolean dentro = true;
            for (double[] punto : puntos) {
                //                    Imgproc.circle(img2, new Point(rect.x, rect.y), r, new Scalar(0, 255, 0));

                if (piv.contains(new Point(punto)) == false) {
                    dentro = false;
                    //                        break;
                }
            }
            if (dentro) {
                //                    Imgcodecs.imwrite(urlHelen + "\\face" + (Math.random()) + ".png", img2);
                return piv;
            }
        }

    }
    //        Imgcodecs.imwrite( urlHelen + "\\face"+(Math.random())+".png", img2);

    return null;
}

From source file:facerecognition.sample1.java

private static void draw_initial_points() {
    //        PrintWriter pw = null;
    //        try {
    faceDetectors = new CascadeClassifier[] { new CascadeClassifier("haarcascade_frontalface_alt_tree.xml"),
            new CascadeClassifier("haarcascade_frontalface_alt2.xml"),
            new CascadeClassifier("haarcascade_profileface.xml") };
    File[] image_files = get_images();
    int index = 0;
    int contador = 0;
    //            File resumen = new File(urlHelen + "\\summary.sum");
    //            pw = new PrintWriter(resumen);

    double[][] mask = leer_mask();

    for (File image_file : image_files) {
        System.out.println("Analizando imagen " + (++index) + " de " + image_files.length);
        //            BufferedImage img = convert_to_BufferedImage(image_file);
        //                File puntos_file = get_puntos_file(image_file);
        //                double[][] puntos = LWF.leerpuntos(puntos_file);

        Mat image = Imgcodecs.imread(image_file.getAbsolutePath());
        Mat img2 = image.clone();//  ww  w .  j a  v a2  s. co  m

        for (CascadeClassifier faceDetector : faceDetectors) {

            // 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()) {
                Rect piv = rect.clone();
                //  falta expandir
                int h = piv.height, w = piv.width;
                piv.x -= w * percent / 2;
                piv.y -= h * percent / 2;
                piv.height *= (1 + percent);
                piv.width *= (1 + percent);

                //            Mat croped = new Mat(image, rect);
                //             Imgcodecs.imwrite("face"+(++i)+".png", croped);
                Imgproc.rectangle(img2, new Point(piv.x, piv.y),
                        new Point(piv.x + piv.width, piv.y + piv.height), new Scalar(0, 255, 0));

                for (double[] punto : mask) {
                    Imgproc.circle(img2, new Point(piv.x + piv.width * punto[0], piv.y + piv.height * punto[1]),
                            5, new Scalar(0, 255, 0));
                }
            }

        }
        //            pw.close();
        Imgcodecs.imwrite(urlHelen + "\\face" + (Math.random()) + ".png", img2);

    }

}

From source file:frclib.FrcOpenCVDetector.java

License:Open Source License

/**
 * This method is called to render an image to the video output and overlay detected objects on top of it.
 *
 * @param image specifies the frame to be rendered to the video output.
 * @param detectedObjectRects specifies the detected object rectangles.
 * @param color specifies the color of the rectangle outline.
 * @param thickness specifies the thickness of the rectangle outline.
 *///from  w ww .j  a v  a2  s .c o  m
public void putFrame(Mat image, Rect[] detectedObjectRects, Scalar color, int thickness) {
    //
    // Overlay a rectangle on each detected object.
    //
    synchronized (image) {
        if (detectedObjectRects != null) {
            for (Rect r : detectedObjectRects) {
                //
                // Draw a rectangle around the detected object.
                //
                Imgproc.rectangle(image, new Point(r.x, r.y), new Point(r.x + r.width, r.y + r.height), color,
                        thickness);
            }
        }

        videoOut.putFrame(image);
    }
}

From source file:fuzzycv.MainFrame.java

private Mat removeBG(Mat frame) {

    Mat hsvImg = new Mat();
    List<Mat> hsvPlanes = new ArrayList<>();
    Mat thresholdImg = new Mat();

    //threshold the image with the histogram average value
    hsvImg.create(frame.size(), CvType.CV_8U);
    Imgproc.cvtColor(frame, hsvImg, Imgproc.COLOR_BGR2HSV);
    Core.split(hsvImg, hsvPlanes);//from  w  w w. ja v a2 s  .c  om

    double threshValue = getHistoAvg(hsvImg, hsvPlanes.get(0));

    if (inverseCheckBox.isSelected()) {
        Imgproc.threshold(hsvPlanes.get(0), thresholdImg, threshValue, 179.0, Imgproc.THRESH_BINARY_INV);
    } else {
        Imgproc.threshold(hsvPlanes.get(0), thresholdImg, threshValue, 179.0, Imgproc.THRESH_BINARY);
    }

    Imgproc.blur(thresholdImg, thresholdImg, new Size(5, 5));

    // dilate to fill gaps, erode to smooth edges
    Imgproc.dilate(thresholdImg, thresholdImg, new Mat(), new Point(-1, 1), 6);
    Imgproc.erode(thresholdImg, thresholdImg, new Mat(), new Point(-1, 1), 6);

    Imgproc.threshold(thresholdImg, thresholdImg, threshValue, 179.0, Imgproc.THRESH_BINARY);

    // create the new image
    Mat foreground = new Mat(frame.size(), CvType.CV_8UC3, new Scalar(255, 255, 255));
    frame.copyTo(foreground, thresholdImg);

    return foreground;
}

From source file:hu.unideb.fksz.VideoProcessor.java

License:Open Source License

/**
 * Initializes the {@code controlPoints},
 * {@link VideoProcessor#VideoProcessor() in the constructor}.
 *///from w ww. j a  v a2s  .c om
private void initControlPoints() {
    try {
        controlPoints.add(new Point(80, 100));
        controlPoints.add(new Point(80, frameSize.height - 100));

        controlPoints.add(new Point(frameSize.width / 2, 100));
        controlPoints.add(new Point(frameSize.width / 2, frameSize.height - 100));

        controlPoints.add(new Point(frameSize.width - 80, 100));
        controlPoints.add(new Point(frameSize.width - 80, frameSize.height - 100));

        controlPoints.add(new Point(80, controlPointsHeight));
        controlPoints.add(new Point(frameSize.width - 80, controlPointsHeight));

        controlPoints.add(new Point(frameSize.width / 2, controlPointsHeight));

        TrafficCounterLogger.traceMessage("Control points initialised successfully!");

    } catch (Exception e) {
        logger.error(e.getMessage());
    }
}