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:com.mycompany.analyzer.DiagonalDominanceAnalyzer.java

public Point getClosestPointOnSegment(Line line, Point p) {
    double xDelta = line.getX2() - line.getX1();
    double yDelta = line.getY2() - line.getY1();

    double u = ((p.x - line.getX1()) * xDelta + (p.y - line.getY1()) * yDelta)
            / (xDelta * xDelta + yDelta * yDelta);

    Point closestPoint;/*from www  .j ava 2s . c  o  m*/
    if (u < 0) {
        closestPoint = new Point(line.getX1(), line.getY1());
    } else if (u > 1) {
        closestPoint = new Point(line.getX2(), line.getY2());
    } else {
        closestPoint = new Point((int) Math.round(line.getX1() + u * xDelta),
                (int) Math.round(line.getY1() + u * yDelta));
    }
    return closestPoint;
}

From source file:com.mycompany.analyzer.DiagonalDominanceAnalyzer.java

private Point intersPointOfTwoLines(Line l1, Line l2) {
    double x1 = l1.getX1();
    double x2 = l1.getX2();
    double y1 = l1.getY1();
    double y2 = l1.getY2();

    double x3 = l2.getX1();
    double x4 = l2.getX2();
    double y3 = l2.getY1();
    double y4 = l2.getY2();

    double d = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);
    if (d == 0) {
        return null;
    }// ww  w.  ja  v a2 s .  c om

    double xi = ((x3 - x4) * (x1 * y2 - y1 * x2) - (x1 - x2) * (x3 * y4 - y3 * x4)) / d;
    double yi = ((y3 - y4) * (x1 * y2 - y1 * x2) - (y1 - y2) * (x3 * y4 - y3 * x4)) / d;

    if (!isPointInFrame(new Point(xi, yi))) {
        return null;
    }
    return new Point(xi, yi);
}

From source file:com.mycompany.analyzer.DiagonalDominanceAnalyzer.java

private Line getLineSegmentInFrame(Line originalLine) {
    ArrayList<Point> points = new ArrayList();
    Point intersect;/*from  w w  w  . ja v a  2 s .c om*/
    int nullNr = 0;

    for (Line line : frameLines) {
        //System.out.println("-----------");
        intersect = intersPointOfTwoLines(line, originalLine);
        if (intersect != null) {
            if (isPointOnLine(intersect, originalLine)) {
                if (intersect.x == 0 && intersect.y == 0 && nullNr == 0) {
                    points.add(intersect);
                    nullNr++;
                } else if (intersect.x == 0 && intersect.y == 0) {
                } else {
                    points.add(intersect);
                }
            }
        }

        if (points.size() == 0) {
            Point startPoint = new Point(originalLine.getX1(), originalLine.getY1());
            Point endPoint = new Point(originalLine.getX2(), originalLine.getY2());
            if (isPointInFrame(startPoint) && isPointInFrame(endPoint)) {
                return originalLine;
            }
        } else if (points.size() == 1) {
            Point inters = points.get(0);
            Point second = new Point(originalLine.getX1(), originalLine.getY1());
            if (!isPointInFrame(second)) {
                second = new Point(originalLine.getX2(), originalLine.getY2());
            }
            return new Line(inters.x, inters.y, second.x, second.y);
        } else if (isPointInFrame(points.get(0)) && isPointInFrame(points.get(1))) {
            return new Line(points.get(0).x, points.get(0).y, points.get(1).x, points.get(1).y);
        }
    }
    return null;
}

From source file:com.mycompany.analyzer.DiagonalDominanceAnalyzer.java

private boolean isPointOnLine(Point point, Line line) {
    Point p1 = new Point(line.getX1(), line.getY1());
    Point p2 = new Point(line.getX2(), line.getY2());
    return normalDistBtwPoints(p1, point) + normalDistBtwPoints(p2, point) == normalDistBtwPoints(p1, p2);
}

From source file:com.mycompany.analyzer.RuleOfThirdsAnalyzer.java

public void calculatePowerPoints() {
    powerPoints = new ArrayList();
    int width = frameWidth;
    int height = frameHeight;
    powerPoints.add(new Point(frameX + (width - 1) / 3, frameY + (height - 1) / 3));
    powerPoints.add(new Point(frameX + (width - 1) / 3 * 2, frameY + (height - 1) / 3));
    powerPoints.add(new Point(frameX + (width - 1) / 3, frameY + (height - 1) / 3 * 2));
    powerPoints.add(new Point(frameX + (width - 1) / 3 * 2, frameY + (height - 1) / 3 * 2));
}

