Search in sources :

Example 86 with GrayF32

use of boofcv.struct.image.GrayF32 in project BoofCV by lessthanoptimal.

the class ExampleColorHistogramLookup method coupledHueSat.

/**
 * HSV stores color information in Hue and Saturation while intensity is in Value.  This computes a 2D histogram
 * from hue and saturation only, which makes it lighting independent.
 */
public static List<double[]> coupledHueSat(List<File> images) {
    List<double[]> points = new ArrayList<>();
    Planar<GrayF32> rgb = new Planar<>(GrayF32.class, 1, 1, 3);
    Planar<GrayF32> hsv = new Planar<>(GrayF32.class, 1, 1, 3);
    for (File f : images) {
        BufferedImage buffered = UtilImageIO.loadImage(f.getPath());
        if (buffered == null)
            throw new RuntimeException("Can't load image!");
        rgb.reshape(buffered.getWidth(), buffered.getHeight());
        hsv.reshape(buffered.getWidth(), buffered.getHeight());
        ConvertBufferedImage.convertFrom(buffered, rgb, true);
        ColorHsv.rgbToHsv_F32(rgb, hsv);
        Planar<GrayF32> hs = hsv.partialSpectrum(0, 1);
        // The number of bins is an important parameter.  Try adjusting it
        Histogram_F64 histogram = new Histogram_F64(12, 12);
        // range of hue is from 0 to 2PI
        histogram.setRange(0, 0, 2.0 * Math.PI);
        // range of saturation is from 0 to 1
        histogram.setRange(1, 0, 1.0);
        // Compute the histogram
        GHistogramFeatureOps.histogram(hs, histogram);
        // normalize so that image size doesn't matter
        UtilFeature.normalizeL2(histogram);
        points.add(histogram.value);
    }
    return points;
}
Also used : Histogram_F64(boofcv.alg.feature.color.Histogram_F64) GrayF32(boofcv.struct.image.GrayF32) Planar(boofcv.struct.image.Planar) File(java.io.File) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage)

Example 87 with GrayF32

use of boofcv.struct.image.GrayF32 in project BoofCV by lessthanoptimal.

the class ExampleColorHistogramLookup method coupledRGB.

/**
 * Constructs a 3D histogram using RGB.  RGB is a popular color space, but the resulting histogram will
 * depend on lighting conditions and might not produce the accurate results.
 */
public static List<double[]> coupledRGB(List<File> images) {
    List<double[]> points = new ArrayList<>();
    Planar<GrayF32> rgb = new Planar<>(GrayF32.class, 1, 1, 3);
    for (File f : images) {
        BufferedImage buffered = UtilImageIO.loadImage(f.getPath());
        if (buffered == null)
            throw new RuntimeException("Can't load image!");
        rgb.reshape(buffered.getWidth(), buffered.getHeight());
        ConvertBufferedImage.convertFrom(buffered, rgb, true);
        // The number of bins is an important parameter.  Try adjusting it
        Histogram_F64 histogram = new Histogram_F64(10, 10, 10);
        histogram.setRange(0, 0, 255);
        histogram.setRange(1, 0, 255);
        histogram.setRange(2, 0, 255);
        GHistogramFeatureOps.histogram(rgb, histogram);
        // normalize so that image size doesn't matter
        UtilFeature.normalizeL2(histogram);
        points.add(histogram.value);
    }
    return points;
}
Also used : Histogram_F64(boofcv.alg.feature.color.Histogram_F64) GrayF32(boofcv.struct.image.GrayF32) Planar(boofcv.struct.image.Planar) File(java.io.File) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage)

Example 88 with GrayF32

use of boofcv.struct.image.GrayF32 in project BoofCV by lessthanoptimal.

the class ExampleImageClassification method main.

public static void main(String[] args) throws IOException {
    // Test set 89.9% for 10 categories
    ClassifierAndSource cs = FactoryImageClassifier.vgg_cifar10();
    // ClassifierAndSource cs = FactoryImageClassifier.nin_imagenet(); // Test set 62.6% for 1000 categories
    File path = DeepBoofDataBaseOps.downloadModel(cs.getSource(), new File("download_data"));
    ImageClassifier<Planar<GrayF32>> classifier = cs.getClassifier();
    classifier.loadModel(path);
    List<String> categories = classifier.getCategories();
    String imagePath = UtilIO.pathExample("recognition/pixabay");
    List<File> images = Arrays.asList(UtilIO.findMatches(new File(imagePath), "\\w*.jpg"));
    Collections.sort(images);
    ImageClassificationPanel gui = new ImageClassificationPanel();
    ShowImages.showWindow(gui, "Image Classification", true);
    for (File f : images) {
        BufferedImage buffered = UtilImageIO.loadImage(f.getPath());
        if (buffered == null)
            throw new RuntimeException("Couldn't find input image");
        Planar<GrayF32> image = new Planar<>(GrayF32.class, buffered.getWidth(), buffered.getHeight(), 3);
        ConvertBufferedImage.convertFromPlanar(buffered, image, true, GrayF32.class);
        classifier.classify(image);
        // add image and results to the GUI for display
        gui.addImage(buffered, f.getName(), classifier.getAllResults(), categories);
    }
}
Also used : ImageClassificationPanel(boofcv.gui.ImageClassificationPanel) GrayF32(boofcv.struct.image.GrayF32) ClassifierAndSource(boofcv.factory.scene.ClassifierAndSource) Planar(boofcv.struct.image.Planar) File(java.io.File) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage)

