Search in sources :

Example 1 with AssistedCalibrationGui

use of boofcv.app.calib.AssistedCalibrationGui 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();
    }
}
Also used : AssistedCalibrationGui(boofcv.app.calib.AssistedCalibrationGui) GrayF32(boofcv.struct.image.GrayF32) AssistedCalibration(boofcv.app.calib.AssistedCalibration) Webcam(com.github.sarxos.webcam.Webcam) ComputeGeometryScore(boofcv.app.calib.ComputeGeometryScore) File(java.io.File) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) ProgressMonitorThread(boofcv.io.ProgressMonitorThread)

Aggregations

AssistedCalibration (boofcv.app.calib.AssistedCalibration)1 AssistedCalibrationGui (boofcv.app.calib.AssistedCalibrationGui)1 ComputeGeometryScore (boofcv.app.calib.ComputeGeometryScore)1 ProgressMonitorThread (boofcv.io.ProgressMonitorThread)1 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)1 GrayF32 (boofcv.struct.image.GrayF32)1 Webcam (com.github.sarxos.webcam.Webcam)1 BufferedImage (java.awt.image.BufferedImage)1 File (java.io.File)1