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:opencv.CaptchaDetection.java

/***
 * ?/*w w w .  j  a  va 2 s .c  o  m*/
 * @param src
 * @param dst
 * @param degree 
 */
private static void rotateImage(Mat src, Mat dst, int degree) {
    Point center = new Point(src.cols() / 2.0 + 0.5, src.rows() / 2.0 + 0.5);
    Mat M = Imgproc.getRotationMatrix2D(center, degree, 1.0);
    Imgproc.warpAffine(src, dst, M, src.size());
}

From source file:opencv.fark.FarkBulMainFrame.java

@Override
public void mousePressed(MouseEvent me) {
    //        System.out.println(first_point);
    if (reference_value == 0) {
        System.out.println("burdaym");
        first_point = new Point(me.getX(), me.getY());
        jPanelRefCapture.repaint();/*from   w ww . ja  v  a2  s. com*/
    }
}

From source file:opencv.fark.FarkBulMainFrame.java

@Override
public void mouseDragged(MouseEvent me) {
    drag = true;// w  w  w. j  a  v a 2  s  .co m
    second_point = new Point(me.getX(), me.getY());
    //        System.out.println(second_point);
}

From source file:opencv.fark.VideoSecMainFrame.java

public VideoSecMainFrame() {
    initComponents();/*from   ww  w .  ja  v a  2 s  .  c om*/

    g = jPanel1.getGraphics();
    g1 = jPanel2.getGraphics();
    referans_degeri = 0;
    drag = false;
    reference_section = new Mat();
    staticFirstPoint = new Point(0, 0);
    staticSecondPoint = new Point(0, 0);
    say = 0;

    this.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            if (videoCapture != null && videoCapture.isOpened()) {
                t.stop();
                videoCapture.release();
                t.interrupt();
            }
            System.exit(0);
        }

    });

    jPanel1.addMouseListener(this);
    jPanel1.addMouseMotionListener(this);
}

From source file:opencv.fark.VideoSecMainFrame.java

@Override
public void mousePressed(MouseEvent me) {
    if (referans_degeri == 0) {
        System.out.println("burdaym");
        first_point = new Point(me.getX(), me.getY());
        staticFirstPoint.x = first_point.x;
        staticFirstPoint.y = first_point.y;
        System.out.println("staticfirst" + staticFirstPoint);
        // System.out.println("firt"+me.getX()+" "+me.getY());
        jPanel2.repaint();//from   w ww  .j  ava  2  s. c o  m
    }
}

From source file:opencv.fark.VideoSecMainFrame.java

@Override
public void mouseDragged(MouseEvent me) {
    if (referans_degeri == 0) {
        drag = true;//from  w  w w . j a v a2  s  .c om
        second_point = new Point(me.getX(), me.getY());
        staticSecondPoint.x = second_point.x;
        staticSecondPoint.y = second_point.y;
        //        System.out.println(staticSecondPoint);
        //        System.out.println(me.getX()+" "+me.getY()); 
    }

}

From source file:opencvdemos.BallGame.java

License:Apache License