From source file:com.mycompany.analyzer.RuleOfThirdsAnalyzer.java

private double minDistToPowerPoints(Rect rect) {
    Point center = new Point(rect.x + (rect.width - 1) / 2, rect.y + (rect.height - 1) / 2);
    double min = 100000000;
    double actualDist = 0;
    for (Point p : powerPoints) {
        actualDist = distanceBtwPoints(center, p);
        if (actualDist < min) {
            min = actualDist;/*from  www  .  j a  v  a2 s. c o  m*/
        }
    }
    return min;
}

From source file:com.mycompany.analyzer.RuleOfThirdsAnalyzer.java

private double minDistToThirdLines(Line line) {
    int width = frameWidth - 1;
    int height = frameHeight - 1;
    Point p1 = new Point(line.getX1(), line.getY1());
    Point p2 = new Point(line.getX2(), line.getY2());

    ArrayList<Double> distances = new ArrayList();
    double dist = 0;

    for (Line thLine : thirdLines) {
        Point closestPoint = getClosestPointOnSegment(thLine, p1);
        dist = distanceBtwPoints(closestPoint, p1);
        closestPoint = getClosestPointOnSegment(thLine, p2);
        dist += distanceBtwPoints(closestPoint, p2);
        distances.add(dist);/*from  www.ja  va  2  s.  co m*/

    }

    double min = distances.get(0);
    for (int i = 1; i < distances.size(); ++i) {
        if (distances.get(i) < min) {
            min = distances.get(i);
        }
    }

    return min;
}

From source file:com.mycompany.analyzer.RuleOfThirdsAnalyzer.java

public Point getClosestPointOnSegment(Line line, Point p) {
    double xDelta = line.getX2() - line.getX1();
    double yDelta = line.getY2() - line.getY1();

    double u = ((p.x - line.getX1()) * xDelta + (p.y - line.getY1()) * yDelta)
            / (xDelta * xDelta + yDelta * yDelta);

    Point closestPoint;// w  w w .  j  ava 2s  .c  o m
    if (u < 0) {
        closestPoint = new Point(line.getX1(), line.getY1());
    } else if (u > 1) {
        closestPoint = new Point(line.getX2(), line.getY2());
    } else {
        closestPoint = new Point((int) Math.round(line.getX1() + u * xDelta),
                (int) Math.round(line.getY1() + u * yDelta));
    }

    return closestPoint;
}

From source file:com.mycompany.analyzer.RuleOfThirdsAnalyzer.java

private Line getLineSegmentInFrame(Line originalLine) {
    ArrayList<Point> points = new ArrayList();
    Point intersect;/*from   w  w w .  jav a 2s  .  c o m*/
    int nullNr = 0;

    for (Line line : frameLines) {
        intersect = intersPointOfTwoLines(line, originalLine);
        if (intersect != null) {
            if (isPointOnLine(intersect, originalLine)) {
                if (intersect.x == 0 && intersect.y == 0 && nullNr == 0) {
                    points.add(intersect);
                    nullNr++;
                } else if (intersect.x == 0 && intersect.y == 0) {
                } else {
                    points.add(intersect);
                }
            }
        }

        if (points.size() == 0) {
            Point startPoint = new Point(originalLine.getX1(), originalLine.getY1());
            Point endPoint = new Point(originalLine.getX2(), originalLine.getY2());
            if (isPointInFrame(startPoint) && isPointInFrame(endPoint)) {
                return originalLine;
            }
        } else if (points.size() == 1) {
            Point inters = points.get(0);
            Point second = new Point(originalLine.getX1(), originalLine.getY1());
            if (!isPointInFrame(second)) {
                second = new Point(originalLine.getX2(), originalLine.getY2());
            }
            return new Line(inters.x, inters.y, second.x, second.y);
        } else if (isPointInFrame(points.get(0)) && isPointInFrame(points.get(1))) {
            return new Line(points.get(0).x, points.get(0).y, points.get(1).x, points.get(1).y);
        }
    }
    return null;
}

From source file:com.mycompany.analyzer.VisualBalanceAnalyzer.java

public Point getRectCenter(Rect rect) {
    int width = rect.width - 1;
    int height = rect.height - 1;
    return new Point(rect.x + (width / 2), rect.y + (height / 2));
}