Difference between revisions of "Example Calibrate Planar Mono"

From BoofCV
Jump to navigationJump to search
m
m
Line 7: Line 7:
This example demonstrates how to use a high level calibration class that automatically detects calibration targets as viewed from a single (monocular) camera in a set of images.  After processing the images the intrinsic camera parameters and lens distortion are saved to an XML file.  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 demonstrates how to use a high level calibration class that automatically detects calibration targets as viewed from a single (monocular) camera in a set of images.  After processing the images the intrinsic camera parameters and lens distortion are saved to an XML file.  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.17/examples/src/boofcv/examples/calibration/ExampleCalibrateMonocularPlanar.java ExampleCalibrateMonocularPlanar.java]
Example File: [https://github.com/lessthanoptimal/BoofCV/blob/v0.19/examples/src/boofcv/examples/calibration/ExampleCalibrateMonocularPlanar.java ExampleCalibrateMonocularPlanar.java]


Calibration Tutorial: [[Tutorial_Camera_Calibration|Wikipage]]
Calibration Tutorial: [[Tutorial_Camera_Calibration|Wikipage]]
Line 48: Line 48:
// Detects the target and calibration point inside the target
// Detects the target and calibration point inside the target
PlanarCalibrationDetector detector;
PlanarCalibrationDetector detector;
// Description of the target's physical dimension
PlanarCalibrationTarget target;


// List of calibration images
// List of calibration images
List<String> images;
List<String> images;
// Many 3D operations assumed a right handed coordinate system with +Z pointing out of the image.
// If the image coordinate system is left handed then the y-axis needs to be flipped to meet
// that requirement.  Most of the time this is false.
boolean flipY;


/**
/**
Line 64: Line 56:
*/
*/
private void setupZhang99() {
private void setupZhang99() {
// Use the wrapper below for square grid targets.
// Creates a detector and specifies its physical characteristics
detector = FactoryPlanarCalibrationTarget.detectorSquareGrid(new ConfigSquareGrid(15, 15));
detector = FactoryPlanarCalibrationTarget.detectorSquareGrid(new ConfigSquareGrid(15, 15, 0.5, 7.0 / 18.0));
 
// physical description
target = FactoryPlanarCalibrationTarget.gridSquare(15, 15, 0.5, 7.0 / 18.0);


// load image list
// load image list
String directory = "../data/evaluation/calibration/mono/PULNiX_CCD_6mm_Zhang";
String directory = "../data/evaluation/calibration/mono/PULNiX_CCD_6mm_Zhang";
images = BoofMiscOps.directoryList(directory,"CalibIm");
images = BoofMiscOps.directoryList(directory,"CalibIm");
// standard image format
flipY = false;
}
}


Line 82: Line 68:
*/
*/
private void setupBumbleBee() {
private void setupBumbleBee() {
// Use the wrapper below for chessboard targets.
// Creates a detector and specifies its physical characteristics
detector = FactoryPlanarCalibrationTarget.detectorChessboard(new ConfigChessboard(5,7));
detector = FactoryPlanarCalibrationTarget.detectorChessboard(new ConfigChessboard(5,7, 30));
 
// physical description
target = FactoryPlanarCalibrationTarget.gridChess(5, 7, 30);


// load image list
// load image list
String directory = "../data/evaluation/calibration/stereo/Bumblebee2_Chess";
String directory = "../data/evaluation/calibration/stereo/Bumblebee2_Chess";
images = BoofMiscOps.directoryList(directory,"left");
images = BoofMiscOps.directoryList(directory,"left");
// standard image format
flipY = false;
}
}


Line 102: Line 82:


// Declare and setup the calibration algorithm
// Declare and setup the calibration algorithm
CalibrateMonoPlanar calibrationAlg = new CalibrateMonoPlanar(detector, flipY);
CalibrateMonoPlanar calibrationAlg = new CalibrateMonoPlanar(detector);


// tell it type type of target and which parameters to estimate
// tell it type type of target and which parameters to estimate
calibrationAlg.configure(target, true, 2);
calibrationAlg.configure( true, 2, false);


for( String n : images ) {
for( String n : images ) {

Revision as of 22:06, 15 September 2015

This example demonstrates how to use a high level calibration class that automatically detects calibration targets as viewed from a single (monocular) camera in a set of images. After processing the images the intrinsic camera parameters and lens distortion are saved to an XML file. 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: ExampleCalibrateMonocularPlanar.java

Calibration Tutorial: Wikipage

Concepts:

  • Camera calibration
  • Lens distortion
  • Intrinsic parameters

Relevant Applets:

Related Examples:

Example Code

/**
 * Example of how to calibrate a single (monocular) camera using a high level interface that processes images of planar
 * calibration targets.  The entire calibration target must be observable in the image and for best results images
 * should be in focus and not blurred.  For a lower level example of camera calibration which processes a set of
 * observed calibration points see {@link ExampleCalibrateMonocularPlanar}.
 *
 * After processing both intrinsic camera parameters and lens distortion are estimated.  Square grid and chessboard
 * targets are demonstrated by 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 CalibrateMonoPlanar}.  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 CalibrateMonoPlanar
 *
 * @author Peter Abeles
 */
public class ExampleCalibrateMonocularPlanar {

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

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

	/**
	 * Images from Zhang's website.  Square grid pattern.
	 */
	private void setupZhang99() {
		// Creates a detector and specifies its physical characteristics
		detector = FactoryPlanarCalibrationTarget.detectorSquareGrid(new ConfigSquareGrid(15, 15, 0.5, 7.0 / 18.0));

		// load image list
		String directory = "../data/evaluation/calibration/mono/PULNiX_CCD_6mm_Zhang";
		images = BoofMiscOps.directoryList(directory,"CalibIm");
	}

	/**
	 * Images collected from a Bumblee Bee stereo camera.  Large amounts of radial distortion. Chessboard pattern.
	 */
	private void setupBumbleBee() {
		// Creates a detector and specifies its physical characteristics
		detector = FactoryPlanarCalibrationTarget.detectorChessboard(new ConfigChessboard(5,7, 30));

		// load image list
		String directory = "../data/evaluation/calibration/stereo/Bumblebee2_Chess";
		images = BoofMiscOps.directoryList(directory,"left");
	}

	/**
	 * Process calibration images, compute intrinsic parameters, save to a file
	 */
	public void process() {

		// Declare and setup the calibration algorithm
		CalibrateMonoPlanar calibrationAlg = new CalibrateMonoPlanar(detector);

		// tell it type type of target and which parameters to estimate
		calibrationAlg.configure( true, 2, false);

		for( String n : images ) {
			BufferedImage input = UtilImageIO.loadImage(n);
			if( n != null ) {
				ImageFloat32 image = ConvertBufferedImage.convertFrom(input,(ImageFloat32)null);
				if( !calibrationAlg.addImage(image) )
					System.err.println("Failed to detect target in "+n);
			}
		}
		// process and compute intrinsic parameters
		IntrinsicParameters intrinsic = calibrationAlg.process();

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

		calibrationAlg.printStatistics();
		System.out.println();
		System.out.println("--- Intrinsic Parameters ---");
		System.out.println();
		intrinsic.print();
	}


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

		// which target should it process
//		alg.setupZhang99();
		alg.setupBumbleBee();

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