use of boofcv.struct.calib.CameraPinhole in project BoofCV by lessthanoptimal.
the class TestPerspectiveOps method matrixToParam.
@Test
public void matrixToParam() {
double fx = 1;
double fy = 2;
double skew = 3;
double cx = 4;
double cy = 5;
DMatrixRMaj K = new DMatrixRMaj(3, 3, true, fx, skew, cx, 0, fy, cy, 0, 0, 1);
CameraPinhole ret = PerspectiveOps.matrixToParam(K, 100, 200, null);
assertTrue(ret.fx == fx);
assertTrue(ret.fy == fy);
assertTrue(ret.skew == skew);
assertTrue(ret.cx == cx);
assertTrue(ret.cy == cy);
assertTrue(ret.width == 100);
assertTrue(ret.height == 200);
}
use of boofcv.struct.calib.CameraPinhole in project BoofCV by lessthanoptimal.
the class TestPinholeToEquirectangular_F64 method setDirection.
/**
* Rotate the camera and see if the camera center is pointing in the right direction now
*/
@Test
public void setDirection() {
CameraPinhole intrinsic = new CameraPinhole(400, 400, 0, imgWidth / 2, imgHeight / 2, imgWidth, imgHeight);
PinholeToEquirectangular_F64 alg = new PinholeToEquirectangular_F64();
alg.setPinhole(intrinsic);
alg.setEquirectangularShape(equiWidth, equiHeight);
alg.setDirection(0, Math.PI / 2, 0);
assertPointing(alg, imgWidth / 2, imgHeight / 2, 1, 0, 0);
}
use of boofcv.struct.calib.CameraPinhole in project BoofCV by lessthanoptimal.
the class ImplPerspectiveOps_F64 method matrixToParam.
public static <C extends CameraPinhole> C matrixToParam(DMatrixRMaj K, int width, int height, C param) {
if (param == null)
param = (C) new CameraPinhole();
param.fx = K.get(0, 0);
param.fy = K.get(1, 1);
param.skew = K.get(0, 1);
param.cx = K.get(0, 2);
param.cy = K.get(1, 2);
param.width = width;
param.height = height;
return param;
}
use of boofcv.struct.calib.CameraPinhole in project BoofCV by lessthanoptimal.
the class VisualizeSquareBinaryFiducial method process.
public void process(String nameImage, @Nullable String nameIntrinsic) {
CameraPinholeBrown intrinsic = nameIntrinsic == null ? null : (CameraPinholeBrown) CalibrationIO.load(nameIntrinsic);
GrayF32 input = Objects.requireNonNull(UtilImageIO.loadImage(nameImage, GrayF32.class));
var undistorted = new GrayF32(input.width, input.height);
InputToBinary<GrayF32> inputToBinary = FactoryThresholdBinary.globalOtsu(0, 255, 1.0, true, GrayF32.class);
Detector detector = new Detector(gridWidth, borderWidth, inputToBinary);
detector.setLengthSide(0.1);
if (intrinsic != null) {
CameraPinholeBrown paramUndist = new CameraPinholeBrown();
ImageDistort<GrayF32, GrayF32> undistorter = LensDistortionOps.changeCameraModel(AdjustmentType.EXPAND, BorderType.EXTENDED, intrinsic, new CameraPinhole(intrinsic), paramUndist, ImageType.single(GrayF32.class));
detector.configure(new LensDistortionBrown(paramUndist), paramUndist.width, paramUndist.height, false);
undistorter.apply(input, undistorted);
detector.process(undistorted);
} else {
detector.process(input);
}
System.out.println("Total Found: " + detector.squares.size());
DogArray<FoundFiducial> fiducials = detector.getFound();
int N = Math.min(20, detector.squares.size());
ListDisplayPanel squares = new ListDisplayPanel();
for (int i = 0; i < N; i++) {
squares.addImage(VisualizeBinaryData.renderBinary(detector.squares.get(i), false, null), " " + i);
squares.addImage(ConvertBufferedImage.convertTo(detector.squaresGray.get(i), null), " " + i);
}
BufferedImage output = new BufferedImage(input.width, input.height, BufferedImage.TYPE_INT_RGB);
ConvertBufferedImage.convertTo(input, output);
Graphics2D g2 = output.createGraphics();
g2.setColor(Color.RED);
g2.setStroke(new BasicStroke(2));
for (int i = 0; i < N; i++) {
VisualizeShapes.drawArrowSubPixel(fiducials.get(i).distortedPixels, 3, 1, g2);
}
ShowImages.showWindow(output, "Binary", true);
ShowImages.showWindow(squares, "Candidates", true);
}
use of boofcv.struct.calib.CameraPinhole in project BoofCV by lessthanoptimal.
the class RefineTwoViewPinholeRotation method refine.
/**
* Refines the provided parameters. Inputs are only modified if it returns true. If two views are specified
* but there's a single view assumption then only the first view is used.
*
* @param associatedPixels (Input) Matches image features between the two views. Pixels.
* @param rotation (Input/Output) Initial estimate of rotation. Results are written to it.
* @param intrinsic1 (Input/Output) Initial estimate of intrinsic1. Results are written to it.
* @param intrinsic2 (Input/Output) Initial estimate of intrinsic2. Results are written to it.
* @return true if it thinks it has a valid solution. False if it knows it failed.
*/
public boolean refine(List<AssociatedPair> associatedPixels, DMatrixRMaj rotation, CameraPinhole intrinsic1, CameraPinhole intrinsic2) {
this.associatedPixels = associatedPixels;
this.inputIntrinsic1 = intrinsic1;
this.inputIntrinsic2 = intrinsic2;
// Copy inputs over
ConvertRotation3D_F64.matrixToRodrigues(rotation, function.state.rotation);
function.state.intrinsic1.setTo(intrinsic1);
function.state.intrinsic2.setTo(intrinsic2);
initialParameters.resize(function.getNumOfInputsN());
function.state.encode(initialParameters.data);
// Configure the minimization
minimizer.setFunction(function, new NumericalJacobianForward_DDRM(new ResidualFunction()));
minimizer.initialize(initialParameters.data, converge.ftol, converge.gtol);
errorBefore = minimizer.getFunctionValue();
// Iterate until a final condition has been met
int iterations;
for (iterations = 0; iterations < converge.maxIterations; iterations++) {
if (minimizer.iterate())
break;
}
errorAfter = minimizer.getFunctionValue();
// Get the refined values
function.state.decode(minimizer.getParameters());
if (verbose != null) {
double theta = UtilAngle.degree(function.state.rotation.theta);
CameraPinhole found1 = function.state.intrinsic1;
CameraPinhole found2 = function.state.intrinsic2;
verbose.printf("before=%.2e after=%.2e iterations=%d converged=%s, " + "view1={fx=%.1f fy=%.1f, cx=%.1f cy=%.1f), " + "view2=(fx=%.1f fy=%.1f, cx=%.1f cy=%.1f) theta=%.2f\n", errorBefore, errorAfter, iterations, minimizer.isConverged(), found1.fx, found1.fy, found1.cx, found1.cy, found2.fx, found2.fy, found2.cx, found2.cy, theta);
}
// Copy results
intrinsic1.setTo(function.state.intrinsic1);
intrinsic2.setTo(function.state.intrinsic2);
ConvertRotation3D_F64.rodriguesToMatrix(function.state.rotation, rotation);
return true;
}
Aggregations