use of georegression.struct.shapes.RectangleLength2D_F32 in project BoofCV by lessthanoptimal.
the class LensDistortionOps method transformChangeModel_F32.
/**
* Creates a {@link Point2Transform2_F32} for converting pixels from original camera model into a new synthetic
* model. The scaling of the image can be adjusted to ensure certain visibility requirements.
*
* @param type The type of adjustment it will apply to the transform
* @param paramOriginal Camera model for the current image
* @param paramDesired Desired camera model for the distorted image
* @param desiredToOriginal If true then the transform's input is assumed to be pixels in the desired
* image and the output will be in original image, if false then the reverse transform
* is returned.
* @param paramMod The modified camera model to meet the requested visibility requirements. Null if you don't want it.
* @return The requested transform
*/
public static <O extends CameraPinhole, D extends CameraPinhole> Point2Transform2_F32 transformChangeModel_F32(AdjustmentType type, O paramOriginal, D paramDesired, boolean desiredToOriginal, D paramMod) {
LensDistortionNarrowFOV original = LensDistortionOps.narrow(paramOriginal);
LensDistortionNarrowFOV desired = LensDistortionOps.narrow(paramDesired);
Point2Transform2_F32 ori_p_to_n = original.undistort_F32(true, false);
Point2Transform2_F32 des_n_to_p = desired.distort_F32(false, true);
Point2Transform2_F32 ori_to_des = new SequencePoint2Transform2_F32(ori_p_to_n, des_n_to_p);
RectangleLength2D_F32 bound;
if (type == AdjustmentType.FULL_VIEW) {
bound = DistortImageOps.boundBox_F32(paramOriginal.width, paramOriginal.height, new PointToPixelTransform_F32(ori_to_des));
} else if (type == AdjustmentType.EXPAND) {
bound = LensDistortionOps.boundBoxInside(paramOriginal.width, paramOriginal.height, new PointToPixelTransform_F32(ori_to_des));
// ensure there are no strips of black
LensDistortionOps.roundInside(bound);
} else if (type == AdjustmentType.NONE) {
bound = new RectangleLength2D_F32(0, 0, paramDesired.width, paramDesired.height);
} else {
throw new IllegalArgumentException("Unsupported type " + type);
}
float scaleX = bound.width / paramDesired.width;
float scaleY = bound.height / paramDesired.height;
float scale;
if (type == AdjustmentType.FULL_VIEW) {
scale = Math.max(scaleX, scaleY);
} else if (type == AdjustmentType.EXPAND) {
scale = Math.min(scaleX, scaleY);
} else {
scale = 1.0f;
}
float deltaX = (float) (bound.x0 + (scaleX - scale) * paramDesired.width / 2.0);
float deltaY = (float) (bound.y0 + (scaleY - scale) * paramDesired.height / 2.0);
// adjustment matrix
FMatrixRMaj A = new FMatrixRMaj(3, 3, true, scale, 0, deltaX, 0, scale, deltaY, 0, 0, 1);
FMatrixRMaj A_inv = new FMatrixRMaj(3, 3);
if (!CommonOps_FDRM.invert(A, A_inv)) {
throw new RuntimeException("Failed to invert adjustment matrix. Probably bad.");
}
if (paramMod != null) {
PerspectiveOps.adjustIntrinsic(paramDesired, A_inv, paramMod);
}
if (desiredToOriginal) {
Point2Transform2_F32 des_p_to_n = desired.undistort_F32(true, false);
Point2Transform2_F32 ori_n_to_p = original.distort_F32(false, true);
PointTransformHomography_F32 adjust = new PointTransformHomography_F32(A);
return new SequencePoint2Transform2_F32(adjust, des_p_to_n, ori_n_to_p);
} else {
PointTransformHomography_F32 adjust = new PointTransformHomography_F32(A_inv);
return new SequencePoint2Transform2_F32(ori_to_des, adjust);
}
}
use of georegression.struct.shapes.RectangleLength2D_F32 in project BoofCV by lessthanoptimal.
the class TestCirculantTracker method basicTrackingCheck.
@Test
public void basicTrackingCheck() {
GrayF32 a = new GrayF32(30, 35);
GrayF32 b = new GrayF32(30, 35);
// randomize input image and move it
GImageMiscOps.fillUniform(a, rand, 0, 200);
GImageMiscOps.fillUniform(b, rand, 0, 200);
CirculantTracker<GrayF32> alg = new CirculantTracker<>(1f / 16, 0.2, 1e-2, 0.075, 1.0, 64, 255, interp);
alg.initialize(a, 5, 6, 20, 25);
shiftCopy(2, 4, a, b);
alg.performTracking(b);
double tolerance = 1;
RectangleLength2D_F32 r = alg.getTargetLocation();
assertEquals(5 + 2, r.x0, tolerance);
assertEquals(6 + 4, r.y0, tolerance);
}
use of georegression.struct.shapes.RectangleLength2D_F32 in project BoofCV by lessthanoptimal.
the class TestCirculantTracker method updateTrackLocation.
/**
* Check a few simple motions. It seems to be accurate to within 1 pixel. Considering alphas seems to be the issue
*/
@Test
public void updateTrackLocation() {
GrayF32 a = new GrayF32(100, 100);
GrayF32 b = new GrayF32(100, 100);
// randomize input image and move it
GImageMiscOps.fillUniform(a, rand, 0, 200);
GImageMiscOps.fillUniform(b, rand, 0, 200);
shiftCopy(0, 0, a, b);
CirculantTracker<GrayF32> alg = new CirculantTracker<>(1f / 16, 0.2, 1e-2, 0.075, 1.0, 64, 255, interp);
alg.initialize(a, 5, 6, 20, 25);
alg.updateTrackLocation(b);
// only pixel level precision.
float tolerance = 1f;
// No motion motion
RectangleLength2D_F32 r = alg.getTargetLocation();
assertEquals(5, r.x0, tolerance);
assertEquals(6, r.y0, tolerance);
// check estimated motion
GImageMiscOps.fillUniform(b, rand, 0, 200);
shiftCopy(-3, 2, a, b);
alg.updateTrackLocation(b);
r = alg.getTargetLocation();
assertEquals(5 - 3, r.x0, tolerance);
assertEquals(6 + 2, r.y0, tolerance);
// try out of bounds case
GImageMiscOps.fillUniform(b, rand, 0, 200);
shiftCopy(-6, 0, a, b);
alg.updateTrackLocation(b);
assertEquals(5 - 6, r.x0, tolerance);
assertEquals(6, r.y0, tolerance);
}
use of georegression.struct.shapes.RectangleLength2D_F32 in project BoofCV by lessthanoptimal.
the class ImplRectifyImageOps_F32 method fullViewLeft.
public static void fullViewLeft(CameraPinholeRadial paramLeft, FMatrixRMaj rectifyLeft, FMatrixRMaj rectifyRight, FMatrixRMaj rectifyK) {
// need to take in account the order in which image distort will remove rectification later on
paramLeft = new CameraPinholeRadial(paramLeft);
Point2Transform2_F32 tranLeft = transformPixelToRect(paramLeft, rectifyLeft);
RectangleLength2D_F32 bound = DistortImageOps.boundBox_F32(paramLeft.width, paramLeft.height, new PointToPixelTransform_F32(tranLeft));
float scaleX = paramLeft.width / bound.width;
float scaleY = paramLeft.height / bound.height;
float scale = (float) Math.min(scaleX, scaleY);
adjustCalibrated(rectifyLeft, rectifyRight, rectifyK, bound, scale);
}
use of georegression.struct.shapes.RectangleLength2D_F32 in project BoofCV by lessthanoptimal.
the class ImplRectifyImageOps_F32 method fullViewLeft.
public static void fullViewLeft(int imageWidth, int imageHeight, FMatrixRMaj rectifyLeft, FMatrixRMaj rectifyRight) {
Point2Transform2_F32 tranLeft = new PointTransformHomography_F32(rectifyLeft);
RectangleLength2D_F32 bound = DistortImageOps.boundBox_F32(imageWidth, imageHeight, new PointToPixelTransform_F32(tranLeft));
float scaleX = imageWidth / bound.width;
float scaleY = imageHeight / bound.height;
float scale = (float) Math.min(scaleX, scaleY);
adjustUncalibrated(rectifyLeft, rectifyRight, bound, scale);
}
Aggregations