use of boofcv.app.calib.AssistedCalibration in project BoofCV by lessthanoptimal.
the class CameraCalibration method handleWebcam.
/**
* Captures calibration data live using a webcam and a GUI to assist the user
*/
public void handleWebcam() {
final Webcam webcam = openSelectedCamera();
if (desiredWidth > 0 && desiredHeight > 0)
UtilWebcamCapture.adjustResolution(webcam, desiredWidth, desiredHeight);
webcam.open();
// close the webcam gracefully on exit
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() {
if (webcam.isOpen()) {
System.out.println("Closing webcam");
webcam.close();
}
}
});
ComputeGeometryScore quality = new ComputeGeometryScore(zeroSkew, detector.getLayout());
AssistedCalibrationGui gui = new AssistedCalibrationGui(webcam.getViewSize());
JFrame frame = ShowImages.showWindow(gui, "Webcam Calibration", true);
GrayF32 gray = new GrayF32(webcam.getViewSize().width, webcam.getViewSize().height);
if (desiredWidth > 0 && desiredHeight > 0) {
if (gray.width != desiredWidth || gray.height != desiredHeight)
System.err.println("Actual camera resolution does not match desired. Actual: " + gray.width + " " + gray.height + " Desired: " + desiredWidth + " " + desiredHeight);
}
AssistedCalibration assisted = new AssistedCalibration(detector, quality, gui, OUTPUT_DIRECTORY, IMAGE_DIRECTORY);
assisted.init(gray.width, gray.height);
BufferedImage image;
while ((image = webcam.getImage()) != null && !assisted.isFinished()) {
ConvertBufferedImage.convertFrom(image, gray);
try {
assisted.process(gray, image);
} catch (RuntimeException e) {
System.err.println("BUG!!! saving image to crash_image.png");
UtilImageIO.saveImage(image, "crash_image.png");
throw e;
}
}
webcam.close();
if (assisted.isFinished()) {
frame.setVisible(false);
inputDirectory = new File(OUTPUT_DIRECTORY, IMAGE_DIRECTORY).getPath();
outputFileName = new File(OUTPUT_DIRECTORY, "intrinsic.yaml").getPath();
handleDirectory();
}
}
Aggregations