Search in sources :

Example 1 with ConfigFiducialImage

use of boofcv.factory.fiducial.ConfigFiducialImage 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 ConfigFiducialImage

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

the class TestSquareImage_to_FiducialDetector method createDetector.

@Override
public FiducialDetector createDetector(ImageType imageType) {
    SquareImage_to_FiducialDetector ret = FactoryFiducial.squareImage(new ConfigFiducialImage(), ConfigThreshold.local(ThresholdType.LOCAL_MEAN, 13), imageType.getImageClass());
    ret.addPatternImage(UtilImageIO.loadImage(directory + "../patterns/chicken.png", imageType.getImageClass()), 125, 0.1);
    return ret;
}
Also used : ConfigFiducialImage(boofcv.factory.fiducial.ConfigFiducialImage)

Example 3 with ConfigFiducialImage

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

the class FiducialDetection method parseImage.

void parseImage(int index, String[] args) {
    boolean robust = true;
    List<String> paths = new ArrayList<>();
    GrowQueue_F64 sizes = new GrowQueue_F64();
    double borderWidth = 0.25;
    for (; index < args.length; index++) {
        String arg = args[index];
        if (!arg.startsWith("--")) {
            throw new RuntimeException("Expected flags for image fiducial");
        }
        splitFlag(arg);
        if (flagName.compareToIgnoreCase("Robust") == 0) {
            robust = Boolean.parseBoolean(parameters);
        } else if (flagName.compareToIgnoreCase("Image") == 0) {
            String[] words = parameters.split(":");
            if (words.length != 2)
                throw new RuntimeException("Expected two for width and image path");
            sizes.add(Double.parseDouble(words[0]));
            paths.add(words[1]);
        } else if (flagName.compareToIgnoreCase("Border") == 0) {
            borderWidth = Double.parseDouble(parameters);
        } else {
            throw new RuntimeException("Unknown image option " + flagName);
        }
    }
    if (paths.isEmpty())
        throw new RuntimeException("Need to specify patterns");
    System.out.println("image: robust = " + robust + " total patterns = " + paths.size() + " border = " + borderWidth);
    ConfigFiducialImage config = new ConfigFiducialImage();
    config.borderWidthFraction = borderWidth;
    ConfigThreshold configThreshold;
    if (robust)
        configThreshold = ConfigThreshold.local(ThresholdType.LOCAL_MEAN, 21);
    else
        configThreshold = ConfigThreshold.fixed(DEFAULT_THRESHOLD);
    SquareImage_to_FiducialDetector<GrayU8> detector = FactoryFiducial.squareImage(config, configThreshold, GrayU8.class);
    for (int i = 0; i < paths.size(); i++) {
        BufferedImage buffered = UtilImageIO.loadImage(paths.get(i));
        if (buffered == null)
            throw new RuntimeException("Can't find pattern " + paths.get(i));
        GrayU8 pattern = new GrayU8(buffered.getWidth(), buffered.getHeight());
        ConvertBufferedImage.convertFrom(buffered, pattern);
        detector.addPatternImage(pattern, 125, sizes.get(i));
    }
    this.detector = detector;
}
Also used : ArrayList(java.util.ArrayList) GrowQueue_F64(org.ddogleg.struct.GrowQueue_F64) ConfigFiducialImage(boofcv.factory.fiducial.ConfigFiducialImage) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) ConfigThreshold(boofcv.factory.filter.binary.ConfigThreshold) GrayU8(boofcv.struct.image.GrayU8)

Example 4 with ConfigFiducialImage

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

the class TestCreateFiducialSquareImage method single.

@Test
public void single() throws IOException, InterruptedException {
    createDocument(String.format("-PrintInfo -PageSize=letter -OutputFile=%s 4 %s", document_name + ".pdf", names[0]));
    GrayF32 gray = loadImageGray();
    ConfigFiducialImage config = new ConfigFiducialImage();
    FiducialDetector<GrayF32> detector = createDetector(config);
    detector.detect(gray);
    assertEquals(1, detector.totalFound());
    assertEquals(0, detector.getId(0));
}
Also used : GrayF32(boofcv.struct.image.GrayF32) ConfigFiducialImage(boofcv.factory.fiducial.ConfigFiducialImage) Test(org.junit.Test)

Example 5 with ConfigFiducialImage

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

the class TestCreateFiducialSquareImage method grid.

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

Aggregations

ConfigFiducialImage (boofcv.factory.fiducial.ConfigFiducialImage)6 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)3 GrayF32 (boofcv.struct.image.GrayF32)3 BufferedImage (java.awt.image.BufferedImage)3 LensDistortionRadialTangential (boofcv.alg.distort.radtan.LensDistortionRadialTangential)2 ConfigThreshold (boofcv.factory.filter.binary.ConfigThreshold)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 SquareImage_to_FiducialDetector (boofcv.abst.fiducial.SquareImage_to_FiducialDetector)1 LensDistortionNarrowFOV (boofcv.alg.distort.LensDistortionNarrowFOV)1 ConfigFiducialBinary (boofcv.factory.fiducial.ConfigFiducialBinary)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 BufferedReader (java.io.BufferedReader)1 FileReader (java.io.FileReader)1