Search in sources :

Example 6 with Webcam

use of com.github.sarxos.webcam.Webcam in project narchy by automenta.

the class RasterHierarchy method process.

/**
 * Invoke to start the main processing loop.
 */
public void process() {
    Webcam webcam = UtilWebcamCapture.openDefault(frameWidth, frameHeight);
    // adjust the window size and let the GUI know it has changed
    Dimension actualSize = webcam.getViewSize();
    setPreferredSize(actualSize);
    setMinimumSize(actualSize);
    window.setMinimumSize(actualSize);
    window.setPreferredSize(actualSize);
    window.setVisible(true);
    BufferedImage input;
    while (running) {
        /*
                 * Uncomment this section to scan the focal point across the frame
                 * automatically - just for demo purposes.
                 */
        /*
                int xx = this.focusPoint.getX();
                int yy = this.focusPoint.getY();
                xx += 1;

                if(xx > frameWidth)
                {
                    xx = 0;
                    yy += 1;
                    if (yy > frameHeight)
                        yy = 0;
                }

                this.setFocus(xx, yy);
                */
        input = webcam.getImage();
        // synchronized (workImage) {
        // copy the latest image into the work buffer
        // Graphics2D g2 = workImage.createGraphics();
        buffered = this.rasterizeImage(input);
        // }
        repaint();
    }
}
Also used : Webcam(com.github.sarxos.webcam.Webcam) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.core.image.ConvertBufferedImage)

Example 7 with Webcam

use of com.github.sarxos.webcam.Webcam in project narchy by automenta.

the class WebcamTrack 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<ImageFloat32> tracker = FactoryPointTracker.klt(configKlt, configDetector, ImageFloat32.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
    ImagePanel gui = new ImagePanel();
    gui.setPreferredSize(webcam.getViewSize());
    ShowImages.showWindow(gui, "KLT Tracker");
    int minimumTracks = 100;
    while (true) {
        BufferedImage image = webcam.getImage();
        ImageFloat32 gray = ConvertBufferedImage.convertFrom(image, (ImageFloat32) 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.setBufferedImageSafe(image);
    }
}
Also used : PointTrack(boofcv.abst.feature.tracker.PointTrack) ImageFloat32(boofcv.struct.image.ImageFloat32) 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.core.image.ConvertBufferedImage) ImagePanel(boofcv.gui.image.ImagePanel)

Example 8 with Webcam

use of com.github.sarxos.webcam.Webcam in project BoofCV by lessthanoptimal.

the class ExampleCollectImages method main.

public static void main(String[] args) {
    // Open a webcam at a resolution close to 640x480
    Webcam webcam = Webcam.getWebcams().get(0);
    UtilWebcamCapture.adjustResolution(webcam, 640, 480);
    webcam.open();
    // Create the panel used to display the image
    ImagePanel gui = new ImagePanel();
    gui.setPreferredSize(webcam.getViewSize());
    gui.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            saveImage = true;
        }
    });
    ShowImages.showWindow(gui, "Webcam", true);
    int total = 0;
    while (true) {
        BufferedImage image = webcam.getImage();
        if (saveImage) {
            System.out.println("Saving image " + total);
            saveImage = false;
            UtilImageIO.saveImage(image, String.format("image%04d.png", (total++)));
        }
        gui.setImageUI(image);
    }
}
Also used : MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter) Webcam(com.github.sarxos.webcam.Webcam) BufferedImage(java.awt.image.BufferedImage) ImagePanel(boofcv.gui.image.ImagePanel)

Example 9 with Webcam

use of com.github.sarxos.webcam.Webcam in project BoofCV by lessthanoptimal.

the class UtilWebcamCapture method openDefault.

/**
 * Opens the default camera while adjusting its resolution
 */
public static Webcam openDefault(int desiredWidth, int desiredHeight) {
    Webcam webcam = Webcam.getDefault();
    // Webcam doesn't list all available resolutions. Just pass in a custom
    // resolution and hope it works
    adjustResolution(webcam, desiredWidth, desiredHeight);
    webcam.open();
    return webcam;
}
Also used : Webcam(com.github.sarxos.webcam.Webcam)

Example 10 with Webcam

use of com.github.sarxos.webcam.Webcam in project BoofCV by lessthanoptimal.

the class UtilWebcamCapture method openDevice.

/**
 * Searches for the first device which matches the pattern.  Webcam capture doesn't name devices
 * using the standard "/dev/video0" scheme, but it includes that in its name.
 *
 * @param deviceName Partial or complete name of the device you wish to pen
 * @return The webcam it found
 */
public static Webcam openDevice(String deviceName, int desiredWidth, int desiredHeight) {
    Webcam webcam = findDevice(deviceName);
    if (webcam == null)
        throw new IllegalArgumentException("Can't find camera " + deviceName);
    adjustResolution(webcam, desiredWidth, desiredHeight);
    webcam.open();
    return webcam;
}
Also used : Webcam(com.github.sarxos.webcam.Webcam)

Aggregations

Webcam (com.github.sarxos.webcam.Webcam)13 BufferedImage (java.awt.image.BufferedImage)9 ImagePanel (boofcv.gui.image.ImagePanel)4 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)4 ConvertBufferedImage (boofcv.core.image.ConvertBufferedImage)3 GrayF32 (boofcv.struct.image.GrayF32)3 ConfigGeneralDetector (boofcv.abst.feature.detect.interest.ConfigGeneralDetector)2 PointTrack (boofcv.abst.feature.tracker.PointTrack)2 PkltConfig (boofcv.alg.tracker.klt.PkltConfig)2 Rectangle2D_F64 (georegression.struct.shapes.Rectangle2D_F64)2 AssistedCalibration (boofcv.app.calib.AssistedCalibration)1 AssistedCalibrationGui (boofcv.app.calib.AssistedCalibrationGui)1 ComputeGeometryScore (boofcv.app.calib.ComputeGeometryScore)1 ProgressMonitorThread (boofcv.io.ProgressMonitorThread)1 ImageFloat32 (boofcv.struct.image.ImageFloat32)1 MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1 File (java.io.File)1 Preferences (java.util.prefs.Preferences)1