use of boofcv.struct.calib.CameraPinholeBrown in project BoofCV by lessthanoptimal.
the class ImplRectifyImageOps_F64 method allInsideLeft.
public static void allInsideLeft(CameraPinholeBrown paramLeft, DMatrixRMaj rectifyLeft, DMatrixRMaj rectifyRight, DMatrixRMaj rectifyK, ImageDimension rectifiedSize) {
// need to take in account the order in which image distort will remove rectification later on
paramLeft = new CameraPinholeBrown(paramLeft);
Point2Transform2_F64 tranLeft = transformPixelToRect(paramLeft, rectifyLeft);
Point2D_F64 work = new Point2D_F64();
RectangleLength2D_F64 bound = LensDistortionOps_F64.boundBoxInside(paramLeft.width, paramLeft.height, new PointToPixelTransform_F64(tranLeft), work);
LensDistortionOps_F64.roundInside(bound);
// Select scale to maintain the same number of pixels
double scale = Math.sqrt((paramLeft.width * paramLeft.height) / (bound.width * bound.height));
rectifiedSize.width = (int) (scale * bound.width + 0.5);
rectifiedSize.height = (int) (scale * bound.height + 0.5);
adjustCalibrated(rectifyLeft, rectifyRight, rectifyK, bound, scale);
}
use of boofcv.struct.calib.CameraPinholeBrown in project BoofCV by lessthanoptimal.
the class ImplRectifyImageOps_F64 method fullViewLeft.
public static void fullViewLeft(CameraPinholeBrown paramLeft, DMatrixRMaj rectifyLeft, DMatrixRMaj rectifyRight, DMatrixRMaj rectifyK, ImageDimension rectifiedSize) {
// need to take in account the order in which image distort will remove rectification later on
paramLeft = new CameraPinholeBrown(paramLeft);
Point2Transform2_F64 tranLeft = transformPixelToRect(paramLeft, rectifyLeft);
Point2D_F64 work = new Point2D_F64();
RectangleLength2D_F64 bound = DistortImageOps.boundBox_F64(paramLeft.width, paramLeft.height, new PointToPixelTransform_F64(tranLeft), work);
// Select scale to maintain the same number of pixels
double scale = Math.sqrt((paramLeft.width * paramLeft.height) / (bound.width * bound.height));
rectifiedSize.width = (int) (scale * bound.width + 0.5);
rectifiedSize.height = (int) (scale * bound.height + 0.5);
adjustCalibrated(rectifyLeft, rectifyRight, rectifyK, bound, scale);
}
use of boofcv.struct.calib.CameraPinholeBrown in project BoofCV by lessthanoptimal.
the class TestDepthSparse3D method basicTest.
@Test
void basicTest() {
GrayU16 depth = new GrayU16(w, h);
depth.set(5, 6, 1000);
CameraPinholeBrown param = new CameraPinholeBrown(1, 1, 0, 5, 10, w, h).fsetRadial(0, 0);
PixelTransform<Point2D_F32> v2d = new PixelTransform<Point2D_F32>() {
@Override
public void compute(int x, int y, Point2D_F32 output) {
output.x = x + 1;
output.y = y + 2;
}
@Override
public PixelTransform<Point2D_F32> copyConcurrent() {
return null;
}
};
DepthSparse3D<GrayU16> alg = new DepthSparse3D.I<>(2.1);
alg.configure(LensDistortionFactory.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.calib.CameraPinholeBrown in project BoofCV by lessthanoptimal.
the class TestPnPStereoResidualReprojection method compareToReprojection.
@Test
void compareToReprojection() {
Se3_F64 worldToLeft = new Se3_F64();
ConvertRotation3D_F64.eulerToMatrix(EulerType.XYZ, 0.1, 1, -0.2, worldToLeft.getR());
worldToLeft.getT().setTo(-0.3, 0.4, 1);
generateScene(10, worldToLeft, false);
// make the input model incorrect
worldToLeft.getR().set(2, 1, 2);
// compute the error in normalized image coordinates per element
PnPStereoResidualReprojection alg = new PnPStereoResidualReprojection();
alg.setModel(new StereoPose(worldToLeft, leftToRight));
// compute errors with perfect model
double[] error = new double[alg.getN()];
alg.computeResiduals(pointPose.get(0), error, 0);
double found = 0;
for (double e : error) {
found += e * e;
}
PnPStereoDistanceReprojectionSq validation = new PnPStereoDistanceReprojectionSq();
StereoParameters param = new StereoParameters();
param.right_to_left = this.param.right_to_left;
// intrinsic parameters are configured to be identical to normalized image coordinates
param.left = new CameraPinholeBrown(1, 1, 0, 0, 0, 0, 0).fsetRadial(0, 0);
param.right = new CameraPinholeBrown(1, 1, 0, 0, 0, 0, 0).fsetRadial(0, 0);
validation.setStereoParameters(param);
validation.setModel(worldToLeft);
double expected = validation.distance(pointPose.get(0));
assertEquals(expected, found, 1e-8);
}
use of boofcv.struct.calib.CameraPinholeBrown in project BoofCV by lessthanoptimal.
the class TestSelectTracksInFrameForBundleAdjustment method minimal_all.
/**
* Basic test. Each track is visible in every frame at the same location.
*/
@Test
void minimal_all() {
var scene = new VisOdomBundleAdjustment<>(BTrack::new);
var alg = new SelectTracksInFrameForBundleAdjustment(0xBEEF);
// makes the math easier
alg.configUniform.regionScaleFactor = 1.0;
alg.maxFeaturesPerFrame = 200;
var selected = new ArrayList<BTrack>();
scene.addCamera(new CameraPinholeBrown(0, 0, 0, 0, 0, width, height));
for (int i = 0; i < 5; i++) {
scene.addFrame(i);
}
for (int i = 0; i < 200; i++) {
scene.tracks.grow().id = i;
}
for (int i = 0; i < scene.frames.size; i++) {
BFrame frame = scene.frames.get(i);
for (int j = 0; j < 200; j++) {
BTrack track = scene.tracks.get(j);
frame.tracks.add(track);
// pixel coordinates
int x = (i * 10) % width;
int y = 10 * ((i * 10) / width);
VisOdomBundleAdjustment.BObservation o = track.observations.grow();
o.frame = frame;
o.pixel.setTo(x, y);
}
}
alg.selectTracks(scene, selected);
assertEquals(200, selected.size());
}
Aggregations