Search in sources :

Example 1 with LensDistortionRadialTangential

use of boofcv.alg.distort.radtan.LensDistortionRadialTangential in project BoofCV by lessthanoptimal.

the class FiducialTrackerDemoApp method openExample.

@Override
public void openExample(Object o) {
    // stop everything because all the data structures about about to be changed
    stopAllInputProcessing();
    PathLabel example = (PathLabel) o;
    String name = example.label;
    String videoName = example.getPath();
    String seperator = System.getProperty("file.separator");
    String path = videoName.substring(0, videoName.lastIndexOf(seperator.charAt(0)));
    ConfigThreshold configThreshold = ConfigThreshold.local(ThresholdType.LOCAL_MEAN, 21);
    boolean stability = true;
    if (name.compareTo(SQUARE_NUMBER) == 0) {
        detector = FactoryFiducial.squareBinary(new ConfigFiducialBinary(0.1), configThreshold, imageClass);
    } else if (name.compareTo(SQUARE_PICTURE) == 0) {
        double length = 0.1;
        detector = FactoryFiducial.squareImage(new ConfigFiducialImage(), configThreshold, imageClass);
        SquareImage_to_FiducialDetector<I> d = (SquareImage_to_FiducialDetector<I>) detector;
        String pathImg = new File(path, "../patterns").getPath();
        List<String> names = new ArrayList<>();
        names.add("chicken.png");
        names.add("yinyang.png");
        for (String foo : names) {
            BufferedImage img = media.openImage(new File(pathImg, foo).getPath());
            if (img == null)
                throw new RuntimeException("Can't find file " + new File(pathImg, foo).getPath());
            d.addPatternImage(ConvertBufferedImage.convertFromSingle(img, null, imageClass), 125, length);
        }
    } else if (name.compareTo(CALIB_CHESS) == 0) {
        detector = FactoryFiducial.calibChessboard(new ConfigChessboard(7, 5, 0.03), imageClass);
    } else if (name.compareTo(CALIB_SQUARE_GRID) == 0) {
        detector = FactoryFiducial.calibSquareGrid(new ConfigSquareGrid(4, 3, 0.03, 0.03), imageClass);
    } else if (name.compareTo(CALIB_SQUARE_BINARY_GRID) == 0) {
        File configFile = new File(path, "description_4x3_3x3_4cm_2cm.txt");
        try {
            ConfigSquareGridBinary config = ConfigSquareGridBinary.parseSimple(new BufferedReader(new FileReader(configFile)));
            detector = FactoryFiducial.calibSquareGridBinary(config, imageClass);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    } else if (name.compareTo(CALIB_CIRCLE_HEXAGONAL_GRID) == 0) {
        stability = false;
        detector = FactoryFiducial.calibCircleHexagonalGrid(new ConfigCircleHexagonalGrid(24, 28, 1, 1.2), imageClass);
    } else if (name.compareTo(CALIB_CIRCLE_REGULAR_GRID) == 0) {
        stability = false;
        detector = FactoryFiducial.calibCircleRegularGrid(new ConfigCircleRegularGrid(10, 8, 1.5, 2.5), imageClass);
    } else {
        throw new RuntimeException("Unknown selection");
    }
    controls.setShowStability(stability);
    intrinsic = CalibrationIO.load(media.openFile(path + "/intrinsic.yaml"));
    detector.setLensDistortion(new LensDistortionRadialTangential(intrinsic), intrinsic.width, intrinsic.height);
    fiducialInfo.clear();
    // give it some initial values so that it doesn't look like there is huge errors right off the bat
    stabilityMax.location = 0.01;
    stabilityMax.orientation = 0.02;
    openVideo(false, videoName);
}
Also used : ConfigFiducialBinary(boofcv.factory.fiducial.ConfigFiducialBinary) IOException(java.io.IOException) ConfigFiducialImage(boofcv.factory.fiducial.ConfigFiducialImage) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) ConfigThreshold(boofcv.factory.filter.binary.ConfigThreshold) LensDistortionRadialTangential(boofcv.alg.distort.radtan.LensDistortionRadialTangential) SquareImage_to_FiducialDetector(boofcv.abst.fiducial.SquareImage_to_FiducialDetector) PathLabel(boofcv.io.PathLabel) BufferedReader(java.io.BufferedReader) ArrayList(java.util.ArrayList) List(java.util.List) FileReader(java.io.FileReader) File(java.io.File)

