use of boofcv.gui.image.ImagePanel in project BoofCV by lessthanoptimal.
the class RemoveLensDistortionApp method addUndistorted.
private void addUndistorted(final String name, final Point2Transform2_F32 model) {
// Set up image distort
InterpolatePixel<T> interp = FactoryInterpolation.createPixel(0, 255, InterpolationType.BILINEAR, BorderType.ZERO, undist.getImageType());
ImageDistort<T, T> undistorter = FactoryDistort.distort(false, interp, undist.getImageType());
undistorter.setModel(new PointToPixelTransform_F32(model));
undistorter.apply(dist, undist);
final BufferedImage out = ConvertBufferedImage.convertTo(undist, null, true);
// Add this rectified image
SwingUtilities.invokeLater(new Runnable() {
public void run() {
gui.addItem(new ImagePanel(out), name);
}
});
}
use of boofcv.gui.image.ImagePanel 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);
}
}
use of boofcv.gui.image.ImagePanel in project BoofCV by lessthanoptimal.
the class ExampleWebcamGradient method main.
public static void main(String[] args) {
// Open a webcam at a resolution close to 640x480
Webcam webcam = UtilWebcamCapture.openDefault(640, 480);
// Create the panel used to display the image and
ImagePanel gui = new ImagePanel();
Dimension viewSize = webcam.getViewSize();
gui.setPreferredSize(viewSize);
// Predeclare storage for the gradient
GrayF32 derivX = new GrayF32((int) viewSize.getWidth(), (int) viewSize.getHeight());
GrayF32 derivY = new GrayF32((int) viewSize.getWidth(), (int) viewSize.getHeight());
ShowImages.showWindow(gui, "Gradient", true);
for (; ; ) {
BufferedImage image = webcam.getImage();
GrayF32 gray = ConvertBufferedImage.convertFrom(image, (GrayF32) null);
// compute the gradient
GImageDerivativeOps.gradient(DerivativeType.SOBEL, gray, derivX, derivY, BorderType.EXTENDED);
// visualize and display
BufferedImage visualized = VisualizeImageData.colorizeGradient(derivX, derivY, -1);
gui.setImageUI(visualized);
}
}
use of boofcv.gui.image.ImagePanel 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.gui.image.ImagePanel in project BoofCV by lessthanoptimal.
the class ExampleRemoveLensDistortion method displayResults.
/**
* Displays results in a window for easy comparison..
*/
private static void displayResults(BufferedImage orig, Planar<GrayF32> distortedImg, ImageDistort allInside, ImageDistort fullView) {
// render the results
Planar<GrayF32> undistortedImg = new Planar<>(GrayF32.class, distortedImg.getWidth(), distortedImg.getHeight(), distortedImg.getNumBands());
allInside.apply(distortedImg, undistortedImg);
BufferedImage out1 = ConvertBufferedImage.convertTo(undistortedImg, null, true);
fullView.apply(distortedImg, undistortedImg);
BufferedImage out2 = ConvertBufferedImage.convertTo(undistortedImg, null, true);
// display in a single window where the user can easily switch between images
ListDisplayPanel panel = new ListDisplayPanel();
panel.addItem(new ImagePanel(orig), "Original");
panel.addItem(new ImagePanel(out1), "Undistorted All Inside");
panel.addItem(new ImagePanel(out2), "Undistorted Full View");
ShowImages.showWindow(panel, "Removing Lens Distortion", true);
}
Aggregations