Difference between revisions of "Example Calibrate Planar Stereo"

From BoofCV
Jump to navigationJump to search
m
m
Line 8: Line 8:
This example demonstrate how to calibrate a stereo camera system using a high level interface which automatically detects calibration targets in a set of stereo images.  After calibration the intrinsic parameters of each camera is found as well as their extrinsic relationship with each other. Both the square grid and chessboard patterns are supported by this example.  For a full description of the calibration process and instruction on how to do it yourself see the tutorial linked to below.
This example demonstrate how to calibrate a stereo camera system using a high level interface which automatically detects calibration targets in a set of stereo images.  After calibration the intrinsic parameters of each camera is found as well as their extrinsic relationship with each other. Both the square grid and chessboard patterns are supported by this example.  For a full description of the calibration process and instruction on how to do it yourself see the tutorial linked to below.


Example File: [https://github.com/lessthanoptimal/BoofCV/blob/v0.20/examples/src/boofcv/examples/calibration/ExampleCalibrateStereo.java ExampleCalibrateStereo.java]
Example File: [https://github.com/lessthanoptimal/BoofCV/blob/v0.21/examples/src/boofcv/examples/calibration/ExampleCalibrateStereo.java ExampleCalibrateStereo.java]


Calibration Tutorial: [[Tutorial_Camera_Calibration|Wikipage]]
Calibration Tutorial: [[Tutorial_Camera_Calibration|Wikipage]]
Line 59: Line 59:
public void setupBumblebeeSquare() {
public void setupBumblebeeSquare() {
// Creates a detector and specifies its physical characteristics
// Creates a detector and specifies its physical characteristics
detector = FactoryPlanarCalibrationTarget.detectorSquareGrid(new ConfigSquareGrid(5, 7, 30, 30));
detector = FactoryCalibrationTarget.detectorSquareGrid(new ConfigSquareGrid(4, 3, 30, 30));


String directory = UtilIO.pathExample("calibration/stereo/Bumblebee2_Square");
String directory = UtilIO.pathExample("calibration/stereo/Bumblebee2_Square");
Line 72: Line 72:
public void setupBumblebeeChess() {
public void setupBumblebeeChess() {
// Creates a detector and specifies its physical characteristics
// Creates a detector and specifies its physical characteristics
detector = FactoryPlanarCalibrationTarget.detectorChessboard(new ConfigChessboard(5,7, 30));
detector = FactoryCalibrationTarget.detectorChessboard(new ConfigChessboard(7, 5, 30));


String directory = UtilIO.pathExample("calibration/stereo/Bumblebee2_Chess");
String directory = UtilIO.pathExample("calibration/stereo/Bumblebee2_Chess");

Revision as of 21:33, 23 January 2016

This example demonstrate how to calibrate a stereo camera system using a high level interface which automatically detects calibration targets in a set of stereo images. After calibration the intrinsic parameters of each camera is found as well as their extrinsic relationship with each other. Both the square grid and chessboard patterns are supported by this example. For a full description of the calibration process and instruction on how to do it yourself see the tutorial linked to below.

Example File: ExampleCalibrateStereo.java

Calibration Tutorial: Wikipage

Concepts:

  • Camera calibration
  • Lens distortion
  • Intrinsic parameters
  • Stereo Vision

Relevant Applets:

Related Examples:

Example Code

/**
 * Example of how to calibrate a stereo camera system using a planar calibration grid given a set of images.
 * Intrinsic camera parameters are estimated for both cameras individually, then extrinsic parameters
 * for the two cameras relative to each other are found   This example does not rectify the images, which is
 * required for some algorithms. See {@link boofcv.examples.stereo.ExampleRectifyCalibratedStereo}. Both square grid and chessboard targets
 * are demonstrated in this example. See calibration tutorial for a discussion of different target types and how to
 * collect good calibration images.
 *
 * All the image processing and calibration is taken care of inside of {@link CalibrateStereoPlanar}.  The code below
 * loads calibration images as inputs, calibrates, and saves results to an XML file.  See in code comments for tuning
 * and implementation issues.
 *
 * @see boofcv.examples.stereo.ExampleRectifyCalibratedStereo
 * @see CalibrateStereoPlanar
 *
 * @author Peter Abeles
 */
public class ExampleCalibrateStereo {

	// Detects the target and calibration point inside the target
	CalibrationDetector detector;

	// List of calibration images
	List<String> left;
	List<String> right;

	/**
	 * Square grid target taken by a PtGrey Bumblebee camera.
	 */
	public void setupBumblebeeSquare() {
		// Creates a detector and specifies its physical characteristics
		detector = FactoryCalibrationTarget.detectorSquareGrid(new ConfigSquareGrid(4, 3, 30, 30));

		String directory = UtilIO.pathExample("calibration/stereo/Bumblebee2_Square");

		left = BoofMiscOps.directoryList(directory, "left");
		right = BoofMiscOps.directoryList(directory, "right");
	}

	/**
	 * Chessboard target taken by a PtGrey Bumblebee camera.
	 */
	public void setupBumblebeeChess() {
		// Creates a detector and specifies its physical characteristics
		detector = FactoryCalibrationTarget.detectorChessboard(new ConfigChessboard(7, 5, 30));

		String directory = UtilIO.pathExample("calibration/stereo/Bumblebee2_Chess");

		left = BoofMiscOps.directoryList(directory, "left");
		right = BoofMiscOps.directoryList(directory, "right");
	}

	/**
	 * Process calibration images, compute intrinsic parameters, save to a file
	 */
	public void process() {
		// Declare and setup the calibration algorithm
		CalibrateStereoPlanar calibratorAlg = new CalibrateStereoPlanar(detector);
		calibratorAlg.configure(true, 2, false);

		// ensure the lists are in the same order
		Collections.sort(left);
		Collections.sort(right);

		for( int i = 0; i < left.size(); i++ ) {
			BufferedImage l = UtilImageIO.loadImage(left.get(i));
			BufferedImage r = UtilImageIO.loadImage(right.get(i));

			ImageFloat32 imageLeft = ConvertBufferedImage.convertFrom(l,(ImageFloat32)null);
			ImageFloat32 imageRight = ConvertBufferedImage.convertFrom(r,(ImageFloat32)null);

			if( !calibratorAlg.addPair(imageLeft, imageRight) )
				System.out.println("Failed to detect target in "+left.get(i)+" and/or "+right.get(i));
		}

		// Process and compute calibration parameters
		StereoParameters stereoCalib = calibratorAlg.process();

		// print out information on its accuracy and errors
		calibratorAlg.printStatistics();

		// save results to a file and print out
		UtilIO.saveXML(stereoCalib, "stereo.xml");
		stereoCalib.print();

		// Note that the stereo baseline translation will be specified in the same units as the calibration grid.
		// Which is in millimeters (mm) in this example.
	}

	public static void main( String args[] ) {
		ExampleCalibrateStereo alg = new ExampleCalibrateStereo();

		// Select which set of targets to use
		alg.setupBumblebeeChess();
//		alg.setupBumblebeeSquare();

		// compute and save results
		alg.process();
	}
}