use of boofcv.struct.image.Planar 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);
}
}
use of boofcv.struct.image.Planar in project BoofCV by lessthanoptimal.
the class ExampleWebcamObjectTracking method main.
public static void main(String[] args) {
ImageType<Planar<GrayU8>> colorType = ImageType.pl(3, GrayU8.class);
TrackerObjectQuad tracker = FactoryTrackerObjectQuad.circulant(null, GrayU8.class);
// FactoryTrackerObjectQuad.sparseFlow(null,GrayU8.class,null);
// FactoryTrackerObjectQuad.tld(null,GrayU8.class);
// FactoryTrackerObjectQuad.meanShiftComaniciu2003(new ConfigComaniciu2003(), colorType);
// FactoryTrackerObjectQuad.meanShiftComaniciu2003(new ConfigComaniciu2003(true),colorType);
// FactoryTrackerObjectQuad.meanShiftLikelihood(30,5,255, MeanShiftLikelihoodType.HISTOGRAM,colorType);
ExampleWebcamObjectTracking app = new ExampleWebcamObjectTracking(tracker, 640, 480);
app.process();
}
use of boofcv.struct.image.Planar in project BoofCV by lessthanoptimal.
the class ExampleImageBlur method main.
public static void main(String[] args) {
ListDisplayPanel panel = new ListDisplayPanel();
BufferedImage buffered = UtilImageIO.loadImage(UtilIO.pathExample("sunflowers.jpg"));
panel.addImage(buffered, "Original");
Planar<GrayU8> input = ConvertBufferedImage.convertFrom(buffered, true, ImageType.pl(3, GrayU8.class));
Planar<GrayU8> blurred = input.createSameShape();
// size of the blur kernel. square region with a width of radius*2 + 1
int radius = 8;
// Apply gaussian blur using a procedural interface
GBlurImageOps.gaussian(input, blurred, -1, radius, null);
panel.addImage(ConvertBufferedImage.convertTo(blurred, null, true), "Gaussian");
// Apply a mean filter using an object oriented interface. This has the advantage of automatically
// recycling memory used in intermediate steps
BlurFilter<Planar<GrayU8>> filterMean = FactoryBlurFilter.mean(input.getImageType(), radius);
filterMean.process(input, blurred);
panel.addImage(ConvertBufferedImage.convertTo(blurred, null, true), "Mean");
// Apply a median filter using image type specific procedural interface. Won't work if the type
// isn't known at compile time
BlurImageOps.median(input, blurred, radius);
panel.addImage(ConvertBufferedImage.convertTo(blurred, null, true), "Median");
ShowImages.showWindow(panel, "Image Blur Examples", true);
}
use of boofcv.struct.image.Planar in project BoofCV by lessthanoptimal.
the class ExamplePointDeformKeyPoints method main.
public static void main(String[] args) {
BufferedImage orig = UtilImageIO.loadImage(UtilIO.pathExample("standard/man_mls.jpg"));
BufferedImage bufferedOut = new BufferedImage(orig.getWidth(), orig.getHeight(), BufferedImage.TYPE_INT_RGB);
Planar<GrayF32> input = ConvertBufferedImage.convertFrom(orig, true, ImageType.pl(3, GrayF32.class));
Planar<GrayF32> output = input.createSameShape();
List<Point2D_F32> src = new ArrayList<>();
List<Point2D_F32> dst = new ArrayList<>();
src.add(new Point2D_F32(64, 241));
src.add(new Point2D_F32(266, 119));
src.add(new Point2D_F32(265, 240));
src.add(new Point2D_F32(208, 410));
src.add(new Point2D_F32(181, 536));
src.add(new Point2D_F32(335, 409));
src.add(new Point2D_F32(375, 531));
src.add(new Point2D_F32(473, 238));
for (Point2D_F32 p : src) {
dst.add(p.copy());
}
ConfigDeformPointMLS config = new ConfigDeformPointMLS();
PointDeformKeyPoints deform = FactoryDistort.deformMls(config);
deform.setImageShape(input.width, input.height);
ImageDistort<Planar<GrayF32>, Planar<GrayF32>> distorter = FactoryDistort.distort(true, InterpolationType.BILINEAR, BorderType.ZERO, input.getImageType(), input.getImageType());
deform.setImageShape(input.width, input.height);
deform.setSource(src);
deform.setDestination(dst);
ConvertBufferedImage.convertTo(output, bufferedOut, true);
ImagePanel panel = ShowImages.showWindow(bufferedOut, "Point Based Distortion Animation", true);
int count = 0;
while (true) {
// specify new locations of key points
double theta = count++ * Math.PI / 30;
// right arm
dst.get(7).y = (float) (238 + Math.sin(theta) * 30);
// left arm
dst.get(0).y = (float) (241 - Math.sin(theta * 2.0) * 20);
// head
dst.get(1).x = (float) (266 + Math.sin(theta * 0.25) * 10);
// tell the deformation algorithm that destination points have changed
deform.setDestination(dst);
// Tell the distorter that the model has changed. If cached is set to false you can ignore this step
distorter.setModel(new PointToPixelTransform_F32(deform));
// distort the image
distorter.apply(input, output);
// Show the results
ConvertBufferedImage.convertTo(output, bufferedOut, true);
panel.repaint();
BoofMiscOps.sleep(30);
}
}
use of boofcv.struct.image.Planar in project BoofCV by lessthanoptimal.
the class TestImplConvertBitmap method checkBitmapToPlanarRGB.
public void checkBitmapToPlanarRGB(Method m, Bitmap.Config config) {
Bitmap orig = Bitmap.createBitmap(w, h, config);
orig.setPixel(1, 2, 0xFF204010);
Class[] params = m.getParameterTypes();
String info = config + " " + m.getName();
try {
int numBands = Bitmap.Config.ARGB_8888 == config ? 4 : 3;
Class msType = m.getName().contains("U8") ? GrayU8.class : GrayF32.class;
Planar found = new Planar(msType, w, h, numBands);
m.invoke(null, orig, found);
assertEquals(0x20, (int) GeneralizedImageOps.get(found.getBand(0), 1, 2));
assertEquals(0x40, (int) GeneralizedImageOps.get(found.getBand(1), 1, 2));
assertEquals(0x10, (int) GeneralizedImageOps.get(found.getBand(2), 1, 2));
if (numBands == 4)
assertEquals(0xFF, (int) GeneralizedImageOps.get(found.getBand(3), 1, 2));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Aggregations