Example 2 with LensDistortionRadialTangential

use of boofcv.alg.distort.radtan.LensDistortionRadialTangential in project BoofCV by lessthanoptimal.

the class VisualizeSquareBinaryFiducial method process.

public void process(String nameImage, String nameIntrinsic) {
    CameraPinholeRadial intrinsic = nameIntrinsic == null ? null : (CameraPinholeRadial) CalibrationIO.load(nameIntrinsic);
    GrayF32 input = UtilImageIO.loadImage(nameImage, GrayF32.class);
    GrayF32 undistorted = new GrayF32(input.width, input.height);
    InputToBinary<GrayF32> inputToBinary = FactoryThresholdBinary.globalOtsu(0, 255, true, GrayF32.class);
    Detector detector = new Detector(gridWidth, borderWidth, inputToBinary);
    detector.setLengthSide(0.1);
    if (intrinsic != null) {
        CameraPinholeRadial paramUndist = new CameraPinholeRadial();
        ImageDistort<GrayF32, GrayF32> undistorter = LensDistortionOps.changeCameraModel(AdjustmentType.EXPAND, BorderType.EXTENDED, intrinsic, new CameraPinhole(intrinsic), paramUndist, ImageType.single(GrayF32.class));
        detector.configure(new LensDistortionRadialTangential(paramUndist), paramUndist.width, paramUndist.height, false);
        undistorter.apply(input, undistorted);
        detector.process(undistorted);
    } else {
        detector.process(input);
    }
    System.out.println("Total Found: " + detector.squares.size());
    FastQueue<FoundFiducial> fiducials = detector.getFound();
    int N = Math.min(20, detector.squares.size());
    ListDisplayPanel squares = new ListDisplayPanel();
    for (int i = 0; i < N; i++) {
        squares.addImage(VisualizeBinaryData.renderBinary(detector.squares.get(i), false, null), " " + i);
        squares.addImage(ConvertBufferedImage.convertTo(detector.squaresGray.get(i), null), " " + i);
    }
    BufferedImage output = new BufferedImage(input.width, input.height, BufferedImage.TYPE_INT_RGB);
    ConvertBufferedImage.convertTo(input, output);
    Graphics2D g2 = output.createGraphics();
    g2.setColor(Color.RED);
    g2.setStroke(new BasicStroke(2));
    for (int i = 0; i < N; i++) {
        VisualizeShapes.drawArrowSubPixel(fiducials.get(i).distortedPixels, 3, 1, g2);
    }
    ShowImages.showWindow(output, "Binary", true);
    ShowImages.showWindow(squares, "Candidates", true);
}
Also used : ListDisplayPanel(boofcv.gui.ListDisplayPanel) FoundFiducial(boofcv.alg.fiducial.square.FoundFiducial) CameraPinhole(boofcv.struct.calib.CameraPinhole) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) LensDistortionRadialTangential(boofcv.alg.distort.radtan.LensDistortionRadialTangential) GrayF32(boofcv.struct.image.GrayF32) FactoryShapeDetector(boofcv.factory.shape.FactoryShapeDetector) ConfigPolygonDetector(boofcv.factory.shape.ConfigPolygonDetector) CameraPinholeRadial(boofcv.struct.calib.CameraPinholeRadial)

Example 3 with LensDistortionRadialTangential

use of boofcv.alg.distort.radtan.LensDistortionRadialTangential in project BoofCV by lessthanoptimal.

the class PinholeRadialToEquirectangular_F32 method setPinhole.

/**
 * Specifies the pinhole camera
 * @param pinhole intrinsic parameters of pinhole camera
 */
public void setPinhole(CameraPinholeRadial pinhole) {
    this.pinhole = pinhole;
    declareVectors(pinhole.width, pinhole.height);
    // computing the 3D ray through each pixel in the pinhole camera at it's canonical
    // location
    Point2Transform2_F32 pixelToNormalized = new LensDistortionRadialTangential(pinhole).undistort_F32(true, false);
    Point2D_F32 norm = new Point2D_F32();
    for (int pixelY = 0; pixelY < pinhole.height; pixelY++) {
        for (int pixelX = 0; pixelX < pinhole.width; pixelX++) {
            pixelToNormalized.compute(pixelX, pixelY, norm);
            Point3D_F32 v = vectors[pixelY * pinhole.width + pixelX];
            v.set(norm.x, norm.y, 1);
        }
    }
}
Also used : Point3D_F32(georegression.struct.point.Point3D_F32) LensDistortionRadialTangential(boofcv.alg.distort.radtan.LensDistortionRadialTangential) Point2D_F32(georegression.struct.point.Point2D_F32) Point2Transform2_F32(boofcv.struct.distort.Point2Transform2_F32)