private Image grabFrame() {
    // Init everything
    Image imageToShow = null;/*from  w ww.j  ava  2  s. c om*/
    Mat frame = new Mat();

    // Check if the capture is open
    if (this.capture.isOpened()) {
        try {
            // Read the current frame
            this.capture.read(frame);
            // Flip image for easy object manipulation
            Core.flip(frame, frame, 1);

            // If the frame is not empty, process it
            if (!frame.empty()) {
                // Init
                Mat blurredImage = new Mat();
                Mat hsvImage = new Mat();
                Mat mask = new Mat();
                Mat morphOutput = new Mat();

                // Remove some noise
                Imgproc.blur(frame, blurredImage, new Size(7, 7));

                // Convert the frame to HSV
                Imgproc.cvtColor(blurredImage, hsvImage, Imgproc.COLOR_BGR2HSV);

                // Get thresholding values from the UI
                // Remember: H ranges 0-180, S and V range 0-255
                Scalar minValues = new Scalar(this.hueStart.getValue(), this.saturationStart.getValue(),
                        this.valueStart.getValue());
                Scalar maxValues = new Scalar(this.hueStop.getValue(), this.saturationStop.getValue(),
                        this.valueStop.getValue());

                // Show the current selected HSV range
                String valuesToPrint = "Hue range: " + minValues.val[0] + "-" + maxValues.val[0]
                        + ". Sat. range: " + minValues.val[1] + "-" + maxValues.val[1] + ". Value range: "
                        + minValues.val[2] + "-" + maxValues.val[2];
                hsvCurrentValues.setText(valuesToPrint);

                // Threshold HSV image to select object
                Core.inRange(hsvImage, minValues, maxValues, mask);
                // Show the partial output
                maskImage.getGraphics().drawImage(this.mat2Image(mask), 0, 0, 205, 154, null);

                // Morphological operators
                // Dilate with large element, erode with small ones
                Mat dilateElement = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(24, 24));
                Mat erodeElement = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(12, 12));

                Imgproc.erode(mask, morphOutput, erodeElement);
                Imgproc.erode(mask, morphOutput, erodeElement);

                Imgproc.dilate(mask, morphOutput, dilateElement);
                Imgproc.dilate(mask, morphOutput, dilateElement);

                // Show the partial output
                morphImage.getGraphics().drawImage(this.mat2Image(morphOutput), 0, 0, 205, 154, null);

                // Find the object(s) contours and show them
                frame = this.findAndDrawObjects(morphOutput, frame);

                // Calculate centers and move ball
                Mat temp = new Mat();
                morphOutput.copyTo(temp);
                List<MatOfPoint> contours = new ArrayList<>();
                Imgproc.findContours(temp, contours, new Mat(), Imgproc.RETR_EXTERNAL,
                        Imgproc.CHAIN_APPROX_SIMPLE);
                for (int i = 0; i < contours.size(); i++) {
                    Rect objectBoundingRectangle = Imgproc.boundingRect(contours.get(i));
                    int x = objectBoundingRectangle.x + objectBoundingRectangle.width / 2;
                    int y = objectBoundingRectangle.y + objectBoundingRectangle.height / 2;

                    // Move ball
                    if (!ballChanged) {
                        if (b.x > objectBoundingRectangle.x
                                && b.x < objectBoundingRectangle.x + objectBoundingRectangle.width
                                && b.y > objectBoundingRectangle.y
                                && b.y < objectBoundingRectangle.y + objectBoundingRectangle.height) {
                            b.dx = -b.dx;
                            b.dy = -b.dy;
                            ballChanged = true;
                        }
                    }

                    // Show crosshair
                    Imgproc.circle(frame, new Point(x, y), 20, new Scalar(0, 255, 0), 2);
                    Imgproc.line(frame, new Point(x, y), new Point(x, y - 25), new Scalar(0, 255, 0), 2);
                    Imgproc.line(frame, new Point(x, y), new Point(x, y + 25), new Scalar(0, 255, 0), 2);
                    Imgproc.line(frame, new Point(x, y), new Point(x - 25, y), new Scalar(0, 255, 0), 2);
                    Imgproc.line(frame, new Point(x, y), new Point(x + 25, y), new Scalar(0, 255, 0), 2);
                    Imgproc.putText(frame, "Tracking object at (" + x + "," + y + ")", new Point(x, y), 1, 1,
                            new Scalar(255, 0, 0), 2);
                }
                ballChanged = false;

                // Move and draw the ball
                if (b.dx < 0)
                    b.dx = ballSpeed.getValue() * -1;
                else
                    b.dx = ballSpeed.getValue();
                if (b.dy < 0)
                    b.dy = ballSpeed.getValue() * -1;
                else
                    b.dy = ballSpeed.getValue();
                b.move();
                Imgproc.circle(frame, new Point(b.x, b.y), b.r, new Scalar(255, 0, 255), -1);

                // convert the Mat object (OpenCV) to Image (Java AWT)
                imageToShow = mat2Image(frame);
            }

        } catch (Exception e) {
            // log the error
            System.err.println("Exception during the frame elaboration: " + e);
        }
    }

    return imageToShow;
}

From source file:opencvtesting.OpenCVTesting.java

/**
 * @param args the command line arguments
 *///  w w  w  . j av  a  2 s  . c om
