Search in sources :

Example 6 with Line

use of com.disnodeteam.dogecv.math.Line in project Relic_Main by TeamOverdrive.

the class Lines method linearExtend.

public static Line linearExtend(Line line, double scale, Size size) {
    scale *= 2;
    double xN1 = line.x1 + (line.x1 - line.x2) / scale;
    double yN1 = line.y1 + (line.y1 - line.y2) / scale;
    double xN2 = line.x2 + (line.x2 - line.x1) / scale;
    double yN2 = line.y2 + (line.y2 - line.y1) / scale;
    Point p1 = new Point(MathFTC.clip((int) xN1, 0, size.width - 1), MathFTC.clip((int) yN1, 0, size.height - 1));
    Point p2 = new Point(MathFTC.clip((int) xN2, 0, size.width - 1), MathFTC.clip((int) yN2, 0, size.height - 1));
    return new Line(p1, p2);
}
Also used : Line(com.disnodeteam.dogecv.math.Line) Point(org.opencv.core.Point)

Example 7 with Line

use of com.disnodeteam.dogecv.math.Line in project Relic_Main by TeamOverdrive.

the class Lines method getPerpindicularConnector.

public static Line getPerpindicularConnector(Line left, Line right, Size size) {
    double angle = Lines.getAngularDistance(left, new Line(new Point(0, 0), new Point(100, 0)));
    angle += 90;
    double dx = 3 * Math.cos(angle * Math.PI / 180);
    double dy = 3 * Math.sin(angle * Math.PI / 180);
    double x = left.center().x + dx;
    double y = left.center().y + dy;
    if (Lines.crossSign(left, new Point(x, y)) != Lines.crossSign(left, right.center())) {
        dx = -dx;
        dy = -dy;
        x -= 2 * dx;
        y -= 2 * dy;
    }
    while (Points.inBounds(new Point(x, y), size) && !Lines.intersect(new Line(left.center(), new Point(x, y)), right)) {
        x += dx;
        y += dy;
    }
    return new Line(left.center(), new Point(x, y));
}
Also used : Line(com.disnodeteam.dogecv.math.Line) Point(org.opencv.core.Point)

Example 8 with Line

use of com.disnodeteam.dogecv.math.Line in project Relic_Main by TeamOverdrive.

the class Lines method resize.

public static List<Line> resize(List<Line> lines, double scale) {
    List<Line> linesN = new ArrayList<Line>();
    for (Line line : lines) {
        line.resize(scale);
        linesN.add(line);
    }
    return linesN;
}
Also used : Line(com.disnodeteam.dogecv.math.Line) ArrayList(java.util.ArrayList)

Example 9 with Line

use of com.disnodeteam.dogecv.math.Line in project Relic_Main by TeamOverdrive.

the class Lines method getPerpindicular.

public static Line getPerpindicular(Line line, double sign) {
    double angle = Lines.getAngularDistance(line, new Line(new Point(0, 0), new Point(100, 0)));
    angle += 90;
    double x = line.center().x + 50 * Math.cos(angle * Math.PI / 180);
    double y = line.center().y + 50 * Math.sin(angle * Math.PI / 180);
    if (Lines.crossSign(line, new Point(x, y)) != sign) {
        x = line.center().x - 50 * Math.cos(angle * Math.PI / 180);
        y = line.center().y - 50 * Math.sin(angle * Math.PI / 180);
    }
    Line perp = new Line(line.center(), new Point(x, y));
    return perp;
}
Also used : Line(com.disnodeteam.dogecv.math.Line) Point(org.opencv.core.Point)

Example 10 with Line

use of com.disnodeteam.dogecv.math.Line in project Relic_Main by TeamOverdrive.

the class Lines method getOpenCvLines.

public static List<Line> getOpenCvLines(Mat original, int scale, double minLength) {
    Mat raw = new Mat();
    Imgproc.resize(original.clone(), raw, new Size((int) (original.size().width / scale), (int) (original.size().height / scale)));
    if (raw.channels() > 1) {
        Imgproc.cvtColor(raw, raw, Imgproc.COLOR_RGB2GRAY);
    }
    Imgproc.equalizeHist(raw, raw);
    Imgproc.blur(raw, raw, new Size(3, 3));
    // Line Segment Detection 2
    Mat linesM1 = new Mat();
    // LineSegmentDetector detector = Imgproc.createLineSegmentDetector(Imgproc.LSD_REFINE_ADV, 0.6, 0.3, 2.6, 22.5, 0, 0.3,256);
    // LineSegmentDetector detector = Imgproc.createLineSegmentDetector(Imgproc.LSD_REFINE_STD, 0.5, 0.4,2.0, 19.5, 0, 0.6, 32);
    // Reference for final glyph detection
    detector.detect(raw, linesM1);
    ArrayList<Line> lines = new ArrayList<Line>();
    for (int x = 0; x < linesM1.rows(); x++) {
        double[] vec = linesM1.get(x, 0);
        Point start = new Point(vec[0], vec[1]);
        Point end = new Point(vec[2], vec[3]);
        Line line = new Line(start, end);
        line = new Line(new Point((int) line.x1 * scale, (int) line.y1 * scale), new Point((int) line.x2 * scale, (int) line.y2 * scale));
        if (line.length() > minLength)
            lines.add(line);
    }
    raw.release();
    linesM1.release();
    return lines;
}
Also used : Line(com.disnodeteam.dogecv.math.Line) Mat(org.opencv.core.Mat) Size(org.opencv.core.Size) ArrayList(java.util.ArrayList) Point(org.opencv.core.Point) Point(org.opencv.core.Point)

Aggregations

Line (com.disnodeteam.dogecv.math.Line)12 Point (org.opencv.core.Point)8 ArrayList (java.util.ArrayList)4 List (java.util.List)2 Mat (org.opencv.core.Mat)2 Size (org.opencv.core.Size)2 MatOfPoint (org.opencv.core.MatOfPoint)1 Scalar (org.opencv.core.Scalar)1