use of boofcv.struct.distort.PointToPixelTransform_F32 in project BoofCV by lessthanoptimal.
the class CalibrationDetectorCircleHexagonalGrid method setLensDistortion.
@Override
public void setLensDistortion(@Nullable LensDistortionNarrowFOV distortion, int width, int height) {
if (distortion == null)
detector.getEllipseDetector().setLensDistortion(null, null);
else {
Point2Transform2_F32 pointDistToUndist = distortion.undistort_F32(true, true);
Point2Transform2_F32 pointUndistToDist = distortion.distort_F32(true, true);
PixelTransform<Point2D_F32> distToUndist = new PointToPixelTransform_F32(pointDistToUndist);
PixelTransform<Point2D_F32> undistToDist = new PointToPixelTransform_F32(pointUndistToDist);
detector.getEllipseDetector().setLensDistortion(distToUndist, undistToDist);
}
}
use of boofcv.struct.distort.PointToPixelTransform_F32 in project BoofCV by lessthanoptimal.
the class RemoveLensDistortionApp method addUndistorted.
private void addUndistorted(final String name, final Point2Transform2_F32 model) {
// Set up image distort
InterpolatePixel<T> interp = FactoryInterpolation.createPixel(0, 255, InterpolationType.BILINEAR, BorderType.ZERO, undist.getImageType());
ImageDistort<T, T> undistorter = FactoryDistort.distort(false, interp, undist.getImageType());
undistorter.setModel(new PointToPixelTransform_F32(model));
undistorter.apply(dist, undist);
final BufferedImage out = ConvertBufferedImage.convertTo(undist, null, true);
// Add this rectified image
SwingUtilities.invokeLater(() -> gui.addItem(new ImagePanel(out), name));
}
use of boofcv.struct.distort.PointToPixelTransform_F32 in project BoofCV by lessthanoptimal.
the class FisheyePinholeApp method processImage.
@Override
public void processImage(int sourceID, long frameID, BufferedImage buffered, ImageBase input) {
synchronized (imageLock) {
// create a copy of the input image for output purposes
if (buffFisheye.getWidth() != buffered.getWidth() || buffFisheye.getHeight() != buffered.getHeight()) {
buffFisheye = new BufferedImage(buffered.getWidth(), buffered.getHeight(), BufferedImage.TYPE_INT_BGR);
panelFisheye.setPreferredSize(new Dimension(buffered.getWidth(), buffered.getHeight()));
panelFisheye.setImageUI(buffFisheye);
distortImage.setModel(new PointToPixelTransform_F32(distorter));
}
buffFisheye.createGraphics().drawImage(buffered, 0, 0, null);
fisheye.setTo((T) input);
rerenderPinhole();
}
}
use of boofcv.struct.distort.PointToPixelTransform_F32 in project BoofCV by lessthanoptimal.
the class ExampleFisheyeToPinhole method main.
public static void main(String[] args) {
// Path to image data and calibration data
String fisheyePath = UtilIO.pathExample("fisheye/theta/");
// load the fisheye camera parameters
CameraUniversalOmni fisheyeModel = CalibrationIO.load(new File(fisheyePath, "front.yaml"));
// Specify what the pinhole camera should look like
CameraPinhole pinholeModel = new CameraPinhole(400, 400, 0, 300, 300, 600, 600);
// Create the transform from pinhole to fisheye views
LensDistortionNarrowFOV pinholeDistort = new LensDistortionPinhole(pinholeModel);
LensDistortionWideFOV fisheyeDistort = new LensDistortionUniversalOmni(fisheyeModel);
NarrowToWidePtoP_F32 transform = new NarrowToWidePtoP_F32(pinholeDistort, fisheyeDistort);
// Load fisheye RGB image
BufferedImage bufferedFisheye = UtilImageIO.loadImage(fisheyePath, "front_table.jpg");
Planar<GrayU8> fisheyeImage = ConvertBufferedImage.convertFrom(bufferedFisheye, true, ImageType.pl(3, GrayU8.class));
// Create the image distorter which will render the image
InterpolatePixel<Planar<GrayU8>> interp = FactoryInterpolation.createPixel(0, 255, InterpolationType.BILINEAR, BorderType.ZERO, fisheyeImage.getImageType());
ImageDistort<Planar<GrayU8>, Planar<GrayU8>> distorter = FactoryDistort.distort(false, interp, fisheyeImage.getImageType());
// Pass in the transform created above
distorter.setModel(new PointToPixelTransform_F32(transform));
// Render the image. The camera will have a rotation of 0 and will thus be looking straight forward
Planar<GrayU8> pinholeImage = fisheyeImage.createNew(pinholeModel.width, pinholeModel.height);
distorter.apply(fisheyeImage, pinholeImage);
BufferedImage bufferedPinhole0 = ConvertBufferedImage.convertTo(pinholeImage, null, true);
// rotate the virtual pinhole camera to the right
transform.setRotationWideToNarrow(ConvertRotation3D_F32.eulerToMatrix(EulerType.YXZ, 0.8f, 0, 0, null));
distorter.apply(fisheyeImage, pinholeImage);
BufferedImage bufferedPinhole1 = ConvertBufferedImage.convertTo(pinholeImage, null, true);
// Display the results
ListDisplayPanel panel = new ListDisplayPanel();
panel.addImage(bufferedPinhole0, "Pinehole Forward");
panel.addImage(bufferedPinhole1, "Pinehole Right");
panel.addImage(bufferedFisheye, "Fisheye");
panel.setPreferredSize(new Dimension(600, 450));
ShowImages.showWindow(panel, "Fisheye to Pinhole", true);
}
use of boofcv.struct.distort.PointToPixelTransform_F32 in project BoofCV by lessthanoptimal.
the class ExamplePointDeformKeyPoints method main.
public static void main(String[] args) {
BufferedImage orig = UtilImageIO.loadImageNotNull(UtilIO.pathExample("standard/man_mls.jpg"));
var bufferedOut = new BufferedImage(orig.getWidth(), orig.getHeight(), BufferedImage.TYPE_INT_RGB);
Planar<GrayF32> input = ConvertBufferedImage.convertFrom(orig, true, ImageType.pl(3, GrayF32.class));
Planar<GrayF32> output = input.createSameShape();
var src = new ArrayList<Point2D_F32>();
var dst = new ArrayList<Point2D_F32>();
src.add(new Point2D_F32(64, 241));
src.add(new Point2D_F32(266, 119));
src.add(new Point2D_F32(265, 240));
src.add(new Point2D_F32(208, 410));
src.add(new Point2D_F32(181, 536));
src.add(new Point2D_F32(335, 409));
src.add(new Point2D_F32(375, 531));
src.add(new Point2D_F32(473, 238));
for (Point2D_F32 p : src) {
dst.add(p.copy());
}
var config = new ConfigDeformPointMLS();
PointDeformKeyPoints deform = FactoryDistort.deformMls(config);
deform.setImageShape(input.width, input.height);
ImageDistort<Planar<GrayF32>, Planar<GrayF32>> distorter = FactoryDistort.distort(true, InterpolationType.BILINEAR, BorderType.ZERO, input.getImageType(), input.getImageType());
deform.setImageShape(input.width, input.height);
deform.setSource(src);
deform.setDestination(dst);
ConvertBufferedImage.convertTo(output, bufferedOut, true);
ImagePanel panel = ShowImages.showWindow(bufferedOut, "Point Based Distortion Animation", true);
int count = 0;
while (true) {
// specify new locations of key points
double theta = count++ * Math.PI / 30;
// right arm
dst.get(7).y = (float) (238 + Math.sin(theta) * 30);
// left arm
dst.get(0).y = (float) (241 - Math.sin(theta * 2.0) * 20);
// head
dst.get(1).x = (float) (266 + Math.sin(theta * 0.25) * 10);
// tell the deformation algorithm that destination points have changed
deform.setDestination(dst);
// Tell the distorter that the model has changed. If cached is set to false you can ignore this step
distorter.setModel(new PointToPixelTransform_F32(deform));
// distort the image
distorter.apply(input, output);
// Show the results
ConvertBufferedImage.convertTo(output, bufferedOut, true);
panel.repaint();
BoofMiscOps.sleep(30);
}
}
Aggregations