Example 4 with LensDistortionRadialTangential

use of boofcv.alg.distort.radtan.LensDistortionRadialTangential in project BoofCV by lessthanoptimal.

the class TestBaseDetectFiducialSquare method checkFindKnown.

private void checkFindKnown(CameraPinholeRadial intrinsic, double tol) {
    GrayU8 pattern = createPattern(6 * 20, false);
    Quadrilateral_F64 where = new Quadrilateral_F64(50, 50, 130, 60, 140, 150, 40, 140);
    // Quadrilateral_F64 where = new Quadrilateral_F64(50,50,  100,50,  100,150,  50,150);
    GrayU8 image = new GrayU8(width, height);
    ImageMiscOps.fill(image, 255);
    render(pattern, where, image);
    Dummy dummy = new Dummy();
    dummy.configure(new LensDistortionRadialTangential(intrinsic), width, height, false);
    dummy.process(image);
    assertEquals(1, dummy.detected.size());
    Quadrilateral_F64 found = dummy.getFound().get(0).distortedPixels;
    // System.out.println("found "+found);
    // System.out.println("where "+where);
    checkMatch(where, found.a, tol);
    checkMatch(where, found.b, tol);
    checkMatch(where, found.c, tol);
    checkMatch(where, found.d, tol);
    // see if the undistorted image is as expected
    checkPattern(dummy.detected.get(0));
}
Also used : LensDistortionRadialTangential(boofcv.alg.distort.radtan.LensDistortionRadialTangential) Quadrilateral_F64(georegression.struct.shapes.Quadrilateral_F64) GrayU8(boofcv.struct.image.GrayU8)

Example 5 with LensDistortionRadialTangential

use of boofcv.alg.distort.radtan.LensDistortionRadialTangential in project BoofCV by lessthanoptimal.

the class TestCalibrationFiducialDetector method loadDistortion.

@Override
public LensDistortionNarrowFOV loadDistortion(boolean distorted) {
    CameraPinholeRadial model = CalibrationIO.load(new File(directory, "intrinsic.yaml"));
    if (!distorted) {
        model.radial = null;
        model.t1 = model.t2 = 0;
    }
    return new LensDistortionRadialTangential(model);
}
Also used : LensDistortionRadialTangential(boofcv.alg.distort.radtan.LensDistortionRadialTangential) CameraPinholeRadial(boofcv.struct.calib.CameraPinholeRadial) File(java.io.File)

Aggregations

LensDistortionRadialTangential (boofcv.alg.distort.radtan.LensDistortionRadialTangential)15 CameraPinholeRadial (boofcv.struct.calib.CameraPinholeRadial)9 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)6 BufferedImage (java.awt.image.BufferedImage)6 GrayF32 (boofcv.struct.image.GrayF32)5 Point2D_F64 (georegression.struct.point.Point2D_F64)5 LensDistortionNarrowFOV (boofcv.alg.distort.LensDistortionNarrowFOV)4 File (java.io.File)4 Point2Transform2_F64 (boofcv.struct.distort.Point2Transform2_F64)3 GrayU8 (boofcv.struct.image.GrayU8)3 Se3_F64 (georegression.struct.se.Se3_F64)3 FoundFiducial (boofcv.alg.fiducial.square.FoundFiducial)2 ConfigFiducialBinary (boofcv.factory.fiducial.ConfigFiducialBinary)2 ConfigFiducialImage (boofcv.factory.fiducial.ConfigFiducialImage)2 ConfigPolygonDetector (boofcv.factory.shape.ConfigPolygonDetector)2 FactoryShapeDetector (boofcv.factory.shape.FactoryShapeDetector)2 ListDisplayPanel (boofcv.gui.ListDisplayPanel)2 ImagePanel (boofcv.gui.image.ImagePanel)2 CameraPinhole (boofcv.struct.calib.CameraPinhole)2 Point2Transform2_F32 (boofcv.struct.distort.Point2Transform2_F32)2