use of georegression.geometry.UtilPoint2D_F64 in project BoofCV by lessthanoptimal.
the class AssistedCalibration method findClosestCenter.
private double findClosestCenter(Point2D_F64 target, Point2D_F64 result) {
Point2D_F64 center = new Point2D_F64();
double bestDistanceSq = Double.MAX_VALUE;
for (int i = 0, j = sidesCollision.size() - 1; i < sidesCollision.size(); j = i, i++) {
UtilPoint2D_F64.mean(sidesCollision.get(i), sidesCollision.get(j), center);
double d = center.distance2(target);
if (d < bestDistanceSq) {
bestDistanceSq = d;
result.set(center);
}
}
return Math.sqrt(bestDistanceSq);
}
use of georegression.geometry.UtilPoint2D_F64 in project BoofCV by lessthanoptimal.
the class LensDistortionOps_F64 method centerBoxInside.
/**
* Attempts to center the box inside. It will be approximately fitted too.
*
* @param srcWidth Width of the source image
* @param srcHeight Height of the source image
* @param transform Transform being applied to the image
* @return Bounding box
*/
public static RectangleLength2D_F64 centerBoxInside(int srcWidth, int srcHeight, PixelTransform<Point2D_F64> transform, Point2D_F64 work) {
List<Point2D_F64> points = computeBoundingPoints(srcWidth, srcHeight, transform, work);
Point2D_F64 center = new Point2D_F64();
UtilPoint2D_F64.mean(points, center);
double x0, x1, y0, y1;
double bx0, bx1, by0, by1;
x0 = x1 = y0 = y1 = 0;
bx0 = bx1 = by0 = by1 = Double.MAX_VALUE;
for (int i = 0; i < points.size(); i++) {
Point2D_F64 p = points.get(i);
double dx = p.x - center.x;
double dy = p.y - center.y;
double adx = Math.abs(dx);
double ady = Math.abs(dy);
if (adx < ady) {
if (dy < 0) {
if (adx < by0) {
by0 = adx;
y0 = dy;
}
} else {
if (adx < by1) {
by1 = adx;
y1 = dy;
}
}
} else {
if (dx < 0) {
if (ady < bx0) {
bx0 = ady;
x0 = dx;
}
} else {
if (ady < bx1) {
bx1 = ady;
x1 = dx;
}
}
}
}
return new RectangleLength2D_F64(x0 + center.x, y0 + center.y, x1 - x0, y1 - y0);
}
use of georegression.geometry.UtilPoint2D_F64 in project BoofCV by lessthanoptimal.
the class LensDistortionOps_F64 method boundBoxInside.
/**
* Ensures that the entire box will be inside
*
* @param srcWidth Width of the source image
* @param srcHeight Height of the source image
* @param transform Transform being applied to the image
* @return Bounding box
*/
public static RectangleLength2D_F64 boundBoxInside(int srcWidth, int srcHeight, PixelTransform<Point2D_F64> transform, Point2D_F64 work) {
List<Point2D_F64> points = computeBoundingPoints(srcWidth, srcHeight, transform, work);
Point2D_F64 center = new Point2D_F64();
UtilPoint2D_F64.mean(points, center);
double x0, x1, y0, y1;
x0 = y0 = Float.MAX_VALUE;
x1 = y1 = -Float.MAX_VALUE;
for (int i = 0; i < points.size(); i++) {
Point2D_F64 p = points.get(i);
if (p.x < x0)
x0 = p.x;
if (p.x > x1)
x1 = p.x;
if (p.y < y0)
y0 = p.y;
if (p.y > y1)
y1 = p.y;
}
x0 -= center.x;
x1 -= center.x;
y0 -= center.y;
y1 -= center.y;
double ox0 = x0;
double oy0 = y0;
double ox1 = x1;
double oy1 = y1;
for (int i = 0; i < points.size(); i++) {
Point2D_F64 p = points.get(i);
double dx = p.x - center.x;
double dy = p.y - center.y;
// see if the point is inside the box
if (dx > x0 && dy > y0 && dx < x1 && dy < y1) {
// find smallest reduction in side length and closest to original rectangle
double d0 = (double) Math.abs(dx - x0) + x0 - ox0;
double d1 = (double) Math.abs(dx - x1) + ox1 - x1;
double d2 = (double) Math.abs(dy - y0) + y0 - oy0;
double d3 = (double) Math.abs(dy - y1) + oy1 - y1;
if (d0 <= d1 && d0 <= d2 && d0 <= d3) {
x0 = dx;
} else if (d1 <= d2 && d1 <= d3) {
x1 = dx;
} else if (d2 <= d3) {
y0 = dy;
} else {
y1 = dy;
}
}
}
return new RectangleLength2D_F64(x0 + center.x, y0 + center.y, x1 - x0, y1 - y0);
}
use of georegression.geometry.UtilPoint2D_F64 in project BoofCV by lessthanoptimal.
the class CompareTwoImagePanel method findBestPoints.
private void findBestPoints(int x, int y, List<Point2D_F64> pts, List<Integer> selected) {
double bestDist = clickDistance * clickDistance;
DogArray_I32 bestIndexes = new DogArray_I32(20);
for (int i = 0; i < pts.size(); i++) {
if (!isValidPoint(i))
continue;
Point2D_F64 p = pts.get(i);
double d = UtilPoint2D_F64.distanceSq(p.x, p.y, x, y);
if (d < bestDist) {
bestDist = d;
bestIndexes.reset();
bestIndexes.add(i);
} else if (Math.abs(d - bestDist) < 0.01) {
bestIndexes.add(i);
}
}
for (int i = 0; i < bestIndexes.size(); i++) {
selected.add(bestIndexes.get(i));
}
}
use of georegression.geometry.UtilPoint2D_F64 in project BoofCV by lessthanoptimal.
the class TestUchiyaMarkerTracker method fitHomography.
@Test
void fitHomography() {
var doc_to_image = new Homography2D_F64(2, 0, 10, 0, 1.5, -5.6, 0, 0, 1);
List<Point2D_F64> landmarks = UtilPoint2D_F64.random(-1, 1, 10, rand);
List<Point2D_F64> dots = new ArrayList<>();
for (var m : landmarks) {
var d = new Point2D_F64();
HomographyPointOps_F64.transform(doc_to_image, m, d);
dots.add(d);
}
// Shuffle the order to test to see if the correct book keeping is being done
List<Point2D_F64> dotsShuffled = new ArrayList<>(dots);
Collections.shuffle(dotsShuffled, rand);
var document = new LlahDocument();
document.landmarks.copyAll(landmarks, (src, dst) -> dst.setTo(src));
var observed = new LlahOperations.FoundDocument();
observed.init(document);
for (int i = 0; i < landmarks.size(); i++) {
observed.landmarkHits.data[i] = 1000;
observed.landmarkToDots.data[i] = dotsShuffled.indexOf(dots.get(i));
}
UchiyaMarkerTracker alg = createTracker();
assertTrue(alg.fitHomography(dotsShuffled, observed));
Homography2D_F64 found = alg.ransac.getModelParameters();
CommonOps_DDF3.divide(found, found.a33);
assertTrue(MatrixFeatures_DDF3.isIdentical(doc_to_image, found, UtilEjml.TEST_F64));
}
Aggregations