Search in sources :

Example 61 with Planar

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

the class TestTrackerMeanShiftComaniciu2003 method updateLocation.

@Test
public void updateLocation() {
    InterpolatePixelS interpSB = FactoryInterpolation.bilinearPixelS(GrayF32.class, BorderType.EXTENDED);
    InterpolatePixelMB interpolate = FactoryInterpolation.createPixelPL(interpSB);
    LocalWeightedHistogramRotRect calcHistogram = new LocalWeightedHistogramRotRect(30, 3, 10, 3, 255, interpolate);
    TrackerMeanShiftComaniciu2003 alg = new TrackerMeanShiftComaniciu2003(false, 100, 1e-8f, 0.1f, 0.0f, 0.1f, calcHistogram);
    Planar<GrayF32> image = new Planar<>(GrayF32.class, 100, 150, 3);
    // odd width and height so samples land on pixels
    render(image, 50, 40, 21, 31);
    RectangleRotate_F32 found = new RectangleRotate_F32(50, 40, 21, 31, 0);
    alg.initialize(image, found);
    // test no change
    alg.updateLocation(image, found);
    check(found, 50, 40, 21, 31, 0);
    // test translation
    render(image, 55, 34, 21, 31);
    alg.updateLocation(image, found);
    check(found, 55, 34, 21, 31, 0);
}
Also used : InterpolatePixelS(boofcv.alg.interpolate.InterpolatePixelS) GrayF32(boofcv.struct.image.GrayF32) RectangleRotate_F32(boofcv.struct.RectangleRotate_F32) InterpolatePixelMB(boofcv.alg.interpolate.InterpolatePixelMB) Planar(boofcv.struct.image.Planar) Test(org.junit.Test)

Example 62 with Planar

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

the class ExampleColorHistogramLookup method independentHueSat.

/**
 * Computes two independent 1D histograms from hue and saturation.  Less affects by sparsity, but can produce
 * worse results since the basic assumption that hue and saturation are decoupled is most of the time false.
 */
public static List<double[]> independentHueSat(List<File> images) {
    List<double[]> points = new ArrayList<>();
    // The number of bins is an important parameter.  Try adjusting it
    TupleDesc_F64 histogramHue = new TupleDesc_F64(30);
    TupleDesc_F64 histogramValue = new TupleDesc_F64(30);
    List<TupleDesc_F64> histogramList = new ArrayList<>();
    histogramList.add(histogramHue);
    histogramList.add(histogramValue);
    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);
        GHistogramFeatureOps.histogram(hsv.getBand(0), 0, 2 * Math.PI, histogramHue);
        GHistogramFeatureOps.histogram(hsv.getBand(1), 0, 1, histogramValue);
        // need to combine them into a single descriptor for processing later on
        TupleDesc_F64 imageHist = UtilFeature.combine(histogramList, null);
        // normalize so that image size doesn't matter
        UtilFeature.normalizeL2(imageHist);
        points.add(imageHist.value);
    }
    return points;
}
Also used : GrayF32(boofcv.struct.image.GrayF32) TupleDesc_F64(boofcv.struct.feature.TupleDesc_F64) Planar(boofcv.struct.image.Planar) File(java.io.File) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage)

Example 63 with Planar

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

the class CreateRgbPointCloudFileApp method main.