Example 89 with GrayF32

use of boofcv.struct.image.GrayF32 in project BoofCV by lessthanoptimal.

the class ExampleMultiviewSceneReconstruction method detectFeatures.

/**
 * Detects image features.  Saves their location, description, and pixel color
 */
private void detectFeatures(BufferedImage colorImage, FastQueue<BrightFeature> features, FastQueue<Point2D_F64> pixels, GrowQueue_I32 colors) {
    GrayF32 image = ConvertBufferedImage.convertFrom(colorImage, (GrayF32) null);
    features.reset();
    pixels.reset();
    colors.reset();
    detDesc.detect(image);
    for (int i = 0; i < detDesc.getNumberOfFeatures(); i++) {
        Point2D_F64 p = detDesc.getLocation(i);
        features.grow().set(detDesc.getDescription(i));
        // store pixels are normalized image coordinates
        pixelToNorm.compute(p.x, p.y, pixels.grow());
        colors.add(colorImage.getRGB((int) p.x, (int) p.y));
    }
}
Also used : GrayF32(boofcv.struct.image.GrayF32) Point2D_F64(georegression.struct.point.Point2D_F64) DetectDescribePoint(boofcv.abst.feature.detdesc.DetectDescribePoint)

Example 90 with GrayF32

use of boofcv.struct.image.GrayF32 in project BoofCV by lessthanoptimal.

the class ExampleTrackingKlt method main.

public static void main(String[] args) {
    // tune the tracker for the image size and visual appearance
    ConfigGeneralDetector configDetector = new ConfigGeneralDetector(-1, 8, 1);
    PkltConfig configKlt = new PkltConfig(3, new int[] { 1, 2, 4, 8 });
    PointTracker<GrayF32> tracker = FactoryPointTracker.klt(configKlt, configDetector, GrayF32.class, null);
    // Open a webcam at a resolution close to 640x480
    Webcam webcam = UtilWebcamCapture.openDefault(640, 480);
    // Create the panel used to display the image and feature tracks
    ImagePanel gui = new ImagePanel();
    gui.setPreferredSize(webcam.getViewSize());
    ShowImages.showWindow(gui, "KLT Tracker", true);
    int minimumTracks = 100;
    while (true) {
        BufferedImage image = webcam.getImage();
        GrayF32 gray = ConvertBufferedImage.convertFrom(image, (GrayF32) null);
        tracker.process(gray);
        List<PointTrack> tracks = tracker.getActiveTracks(null);
        // Spawn tracks if there are too few
        if (tracks.size() < minimumTracks) {
            tracker.spawnTracks();
            tracks = tracker.getActiveTracks(null);
            minimumTracks = tracks.size() / 2;
        }
        // Draw the tracks
        Graphics2D g2 = image.createGraphics();
        for (PointTrack t : tracks) {
            VisualizeFeatures.drawPoint(g2, (int) t.x, (int) t.y, Color.RED);
        }
        gui.setImageUI(image);
    }
}
Also used : GrayF32(boofcv.struct.image.GrayF32) PointTrack(boofcv.abst.feature.tracker.PointTrack) PkltConfig(boofcv.alg.tracker.klt.PkltConfig) ConfigGeneralDetector(boofcv.abst.feature.detect.interest.ConfigGeneralDetector) Webcam(com.github.sarxos.webcam.Webcam) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) ImagePanel(boofcv.gui.image.ImagePanel)

Aggregations

GrayF32 (boofcv.struct.image.GrayF32)530 Test (org.junit.Test)291 BufferedImage (java.awt.image.BufferedImage)81 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)76 GrayU8 (boofcv.struct.image.GrayU8)49 Planar (boofcv.struct.image.Planar)34 ArrayList (java.util.ArrayList)28 ImageBorder_F32 (boofcv.core.image.border.ImageBorder_F32)20 ImageGray (boofcv.struct.image.ImageGray)20 File (java.io.File)20 CameraPinholeRadial (boofcv.struct.calib.CameraPinholeRadial)19 Se3_F64 (georegression.struct.se.Se3_F64)18 TupleDesc_F64 (boofcv.struct.feature.TupleDesc_F64)17 GrayS8 (boofcv.struct.image.GrayS8)16 ListDisplayPanel (boofcv.gui.ListDisplayPanel)14 PathLabel (boofcv.io.PathLabel)14 Kernel2D_F32 (boofcv.struct.convolve.Kernel2D_F32)13 GrayS16 (boofcv.struct.image.GrayS16)13 GrayS32 (boofcv.struct.image.GrayS32)13 Point2D_F64 (georegression.struct.point.Point2D_F64)13