use of org.opencv.core.Point in project Relic_Main by TeamOverdrive.
the class Lines method constructLine.
public static Line constructLine(Point point, double angle, double length) {
double dx = Math.cos(angle * Math.PI / 180);
double dy = Math.sin(angle * Math.PI / 180);
Point p1 = new Point(point.x + 0.5 * length * dx, point.y + 0.5 * length * dy);
Point p2 = new Point(point.x - 0.5 * length * dx, point.y - 0.5 * length * dy);
return new Line(p1, p2);
}
use of org.opencv.core.Point 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);
}
use of org.opencv.core.Point 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));
}
use of org.opencv.core.Point 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;
}
use of org.opencv.core.Point 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;
}
Aggregations