public static void main(String[] args) throws IOException {
    String baseDir = "log/";
    String nameRgb = baseDir + "rgb0000000.ppm";
    String nameDepth = baseDir + "depth0000000.depth";
    String nameCalib = baseDir + "intrinsic.yaml";
    CameraPinholeRadial param = CalibrationIO.load(nameCalib);
    GrayU16 depth = new GrayU16(1, 1);
    Planar<GrayU8> rgb = new Planar<>(GrayU8.class, 1, 1, 3);
    UtilImageIO.loadPPM_U8(nameRgb, rgb, null);
    UtilOpenKinect.parseDepth(nameDepth, depth, null);
    FastQueue<Point3D_F64> cloud = new FastQueue<Point3D_F64>(Point3D_F64.class, true);
    FastQueueArray_I32 cloudColor = new FastQueueArray_I32(3);
    VisualDepthOps.depthTo3D(param, rgb, depth, cloud, cloudColor);
    DataOutputStream file = new DataOutputStream(new FileOutputStream("kinect_pointcloud.txt"));
    file.write("# Kinect RGB Point cloud. Units: millimeters. Format: X Y Z R G B\n".getBytes());
    for (int i = 0; i < cloud.size; i++) {
        Point3D_F64 p = cloud.get(i);
        int[] color = cloudColor.get(i);
        String line = String.format("%.10f %.10f %.10f %d %d %d\n", p.x, p.y, p.z, color[0], color[1], color[2]);
        file.write(line.getBytes());
    }
    file.close();
    System.out.println("Total points = " + cloud.size);
}
Also used : Point3D_F64(georegression.struct.point.Point3D_F64) GrayU16(boofcv.struct.image.GrayU16) FastQueue(org.ddogleg.struct.FastQueue) DataOutputStream(java.io.DataOutputStream) FastQueueArray_I32(boofcv.struct.FastQueueArray_I32) CameraPinholeRadial(boofcv.struct.calib.CameraPinholeRadial) FileOutputStream(java.io.FileOutputStream) Planar(boofcv.struct.image.Planar) GrayU8(boofcv.struct.image.GrayU8)

Example 64 with Planar

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

the class ExampleTrackerMeanShiftLikelihood method main.

public static void main(String[] args) {
    MediaManager media = DefaultMediaManager.INSTANCE;
    String fileName = UtilIO.pathExample("tracking/balls_blue_red.mjpeg");
    RectangleLength2D_I32 location = new RectangleLength2D_I32(394, 247, 475 - 394, 325 - 247);
    ImageType<Planar<GrayU8>> imageType = ImageType.pl(3, GrayU8.class);
    SimpleImageSequence<Planar<GrayU8>> video = media.openVideo(fileName, imageType);
    // Return a higher likelihood for pixels close to this RGB color
    RgbLikelihood likelihood = new RgbLikelihood(64, 71, 69);
    TrackerMeanShiftLikelihood<Planar<GrayU8>> tracker = new TrackerMeanShiftLikelihood<>(likelihood, 50, 0.1f);
    // specify the target's initial location and initialize with the first frame
    Planar<GrayU8> frame = video.next();
    // Note that the tracker will not automatically invoke RgbLikelihood.createModel() in its initialize function
    tracker.initialize(frame, location);
    // For displaying the results
    TrackerObjectQuadPanel gui = new TrackerObjectQuadPanel(null);
    gui.setPreferredSize(new Dimension(frame.getWidth(), frame.getHeight()));
    gui.setImageUI((BufferedImage) video.getGuiImage());
    gui.setTarget(location, true);
    ShowImages.showWindow(gui, "Tracking Results", true);
    // Track the object across each video frame and display the results
    while (video.hasNext()) {
        frame = video.next();
        boolean visible = tracker.process(frame);
        gui.setImageUI((BufferedImage) video.getGuiImage());
        gui.setTarget(tracker.getLocation(), visible);
        gui.repaint();
        BoofMiscOps.pause(20);
    }
}
Also used : TrackerMeanShiftLikelihood(boofcv.alg.tracker.meanshift.TrackerMeanShiftLikelihood) MediaManager(boofcv.io.MediaManager) DefaultMediaManager(boofcv.io.wrapper.DefaultMediaManager) RectangleLength2D_I32(georegression.struct.shapes.RectangleLength2D_I32) Planar(boofcv.struct.image.Planar) GrayU8(boofcv.struct.image.GrayU8) TrackerObjectQuadPanel(boofcv.gui.tracker.TrackerObjectQuadPanel)

Example 65 with Planar

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

the class TestSegmentMeanShiftSearchColor method compareToGray.

