Difference between revisions of "Example Fisheye To Pinhole"

From BoofCV
Jump to navigationJump to search
m
m
 
(One intermediate revision by the same user not shown)
Line 10: Line 10:
run part of the view needs to be converted into a pinhole camera view.
run part of the view needs to be converted into a pinhole camera view.


Example File: [https://github.com/lessthanoptimal/BoofCV/blob/v0.33/examples/src/boofcv/examples/calibration/ExampleFisheyeToPinhole.java ExampleFisheyeToPinhole.java]
Example File: [https://github.com/lessthanoptimal/BoofCV/blob/v0.38/examples/src/boofcv/examples/calibration/ExampleFisheyeToPinhole.java ExampleFisheyeToPinhole.java]


Concepts:
Concepts:
Line 22: Line 22:
<syntaxhighlight lang="java">
<syntaxhighlight lang="java">
/**
/**
  * Demonstration for how to project a fisheye camera onto a synthetic pinhole camera view. Internally NarrowToWide
  * Demonstration for how to project a fisheye camera onto a synthetic pinhole camera view. Internally NarrowToWide
  * has the following steps. 1) compute normalized image coordinates for each pixel. 2) convert into unit circle
  * has the following steps. 1) compute normalized image coordinates for each pixel. 2) convert into unit circle
  * coordinates, and 3) compute pixe location in fisheye camera.
  * coordinates, and 3) compute pixe location in fisheye camera.
  *
  *
Line 58: Line 58:
distorter.setModel(new PointToPixelTransform_F32(transform));
distorter.setModel(new PointToPixelTransform_F32(transform));


// Render the image. The camera will have a rotation of 0 and will thus be looking straight forward
// 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);
Planar<GrayU8> pinholeImage = fisheyeImage.createNew(pinholeModel.width, pinholeModel.height);



Latest revision as of 09:15, 12 July 2021

Fisheye lens can allow a view greater than 180 degrees to be seen. This cannot be represented using a pinhole camera and is highly distorted. To allow many vision algorithms to run part of the view needs to be converted into a pinhole camera view.

Example File: ExampleFisheyeToPinhole.java

Concepts:

  • Fisheye Cameras
  • Camera calibration

Related Examples:

Example Code

/**
 * Demonstration for how to project a fisheye camera onto a synthetic pinhole camera view. Internally NarrowToWide
 * has the following steps. 1) compute normalized image coordinates for each pixel. 2) convert into unit circle
 * coordinates, and 3) compute pixe location in fisheye camera.
 *
 * @author Peter Abeles
 */
public class ExampleFisheyeToPinhole {
	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);
	}
}