Search in sources :

Example 1 with ConfigFiducialBinary

use of boofcv.factory.fiducial.ConfigFiducialBinary in project BoofCV by lessthanoptimal.

the class DetectFiducialSquareBinaryApp method createDetector.

protected void createDetector(boolean initializing) {
    if (!initializing)
        BoofSwingUtil.checkGuiThread();
    synchronized (lockProcessing) {
        ConfigThreshold configThresh = controls.polygonPanel.getThresholdPanel().createConfig();
        ConfigFiducialBinary configFid = controls.getConfig();
        final InputToBinary<GrayF32> binary = FactoryThresholdBinary.threshold(configThresh, GrayF32.class);
        final DetectPolygonBinaryGrayRefine<GrayF32> squareDetector = FactoryShapeDetector.polygon(configFid.squareDetector, GrayF32.class);
        detector = new Detector(configFid, binary, squareDetector);
    }
}
Also used : ConfigThreshold(boofcv.factory.filter.binary.ConfigThreshold) ConfigFiducialBinary(boofcv.factory.fiducial.ConfigFiducialBinary) GrayF32(boofcv.struct.image.GrayF32) FactoryShapeDetector(boofcv.factory.shape.FactoryShapeDetector)

Example 2 with ConfigFiducialBinary

use of boofcv.factory.fiducial.ConfigFiducialBinary 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 3 with ConfigFiducialBinary

use of boofcv.factory.fiducial.ConfigFiducialBinary in project BoofCV by lessthanoptimal.

the class BenchmarkFiducialDetector method main.

public static void main(String[] args) {
    String directory = UtilIO.pathExample("fiducial/binary/");
    FiducialDetector detector = FactoryFiducial.squareBinary(new ConfigFiducialBinary(0.2), ConfigThreshold.fixed(100), GrayU8.class);
    perform(directory, detector);
// detector = FactoryFiducial.
// squareBinaryRobust(new ConfigFiducialBinary(0.2), 6, GrayU8.class);
// perform(directory, detector);
}
Also used : ConfigFiducialBinary(boofcv.factory.fiducial.ConfigFiducialBinary)

Example 4 with ConfigFiducialBinary

use of boofcv.factory.fiducial.ConfigFiducialBinary in project BoofCV by lessthanoptimal.

the class FiducialDetection method parseBinary.

void parseBinary(int index, String[] args) {
    boolean robust = true;
    double size = 1;
    int gridWidth = 4;
    double borderWidth = 0.25;
    for (; index < args.length; index++) {
        String arg = args[index];
        if (!arg.startsWith("--")) {
            throw new RuntimeException("Expected flags for binary fiducial");
        }
        splitFlag(arg);
        if (flagName.compareToIgnoreCase("Robust") == 0) {
            robust = Boolean.parseBoolean(parameters);
        } else if (flagName.compareToIgnoreCase("Size") == 0) {
            size = Double.parseDouble(parameters);
        } else if (flagName.compareToIgnoreCase("GridWidth") == 0) {
            gridWidth = Integer.parseInt(parameters);
        } else if (flagName.compareToIgnoreCase("Border") == 0) {
            borderWidth = Double.parseDouble(parameters);
        } else {
            throw new RuntimeException("Unknown image option " + flagName);
        }
    }
    System.out.println("binary: robust = " + robust + " size = " + size + " grid width = " + gridWidth + " border = " + borderWidth);
    ConfigFiducialBinary configFid = new ConfigFiducialBinary();
    configFid.targetWidth = size;
    configFid.gridWidth = gridWidth;
    configFid.squareDetector.minimumRefineEdgeIntensity = 10;
    configFid.borderWidthFraction = borderWidth;
    ConfigThreshold configThreshold;
    if (robust)
        configThreshold = ConfigThreshold.local(ThresholdType.LOCAL_MEAN, 21);
    else
        configThreshold = ConfigThreshold.fixed(DEFAULT_THRESHOLD);
    detector = FactoryFiducial.squareBinary(configFid, configThreshold, GrayU8.class);
}
Also used : ConfigFiducialBinary(boofcv.factory.fiducial.ConfigFiducialBinary) ConfigThreshold(boofcv.factory.filter.binary.ConfigThreshold) GrayU8(boofcv.struct.image.GrayU8)

Example 5 with ConfigFiducialBinary

use of boofcv.factory.fiducial.ConfigFiducialBinary in project BoofCV by lessthanoptimal.

the class TestCreateFiducialSquareBinary method grid.

@Test
public void grid() throws IOException, InterruptedException {
    int[] expected = new int[] { 234, 123 };
    createDocument(String.format("-PrintInfo -PrintGrid  -Grid=fill -PageSize=letter -OutputFile=%s 3 %d %d", document_name + ".pdf", expected[0], expected[1]));
    GrayF32 gray = loadImageGray();
    ConfigFiducialBinary config = new ConfigFiducialBinary(30);
    FiducialDetector<GrayF32> detector = FactoryFiducial.squareBinary(config, configThreshold, GrayF32.class);
    detector.detect(gray);
    assertEquals(9, detector.totalFound());
    for (int i = 0; i < detector.totalFound(); i++) {
        assertEquals(expected[i % 2], detector.getId(i));
    }
}
Also used : ConfigFiducialBinary(boofcv.factory.fiducial.ConfigFiducialBinary) GrayF32(boofcv.struct.image.GrayF32) Test(org.junit.Test)

Aggregations

ConfigFiducialBinary (boofcv.factory.fiducial.ConfigFiducialBinary)9 GrayF32 (boofcv.struct.image.GrayF32)6 Test (org.junit.Test)4 ConfigThreshold (boofcv.factory.filter.binary.ConfigThreshold)3 LensDistortionRadialTangential (boofcv.alg.distort.radtan.LensDistortionRadialTangential)2 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)2 BufferedImage (java.awt.image.BufferedImage)2 File (java.io.File)2 SquareImage_to_FiducialDetector (boofcv.abst.fiducial.SquareImage_to_FiducialDetector)1 LensDistortionNarrowFOV (boofcv.alg.distort.LensDistortionNarrowFOV)1 ConfigFiducialImage (boofcv.factory.fiducial.ConfigFiducialImage)1 FactoryShapeDetector (boofcv.factory.shape.FactoryShapeDetector)1 PathLabel (boofcv.io.PathLabel)1 CameraPinholeRadial (boofcv.struct.calib.CameraPinholeRadial)1 GrayU8 (boofcv.struct.image.GrayU8)1 Point2D_F64 (georegression.struct.point.Point2D_F64)1 Se3_F64 (georegression.struct.se.Se3_F64)1 Polygon2D_F64 (georegression.struct.shapes.Polygon2D_F64)1 Quadrilateral_F64 (georegression.struct.shapes.Quadrilateral_F64)1 BufferedReader (java.io.BufferedReader)1