public void compareToGray(boolean fast) {
    Planar<GrayF32> image = new Planar<>(GrayF32.class, 20, 25, 1);
    GImageMiscOps.fillUniform(image, rand, 0, 256);
    ImageType<Planar<GrayF32>> imageType = ImageType.pl(1, GrayF32.class);
    InterpolatePixelMB<Planar<GrayF32>> interpMB = FactoryInterpolation.createPixelMB(0, 255, InterpolationType.BILINEAR, BorderType.EXTENDED, imageType);
    InterpolatePixelS<GrayF32> interpSB = FactoryInterpolation.bilinearPixelS(GrayF32.class, BorderType.EXTENDED);
    SegmentMeanShiftSearchColor<Planar<GrayF32>> algMB = new SegmentMeanShiftSearchColor<>(30, 0.05f, interpMB, 2, 2, 200, fast, imageType);
    SegmentMeanShiftSearchGray<GrayF32> algSB = new SegmentMeanShiftSearchGray<>(30, 0.05f, interpSB, 2, 2, 200, fast);
    algMB.process(image);
    algSB.process(image.getBand(0));
    // there should be a fair number of local peaks due to the image being random
    assertTrue(algMB.getModeLocation().size > 20);
    assertEquals(algMB.getModeColor().size, algSB.getModeColor().size);
    assertEquals(algMB.getModeLocation().size, algSB.getModeLocation().size);
    assertEquals(algMB.getRegionMemberCount().size, algSB.getRegionMemberCount().size);
    for (int i = 0; i < algMB.getModeColor().size; i++) {
        assertEquals(algMB.getModeColor().get(i)[0], algSB.getModeColor().get(i)[0], 1e-4f);
        assertEquals(algMB.getModeLocation().get(i).x, algSB.getModeLocation().get(i).x, 1e-4f);
        assertEquals(algMB.getModeLocation().get(i).y, algSB.getModeLocation().get(i).y, 1e-4f);
        assertEquals(algMB.getRegionMemberCount().get(i), algSB.getRegionMemberCount().get(i));
    }
    GrayS32 segmentMB = algMB.getPixelToRegion();
    GrayS32 segmentSB = algSB.getPixelToRegion();
    for (int y = 0; y < segmentMB.height; y++) {
        for (int x = 0; x < segmentMB.width; x++) {
            assertEquals(segmentMB.get(x, y), segmentSB.get(x, y));
        }
    }
}
Also used : GrayF32(boofcv.struct.image.GrayF32) Planar(boofcv.struct.image.Planar) GrayS32(boofcv.struct.image.GrayS32)

Aggregations

Planar (boofcv.struct.image.Planar)73 Test (org.junit.Test)39 GrayF32 (boofcv.struct.image.GrayF32)34 GrayU8 (boofcv.struct.image.GrayU8)28 BufferedImage (java.awt.image.BufferedImage)21 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)20 RectangleLength2D_I32 (georegression.struct.shapes.RectangleLength2D_I32)12 File (java.io.File)9 Bitmap (android.graphics.Bitmap)4 ListDisplayPanel (boofcv.gui.ListDisplayPanel)4 ImageGray (boofcv.struct.image.ImageGray)4 ConfigGeneralDetector (boofcv.abst.feature.detect.interest.ConfigGeneralDetector)3 LensDistortionUniversalOmni (boofcv.alg.distort.universal.LensDistortionUniversalOmni)3 MediaManager (boofcv.io.MediaManager)3 DefaultMediaManager (boofcv.io.wrapper.DefaultMediaManager)3 CameraPinhole (boofcv.struct.calib.CameraPinhole)3 GrayU16 (boofcv.struct.image.GrayU16)3 Homography2D_F64 (georegression.struct.homography.Homography2D_F64)3 Se3_F64 (georegression.struct.se.Se3_F64)3 DescribeRegionPoint (boofcv.abst.feature.describe.DescribeRegionPoint)2