use of georegression.struct.point.Point2D_F32 in project BoofCV by lessthanoptimal.
the class LineImageOps method convert.
/**
* Find the point in which the line intersects the image border and create a line segment at those points
*/
public static LineSegment2D_F32 convert(LineParametric2D_F32 l, int width, int height) {
double t0 = (0 - l.p.x) / l.getSlopeX();
double t1 = (0 - l.p.y) / l.getSlopeY();
double t2 = (width - l.p.x) / l.getSlopeX();
double t3 = (height - l.p.y) / l.getSlopeY();
Point2D_F32 a = computePoint(l, t0);
Point2D_F32 b = computePoint(l, t1);
Point2D_F32 c = computePoint(l, t2);
Point2D_F32 d = computePoint(l, t3);
List<Point2D_F32> inside = new ArrayList<>();
checkAddInside(width, height, a, inside);
checkAddInside(width, height, b, inside);
checkAddInside(width, height, c, inside);
checkAddInside(width, height, d, inside);
if (inside.size() != 2) {
return null;
// System.out.println("interesting");
}
return new LineSegment2D_F32(inside.get(0), inside.get(1));
}
use of georegression.struct.point.Point2D_F32 in project BoofCV by lessthanoptimal.
the class GenericBackgroundModelMovingChecks method checkSegmented.
/**
* Checks to see if pixels outside of BG are marked as unknown
*/
private void checkSegmented(Homography2D_F32 transform, GrayU8 segmented, double tol) {
Point2D_F32 p = new Point2D_F32();
int numErrors = 0;
for (int y = 0; y < segmented.height; y++) {
for (int x = 0; x < segmented.width; x++) {
HomographyPointOps_F32.transform(transform, x, y, p);
int xx = (int) Math.floor(p.x);
int yy = (int) Math.floor(p.y);
if (segmented.isInBounds(xx, yy)) {
if (segmented.get(x, y) == 2)
numErrors++;
} else {
if (segmented.get(x, y) != 2)
numErrors++;
}
}
}
assertTrue(numErrors / (double) (segmented.width * segmented.height) <= tol);
}
use of georegression.struct.point.Point2D_F32 in project BoofCV by lessthanoptimal.
the class MultiCameraToEquirectangular method addCamera.
/**
* Adds a camera and attempts to compute the mask from the provided distortion model. if a pixel is rendered
* outside the bounds in the input image then it is masked out. If the forwards/backwards transform is too
* different then it is masked out.
*
* @param cameraToCommon Rigid body transform from this camera to the common frame the equirectangular image
* is in
* @param factory Distortion model
* @param camMask Binary mask with invalid pixels marked as not zero. Pixels are in camera image frame.
*/
public void addCamera(Se3_F32 cameraToCommon, LensDistortionWideFOV factory, GrayU8 camMask) {
Point2Transform3_F32 p2s = factory.undistortPtoS_F32();
Point3Transform2_F32 s2p = factory.distortStoP_F32();
EquiToCamera equiToCamera = new EquiToCamera(cameraToCommon.getR(), s2p);
GrayF32 equiMask = new GrayF32(equiWidth, equHeight);
PixelTransformCached_F32 transformEquiToCam = new PixelTransformCached_F32(equiWidth, equHeight, new PointToPixelTransform_F32(equiToCamera));
int width = camMask.width;
int height = camMask.height;
Point3D_F32 p3b = new Point3D_F32();
Point2D_F32 p2 = new Point2D_F32();
for (int row = 0; row < equHeight; row++) {
for (int col = 0; col < equiWidth; col++) {
equiToCamera.compute(col, row, p2);
if (UtilEjml.isUncountable(p2.x) || UtilEjml.isUncountable(p2.y)) {
// can't have it be an invalid number in the cache, but had to be invalid so that the mask
// could be set to zero. So set it to some valid value that won't cause it to blow up
transformEquiToCam.getPixel(col, row).set(-1, -1);
continue;
}
int camX = (int) (p2.x + 0.5f);
int camY = (int) (p2.y + 0.5f);
if (camX < 0 || camY < 0 || camX >= width || camY >= height)
continue;
if (camMask.unsafe_get(camX, camY) == 1) {
p2s.compute(p2.x, p2.y, p3b);
if (Double.isNaN(p3b.x) || Double.isNaN(p3b.y) || Double.isNaN(p3b.z))
continue;
double angle = UtilVector3D_F32.acute(equiToCamera.unitCam, p3b);
if (angle < maskToleranceAngle) {
equiMask.set(col, row, 1);
}
}
}
}
cameras.add(new Camera(equiMask, transformEquiToCam));
}
use of georegression.struct.point.Point2D_F32 in project BoofCV by lessthanoptimal.
the class PointDeform_MLS method setSource.
@Override
public void setSource(List<Point2D_F32> locations) {
alg.reset();
for (int i = 0; i < locations.size(); i++) {
Point2D_F32 p = locations.get(i);
alg.addControl(p.x, p.y);
}
alg.fixateUndistorted();
}
use of georegression.struct.point.Point2D_F32 in project BoofCV by lessthanoptimal.
the class ChecksPointDeformKeyPoints method individualDstSameAsAll.
/**
* Makes sure modifying a single points is the same as modifying all the points at once
*/
@Test
public void individualDstSameAsAll() {
List<Point2D_F32> src = createTestPoints();
List<Point2D_F32> dst = createTestPoints();
PointDeformKeyPoints alg = createAlgorithm();
alg.setImageShape(80, 100);
alg.setSource(src);
alg.setSource(dst);
alg.setDestination(1, 20, 25);
Point2D_F32 expected = new Point2D_F32();
alg.compute(12, 19.5f, expected);
dst.get(1).set(20, 25);
Point2D_F32 found = new Point2D_F32();
alg.compute(12, 19.5f, found);
assertEquals(expected.x, found.x, GrlConstants.TEST_F32);
assertEquals(expected.y, found.y, GrlConstants.TEST_F32);
}
Aggregations