use of boofcv.struct.calib.CameraPinholeRadial in project BoofCV by lessthanoptimal.
the class TestUtilOpenCV method savePinholeRadial.
@Test
public void savePinholeRadial() {
CameraPinholeRadial model = new CameraPinholeRadial();
model.fsetK(1, 2, 3, 4, 0.65, 100, 7);
model.fsetRadial(.1, .2, .3);
model.fsetTangental(0.5, 0.7);
UtilOpenCV.save(model, "temp.yml");
CameraPinholeRadial found = UtilOpenCV.loadPinholeRadial("temp.yml");
assertEquals(model.width, found.width);
assertEquals(model.height, found.height);
assertEquals(model.fx, found.fx, 1e-8);
assertEquals(model.fy, found.fy, 1e-8);
assertEquals(model.skew, found.skew, 1e-8);
assertEquals(model.cx, found.cx, 1e-8);
assertEquals(model.cy, found.cy, 1e-8);
for (int i = 0; i < 3; i++) {
assertEquals(model.radial[i], found.radial[i], 1e-8);
}
assertEquals(model.t1, found.t1, 1e-8);
assertEquals(model.t2, found.t2, 1e-8);
assertTrue(new File("temp.yml").delete());
}
use of boofcv.struct.calib.CameraPinholeRadial in project BoofCV by lessthanoptimal.
the class TestPnPStereoResidualReprojection method compareToReprojection.
@Test
public void compareToReprojection() {
Se3_F64 worldToLeft = new Se3_F64();
ConvertRotation3D_F64.eulerToMatrix(EulerType.XYZ, 0.1, 1, -0.2, worldToLeft.getR());
worldToLeft.getT().set(-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.rightToLeft = this.param.rightToLeft;
// intrinsic parameters are configured to be identical to normalized image coordinates
param.left = new CameraPinholeRadial(1, 1, 0, 0, 0, 0, 0).fsetRadial(0, 0);
param.right = new CameraPinholeRadial(1, 1, 0, 0, 0, 0, 0).fsetRadial(0, 0);
validation.setStereoParameters(param);
validation.setModel(worldToLeft);
double expected = validation.computeDistance(pointPose.get(0));
assertEquals(expected, found, 1e-8);
}
use of boofcv.struct.calib.CameraPinholeRadial in project BoofCV by lessthanoptimal.
the class TestObjectSerialization method testIntrinsicParamters.
@Test
public void testIntrinsicParamters() {
CameraPinholeRadial original = new CameraPinholeRadial().fsetK(1, 2, 3, 4, 5, 6, 7).fsetRadial(8, 9).fsetTangental(10, 11);
CameraPinholeRadial found = serializeDeSerialize(original);
assertEquals(original.fx, found.fx, 1e-8);
assertEquals(original.fy, found.fy, 1e-8);
assertEquals(original.skew, found.skew, 1e-8);
assertEquals(original.cx, found.cx, 1e-8);
assertEquals(original.cy, found.cy, 1e-8);
assertEquals(original.width, found.width);
assertEquals(original.height, found.height);
assertEquals(original.radial[0], found.radial[0], 1e-8);
assertEquals(original.radial[1], found.radial[1], 1e-8);
assertEquals(original.t1, found.t1, 1e-8);
assertEquals(original.t2, found.t2, 1e-8);
}
use of boofcv.struct.calib.CameraPinholeRadial 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.calib.CameraPinholeRadial in project BoofCV by lessthanoptimal.
the class CameraCalibration method handleDirectory.
protected void handleDirectory() {
final CalibrateMonoPlanar calibrationAlg = new CalibrateMonoPlanar(detector.getLayout());
final CalibratedPlanarPanel gui;
ProcessThread monitor = null;
switch(modeType) {
case PINHOLE:
calibrationAlg.configurePinhole(zeroSkew, numRadial, tangential);
break;
case UNIVERSAL:
calibrationAlg.configureUniversalOmni(zeroSkew, numRadial, tangential);
break;
default:
throw new RuntimeException("Unknown model type: " + modeType);
}
if (visualize) {
switch(modeType) {
case PINHOLE:
gui = new MonoPlanarPanel();
break;
case UNIVERSAL:
gui = new FisheyePlanarPanel();
break;
default:
throw new RuntimeException("Unknown model type: " + modeType);
}
monitor = new ProcessThread(gui);
monitor.start();
} else {
gui = null;
}
File directory = new File(inputDirectory);
if (!directory.exists()) {
System.err.println("Input directory doesn't exist!");
System.err.println(" " + inputDirectory);
System.exit(0);
}
List<File> files = Arrays.asList(directory.listFiles());
BoofMiscOps.sortFilesByName(files);
if (files.isEmpty()) {
System.err.println("No image files found!");
System.err.println(inputDirectory);
System.exit(0);
}
if (visualize) {
monitor.setMessage(0, "Loading images");
}
final List<File> imagesSuccess = new ArrayList<>();
final List<File> imagesFailed = new ArrayList<>();
boolean first = true;
for (File f : files) {
if (f.isDirectory() || f.isHidden())
continue;
final BufferedImage buffered = UtilImageIO.loadImage(f.getPath());
if (buffered == null)
continue;
GrayF32 image = ConvertBufferedImage.convertFrom(buffered, (GrayF32) null);
if (visualize) {
monitor.setMessage(0, f.getName());
if (first) {
first = false;
// should do this more intelligently based on image resolution
int width = Math.min(1000, image.getWidth());
int height = Math.min(width * image.height / image.width, image.getHeight());
gui.mainView.setPreferredSize(new Dimension(width, height));
gui.showImageProcessed(buffered);
ShowImages.showWindow(gui, "Monocular Calibration", true);
} else {
BoofSwingUtil.invokeNowOrLater(new Runnable() {
@Override
public void run() {
gui.showImageProcessed(buffered);
}
});
}
}
if (!detector.process(image)) {
imagesFailed.add(f);
System.err.println("Failed to detect target in " + f.getName());
} else {
calibrationAlg.addImage(detector.getDetectedPoints());
imagesSuccess.add(f);
}
}
if (visualize) {
monitor.setMessage(1, "Computing intrinsics");
}
// process and compute intrinsic parameters
try {
final CameraModel intrinsic = calibrationAlg.process();
if (visualize) {
monitor.stopThread();
if (imagesFailed.size() > 0) {
JOptionPane.showMessageDialog(gui, "Failed to detect in " + imagesFailed.size() + " images");
}
SwingUtilities.invokeLater(new Runnable() {
public void run() {
gui.setImages(imagesSuccess);
gui.setImagesFailed(imagesFailed);
gui.setObservations(calibrationAlg.getObservations());
gui.setResults(calibrationAlg.getErrors());
gui.setCalibration(calibrationAlg.getZhangParam());
gui.setCorrection(intrinsic);
gui.repaint();
}
});
}
calibrationAlg.printStatistics();
System.out.println();
System.out.println("--- " + modeType + " Parameters ---");
System.out.println();
switch(modeType) {
case PINHOLE:
{
CameraPinholeRadial m = (CameraPinholeRadial) intrinsic;
switch(formatType) {
case BOOFCV:
CalibrationIO.save(m, outputFileName);
break;
case OPENCV:
UtilOpenCV.save(m, outputFileName);
break;
}
m.print();
}
break;
case UNIVERSAL:
{
CameraUniversalOmni m = (CameraUniversalOmni) intrinsic;
CalibrationIO.save(m, outputFileName);
m.print();
}
break;
default:
throw new RuntimeException("Unknown model type. " + modeType);
}
System.out.println();
System.out.println("Save file format " + formatType);
System.out.println();
} catch (RuntimeException e) {
if (visualize)
BoofSwingUtil.warningDialog(gui, e);
e.printStackTrace();
System.exit(1);
}
}
Aggregations