use of imagingbook.pub.geometry.basic.Pnt2d in project imagingbook-common by imagingbook.
the class HomographyEstimator method runTestDLT.
private static void runTestDLT(HomographyEstimator he, Pnt2d[] pntsA, Pnt2d[] pntsB) {
RealMatrix Hest = he.getHomography(pntsA, pntsB);
System.out.println("H (estim.) = ");
System.out.println(Matrix.toString(Hest.getData()));
Pnt2d[] pntsC = new Pnt2d[pntsA.length];
for (int i = 0; i < pntsA.length; i++) {
pntsC[i] = mapPoint(Hest, pntsA[i]);
}
System.out.println("\nPoints mapped:");
double sumDist2 = 0;
double maxDist2 = Double.NEGATIVE_INFINITY;
for (int i = 0; i < pntsA.length; i++) {
Pnt2d a = pntsA[i];
Pnt2d b = pntsB[i];
Pnt2d c = pntsC[i];
double dist2 = b.distanceSq(c);
sumDist2 += dist2;
maxDist2 = Math.max(maxDist2, dist2);
System.out.format("(%.3f, %.3f) -> (%.3f, %.3f) d=%.4f\n", a.getX(), a.getY(), c.getX(), c.getY(), dist2);
}
System.out.format("\nTotal error = %.2f\n", Math.sqrt(sumDist2));
System.out.format("Max. dist = %.2f\n", Math.sqrt(maxDist2));
}
use of imagingbook.pub.geometry.basic.Pnt2d in project imagingbook-common by imagingbook.
the class SlopeInterceptLine method main.
// --------------------------------------------------
public static void main(String[] args) {
Pnt2d p1 = Pnt2d.from(1, 2);
Pnt2d p2 = Pnt2d.from(4, 3);
AlgebraicLine al1 = AlgebraicLine.from(p1, p2);
System.out.println("al1 = " + al1);
SlopeInterceptLine sl = SlopeInterceptLine.from(al1);
System.out.println("sl = " + sl);
AlgebraicLine al2 = AlgebraicLine.from(sl);
System.out.println("al2 = " + al2);
System.out.println("al1 = al2 ? " + al1.equals(al2));
}
use of imagingbook.pub.geometry.basic.Pnt2d in project imagingbook-common by imagingbook.
the class Contour method isClosed.
/**
* Checks if this contour is closed w.r.t. the specified
* {@link NeighborhoodType2D}, i.e., if the last and the first
* contour point are "connected".
*
* @param nht the (@link NeighborhoodType}.
* @return true if the contour is closed.
*/
public boolean isClosed(NeighborhoodType2D nht) {
Pnt2d[] pnts = this.getPointArray();
if (pnts.length < 2)
return true;
Pnt2d p1 = pnts[pnts.length - 1];
Pnt2d p2 = pnts[0];
// N4: max 1, N8: max 2
double d2 = p1.distanceSq(p2);
if (nht == NeighborhoodType2D.N4 && d2 <= 1)
return true;
if (nht == NeighborhoodType2D.N8 && d2 <= 2)
return true;
return false;
}
use of imagingbook.pub.geometry.basic.Pnt2d in project imagingbook-common by imagingbook.
the class EdgeTrace method main.
// ---------------------------------------------------------
public static void main(String[] args) {
EdgeTrace trace = new EdgeTrace();
trace.addPoint(PntInt.from(1, 2));
trace.addPoint(PntInt.from(3, 4));
trace.addPoint(PntInt.from(5, 6));
for (Pnt2d p : trace) {
System.out.println(p);
}
System.out.println();
trace.addPoint(PntInt.from(7, 8));
for (PntInt p : trace.getPointArray()) {
System.out.println(p);
}
System.out.println();
for (Point p : trace.getAwtPoints()) {
System.out.println(p);
}
System.out.println(trace.getPoint(3));
System.out.println(trace.getPoint(4));
PntInt[] copy = Arrays.copyOfRange(trace.getPointArray(), 0, 7);
System.out.println(copy.length);
for (PntInt p : copy) {
System.out.println(p);
}
}
use of imagingbook.pub.geometry.basic.Pnt2d in project imagingbook-common by imagingbook.
the class HoughLineTest method test2.
@Test
public void test2() {
HoughLine l12 = HoughLine.fromPoints(p1, p2, pRef, 2);
Pnt2d x0 = l12.getClosestLinePoint(p3);
// x0 is actually ON the line
Assert.assertEquals(0.0, l12.getDistance(x0), 1E-6);
// distance (p3,x0) is shortest
Assert.assertEquals(p3.distance(x0), Math.abs(l12.getDistance(p3)), 1E-6);
}
Aggregations