use of boofcv.struct.distort.PixelTransform2_F32 in project BoofCV by lessthanoptimal.
the class TestFDistort method setRefs.
/**
* Makes sure that setRefs doesn't cause it to blow up
*/
@Test
public void setRefs() {
ImageMiscOps.fillUniform(input, rand, 0, 200);
FDistort alg = new FDistort();
alg.setRefs(input, output).interp(InterpolationType.BILINEAR).scaleExt().apply();
ImageDistort distorter = alg.distorter;
InterpolatePixel interp = alg.interp;
;
PixelTransform2_F32 outputToInput = alg.outputToInput;
// a new image shouldn't cause new memory to be declared bad stuff to happen
GrayU8 found = new GrayU8(width / 2, height / 2);
GrayU8 expected = new GrayU8(width / 2, height / 2);
alg.setRefs(input, found).scale().apply();
assertTrue(distorter == alg.distorter);
assertTrue(interp == alg.interp);
assertTrue(outputToInput == alg.outputToInput);
new FDistort(input, expected).scaleExt().apply();
BoofTesting.assertEquals(expected, found, 1e-4);
}
use of boofcv.struct.distort.PixelTransform2_F32 in project BoofCV by lessthanoptimal.
the class TestDetectPolygonFromContour method checkDetected_LensDistortion.
private void checkDetected_LensDistortion(Class imageType, double tol) {
renderDistortedRectangles(true, imageType);
Affine2D_F32 a = new Affine2D_F32();
UtilAffine.convert(transform, a);
PixelTransform2_F32 tranFrom = new PixelTransformAffine_F32(a);
PixelTransform2_F32 tranTo = new PixelTransformAffine_F32(a.invert(null));
int numberOfSides = 4;
DetectPolygonFromContour alg = createDetector(imageType, numberOfSides, numberOfSides);
alg.setLensDistortion(image.width, image.height, tranTo, tranFrom);
alg.process(image, binary);
FastQueue<DetectPolygonFromContour.Info> found = alg.getFound();
assertEquals(rectangles.size(), found.size);
for (int i = 0; i < found.size; i++) {
Polygon2D_F64 p = found.get(i).polygon;
assertEquals(1, findMatchesOriginal(p, tol));
assertEquals(black, found.get(i).edgeInside, 3);
assertEquals(white, found.get(i).edgeOutside, white * 0.05);
}
}
use of boofcv.struct.distort.PixelTransform2_F32 in project BoofCV by lessthanoptimal.
the class TestDepthSparse3D method basicTest.
@Test
public void basicTest() {
GrayU16 depth = new GrayU16(w, h);
depth.set(5, 6, 1000);
CameraPinholeRadial param = new CameraPinholeRadial(1, 1, 0, 5, 10, w, h).fsetRadial(0, 0);
PixelTransform2_F32 v2d = new PixelTransform2_F32() {
@Override
public void compute(int x, int y) {
distX = x + 1;
distY = y + 2;
}
};
DepthSparse3D<GrayU16> alg = new DepthSparse3D.I<>(2.1);
alg.configure(LensDistortionOps.narrow(param), v2d);
alg.setDepthImage(depth);
assertTrue(alg.process(4, 4));
Point3D_F64 found = alg.getWorldPt();
Point2D_F64 norm = new Point2D_F64();
PerspectiveOps.convertPixelToNorm(param, new Point2D_F64(4, 4), norm);
double z = 1000 * 2.1;
assertEquals(z, found.z, 1e-8);
assertEquals(norm.x * z, found.x, 1e-8);
assertEquals(norm.y * z, found.y, 1e-8);
}
use of boofcv.struct.distort.PixelTransform2_F32 in project BoofCV by lessthanoptimal.
the class StitchingFromMotion2D method setOriginToCurrent.
/**
* Sets the current image to be the origin of the stitched coordinate system. The background is filled
* with a value of 0.
* Must be called after {@link #process(boofcv.struct.image.ImageBase)}.
*/
public void setOriginToCurrent() {
IT currToWorld = (IT) worldToCurr.invert(null);
IT oldWorldToNewWorld = (IT) worldToInit.concat(currToWorld, null);
PixelTransform2_F32 newToOld = converter.convertPixel(oldWorldToNewWorld, null);
// fill in the background color
GImageMiscOps.fill(workImage, 0);
// render the transform
distorter.setModel(newToOld);
distorter.apply(stitchedImage, workImage);
// swap the two images
I s = workImage;
workImage = stitchedImage;
stitchedImage = s;
// have motion estimates be relative to this frame
motion.setToFirst();
first = true;
computeCurrToInit_PixelTran();
}
use of boofcv.struct.distort.PixelTransform2_F32 in project BoofCV by lessthanoptimal.
the class UtilImageMotion method createPixelTransform.
/**
* Given a motion model create a PixelTransform used to distort the image
*
* @param transform Motion transform
* @return PixelTransform_F32 used to distort the image
*/
public static PixelTransform2_F32 createPixelTransform(InvertibleTransform transform) {
PixelTransform2_F32 pixelTran;
if (transform instanceof Homography2D_F64) {
Homography2D_F32 t = ConvertFloatType.convert((Homography2D_F64) transform, null);
pixelTran = new PixelTransformHomography_F32(t);
} else if (transform instanceof Homography2D_F32) {
pixelTran = new PixelTransformHomography_F32((Homography2D_F32) transform);
} else if (transform instanceof Affine2D_F64) {
Affine2D_F32 t = UtilAffine.convert((Affine2D_F64) transform, null);
pixelTran = new PixelTransformAffine_F32(t);
} else if (transform instanceof Affine2D_F32) {
pixelTran = new PixelTransformAffine_F32((Affine2D_F32) transform);
} else {
throw new RuntimeException("Unknown model type");
}
return pixelTran;
}
Aggregations