public static void main(String[] args) throws IOException {
    /* Set the Nimbus look and feel */
    //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
    /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
     * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
     */
    try {
        for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
            if ("Nimbus".equals(info.getName())) {
                javax.swing.UIManager.setLookAndFeel(info.getClassName());
                break;
            }
        }
    } catch (ClassNotFoundException ex) {
        java.util.logging.Logger.getLogger(CameraWindow.class.getName()).log(java.util.logging.Level.SEVERE,
                null, ex);
    } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(CameraWindow.class.getName()).log(java.util.logging.Level.SEVERE,
                null, ex);
    } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(CameraWindow.class.getName()).log(java.util.logging.Level.SEVERE,
                null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(CameraWindow.class.getName()).log(java.util.logging.Level.SEVERE,
                null, ex);
    }
    //</editor-fold>

    /* Create and display the form */

    CameraWindow cWindow = new CameraWindow();
    cWindow.setVisible(true);

    Random gen = new Random();
    JFrame frameF = new JFrame();
    System.loadLibrary("opencv_java248");

    VideoCapture camera = new VideoCapture(0);
    camera.open(0); //Useless

    if (!camera.isOpened()) {
        System.out.println("Camera Error");
    } else {
        System.out.println("Camera OK?");
    }

    frame = new Mat();
    frame_gray = new Mat();
    camera.read(frame);
    showResult(frame, frameF);

    dst = new Mat(frame.size(), frame.type());
    mapX = new Mat(frame.size(), CvType.CV_32FC1);
    mapY = new Mat(frame.size(), CvType.CV_32FC1);
    boolean bEnd = true;
    while (bEnd) {

        camera.read(frame);
        Imgproc.cvtColor(frame, frame_gray, Imgproc.COLOR_BGR2GRAY);
        Imgproc.GaussianBlur(frame_gray, frame_gray, new Size(1, 1), 2);
        Imgproc.equalizeHist(frame_gray, frame_gray);
        Mat circles = new Mat();

        Imgproc.HoughCircles(frame_gray, circles, Imgproc.CV_HOUGH_GRADIENT, cWindow.get_dp(),
                frame_gray.rows() / 8, cWindow.get_param1(), cWindow.get_param2(), 0, 0);
        //System.out.println(circles.rows());

        for (int i = 0; i < circles.cols(); i++) {
            double[] circle = circles.get(0, i);
            Point center = new Point(Math.round(circle[0]), Math.round(circle[1]));
            int radius = (int) Math.round(circle[2]);
            Core.circle(frame, center, 3, new Scalar(gen.nextInt(), gen.nextInt(), gen.nextInt()), -1, 8, 0);
            Core.circle(frame, center, radius, new Scalar(gen.nextInt(), gen.nextInt(), gen.nextInt()), 3, 8,
                    0);
        }
        showResult(frame, frameF);

    }
    //Highgui.imwrite("camera1.jpg", frame);
    //System.out.println("OK");

}

From source file:opencv_ext.TGG_OpenCV_Util.java

public static Point[] getCentroidPoints(BufferedImage bufferedImage) {
    Point[][] contourPoints = getExternalConvexHullPoints(bufferedImage);
    Point[] centroidPoints = new Point[contourPoints.length];
    for (int c = 0; c < contourPoints.length; c++) {
        BufferedImage grayImage = new BufferedImage(bufferedImage.getWidth(), bufferedImage.getHeight(),
                BufferedImage.TYPE_BYTE_GRAY);
        Graphics g = grayImage.getGraphics();
        g.setColor(Color.GREEN);/*w  w w  .j  a  v a  2s.com*/
        Polygon convexHull = new Polygon();
        for (int p = 0; p < contourPoints[c].length; p++) {
            Point p0 = contourPoints[c][p];
            convexHull.addPoint((int) p0.x, (int) p0.y);
        }
        g.fillPolygon(convexHull);
        Mat cHull = bufferedImage2Mat(grayImage);
        Moments m = Imgproc.moments(cHull);
        centroidPoints[c] = new Point(m.m10 / m.m00, m.m01 / m.m00);
    }
    return centroidPoints;
}

From source file:opencv_ext.TGG_OpenCV_Util.java

public static byte[] getContourLineData(BufferedImage bufferedImage) {
    byte[] lineData = null;
    Point[][] contourPoints = getExternalConvexHullPoints(bufferedImage);
    boolean[][] greaterThan_lineData = new boolean[contourPoints.length][0];
    for (int c = 0; c < contourPoints.length; c++) {
        greaterThan_lineData[c] = new boolean[contourPoints[c].length];
        for (int p = 0; p < contourPoints[c].length; p++) {
            Point p0 = contourPoints[c][p];
            Point p1 = contourPoints[c][(p + 1) % contourPoints[c].length];
            Point mid = new Point((p1.x + p0.x) / 2, (p1.y + p0.y) / 2);
            Point testPoint = new Point(mid.x, mid.y);
            double slopeN = -(p0.y - p1.y);
            double slopeD = (p0.x - p1.x);
            boolean nonZeroSlope = false;
            double slope = 0;
            if (slopeN == 0) { // Horizontal Line
                testPoint.y -= 1;//ww w.j  a  va 2 s.co  m
            } else if (slopeD == 0) { // Vertical Line
                testPoint.x += 1;
            } else { // Sloped Line
                slope = slopeN / slopeD;
                double perpendicularSlope = -1 / slope;
                nonZeroSlope = true;
                testPoint.x += 1;
                testPoint.y = -perpendicularSlope * (testPoint.x - mid.x) + mid.y;
            }
            greaterThan_lineData[c][p] = (bufferedImage.getRGB((int) Math.ceil(testPoint.x),
                    (int) Math.ceil(testPoint.y)) & 0x00ffffff) != 0;
            greaterThan_lineData[c][p] = greaterThan_lineData[c][p] ^ (nonZeroSlope && slope > 0);
            System.out.println(
                    p0 + "," + p1 + ", gt:" + greaterThan_lineData[c][p] + "," + testPoint + "slope" + slope);
        }
    }
    lineData = DataUtil.boolArray2D_2byteArray(greaterThan_lineData);
    return lineData;
}