Search in sources :

Example 11 with Webcam

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

the class WebcamCaptureWebcamInterface method open.

@Override
public <T extends ImageBase<T>> SimpleImageSequence<T> open(String device, int width, int height, ImageType<T> imageType) {
    if (device != null) {
        Webcam webcam;
        try {
            int which = Integer.parseInt(device);
            webcam = Webcam.getWebcams().get(which);
        } catch (NumberFormatException ignore) {
            webcam = UtilWebcamCapture.findDevice(device);
        }
        if (webcam == null) {
            throw new RuntimeException("Can't find webcam with ID or name at " + device);
        }
        try {
            if (width >= 0 && height >= 0) {
                UtilWebcamCapture.adjustResolution(webcam, width, height);
            }
            webcam.open();
            return new SimpleSequence<>(webcam, imageType);
        } catch (RuntimeException ignore) {
        }
    }
    return new SimpleSequence<>(device, width, height, imageType);
}
Also used : Webcam(com.github.sarxos.webcam.Webcam)

Example 12 with Webcam

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

the class WebcamObjectTrack method process.

/**
 * Invoke to start the main processing loop.
 */
public void process() {
    Webcam webcam = UtilWebcamCapture.openDefault(desiredWidth, desiredHeight);
    // 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);
    // create
    T input = tracker.getImageType().createImage(actualSize.width, actualSize.height);
    workImage = new BufferedImage(input.getWidth(), input.getHeight(), BufferedImage.TYPE_INT_RGB);
    ImageFloat32 inputFloat = new ImageFloat32(actualSize.width, actualSize.height);
    while (true) {
        BufferedImage buffered = webcam.getImage();
        ConvertBufferedImage.convertFrom(webcam.getImage(), input, true);
        // mode is read/written to by the GUI also
        int mode = this.mode;
        boolean success = false;
        if (mode == 2) {
            Rectangle2D_F64 rect = new Rectangle2D_F64();
            rect.set(point0.x, point0.y, point1.x, point1.y);
            UtilPolygons2D_F64.convert(rect, target);
            success = tracker.initialize(input, target);
            this.mode = success ? 3 : 0;
        } else if (mode == 3) {
            success = tracker.process(input, target);
        }
        synchronized (workImage) {
            // copy the latest image into the work buffered
            Graphics2D g2 = workImage.createGraphics();
            g2.drawImage(buffered, 0, 0, null);
            ConvertBufferedImage.convertFrom(buffered, inputFloat);
            fitCannyBinary(inputFloat, g2);
            // visualize the current results
            if (mode == 1) {
                drawSelected(g2);
            } else if (mode == 3) {
                if (success) {
                    drawTrack(g2);
                }
            }
        }
        repaint();
    }
}
Also used : Rectangle2D_F64(georegression.struct.shapes.Rectangle2D_F64) Webcam(com.github.sarxos.webcam.Webcam) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.core.image.ConvertBufferedImage)

Example 13 with Webcam

use of com.github.sarxos.webcam.Webcam in project opennars by opennars.

the class RasterHierachy 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, buffered;
    workImage = new BufferedImage(actualSize.width, actualSize.height, BufferedImage.TYPE_INT_RGB);
    while (true) {
        /*
                 * 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);
            g2.drawImage(buffered, 0, 0, null);
        }
        repaint();
    }
}
Also used : Webcam(com.github.sarxos.webcam.Webcam) BufferedImage(java.awt.image.BufferedImage)

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