Example usage for org.opencv.videoio VideoCapture VideoCapture

List of usage examples for org.opencv.videoio VideoCapture VideoCapture

Introduction

In this page you can find the example usage for org.opencv.videoio VideoCapture VideoCapture.

Prototype

public VideoCapture(int index) 

Source Link

Usage

From source file:bitirme.arayuz.KullaniciOlustur.java

private void baslatBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_baslatBtnActionPerformed

    kamera = new VideoCapture(0);
    //sistemdeki kameralar 0,1,2

    th = new CanliThread();
    Thread t = new Thread(th);
    t.setDaemon(true);//from w  w w.  java2  s . co m
    //threadi altr
    th.calismaDurumu = true;

    t.start();
    //     baslatBtn.setEnabled(false);  //start button
    //     duraklatBtn.setEnabled(true);  // stop button
}

From source file:camviewer.VideoThread.java

public VideoThread(String url, JPanel p) {
    webSource = new VideoCapture(url);
    panel = p;
}

From source file:com.armeniopinto.stress.control.vision.VisionConfig.java

@Bean(name = "visionDevice", destroyMethod = "release")
public VideoCapture videoCapture() throws VisionException {
    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
    LOGGER.debug("OpenCV native library loaded.");

    final VideoCapture device = new VideoCapture(deviceId) {
        @Override/*from   w  w w.  ja  v  a 2s  . c om*/
        public void release() {
            super.release();
            LOGGER.debug("Vision device stopped.");
        }
    };
    device.set(CAP_PROP_FRAME_WIDTH, width);
    device.set(CAP_PROP_FRAME_HEIGHT, height);
    try {
        TimeUnit.MICROSECONDS.sleep(2000L);
    } catch (final InterruptedException ie) {
        LOGGER.warn("Failed to sleep!", ie);
    }
    if (!device.isOpened()) {
        throw new VisionException("Unable to open the camera.");
    }

    final int actualWidth = (int) device.get(CAP_PROP_FRAME_WIDTH);
    final int actualHeight = (int) device.get(CAP_PROP_FRAME_HEIGHT);
    if (actualWidth != width) {
        LOGGER.warn(String.format("Requested frame width %d but got %d instead.", width, actualWidth));
    }
    if (actualHeight != height) {
        LOGGER.warn(String.format("Requested frame height %d but got %d instead.", height, actualHeight));
    }

    LOGGER.debug(String.format("Vision device %d started at %dx%d.", deviceId, actualWidth, actualHeight));

    return device;
}

From source file:com.arvin.facedetect.FaceDetect.java

private void start() {

    cap = new VideoCapture(0);
    thread = new thread();
    Thread t = new Thread(thread);
    t.setDaemon(true);//from   w w w.ja v  a 2 s.  co  m
    t.start();

}

From source file:com.example.afs.makingmusic.process.CameraReader.java

License:Open Source License

public CameraReader(long intervalMillis) {
    super(intervalMillis);
    this.camera = new VideoCapture(0);
}

From source file:com.example.afs.makingmusic.process.CameraReader.java

License:Open Source License

@Override
public Frame process() throws InterruptedException {
    Mat image = new Mat();
    while (!camera.read(image)) {
        System.err.println("Cannot read image. Is the camera plugged in?");
        sleep(100);//from w  ww .  j  a  v a 2  s.  com
        camera.release();
        camera = new VideoCapture(0);
    }
    Injector.getMetrics().setFrames(++frameCount);
    return new Frame(image);
}

From source file:com.jeremydyer.nifi.GetCameraFrame.java

License:Apache License

@Override
protected void init(final ProcessorInitializationContext context) {
    final List<PropertyDescriptor> descriptors = new ArrayList<PropertyDescriptor>();
    //descriptors.add(CAMERA);
    descriptors.add(FRAME_WIDTH);/*from   www. j ava 2 s  .c om*/
    descriptors.add(FRAME_HEIGHT);

    this.descriptors = Collections.unmodifiableList(descriptors);

    final Set<Relationship> relationships = new HashSet<Relationship>();
    relationships.add(REL_SUCCESS);
    this.relationships = Collections.unmodifiableSet(relationships);

    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
    camera = new VideoCapture(CAMERA_ID);
    try {
        Thread.sleep(2000); //Give the Camera a few seconds to initialize
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    camera.open(CAMERA_ID);

    if (!camera.isOpened()) {
        getLogger().error("Camera Error");
    } else {
        getLogger().error("Camera OK?");
    }

}

From source file:com.randhirkumar.webcam.MainFrameForm.java

public void displayScreen() {

    Mat webcamImage = new Mat();
    VideoCapture videoCapture = new VideoCapture(0);

    if (videoCapture.isOpened()) {

        while (true) {

            videoCapture.read(webcamImage);

            if (!webcamImage.empty()) {
                setSize(webcamImage.width() + 50, webcamImage.height() + 70);
                webcamImage = processor.detect(webcamImage);
                cameraPanel.convertMatToImage(webcamImage);
                cameraPanel.repaint();//from  w  w w  .  ja  va  2 s. c o m
            } else {
                System.out.println("Problem");
                break;
            }
        }
    }
}

From source file:ConfOpenCV_Java.ConfOpenCV_Java.java

/**
 * @param args the command line arguments
 *//*from www  . j a  v  a 2 s  .  com*/
public static void main(String[] args) {

    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
    System.out.println("Welcome to OpenCV " + Core.VERSION);
    String outputFile = "mivideo.avi";
    VideoCapture vc = new VideoCapture(0);
    System.out.println("fps= " + Videoio.CAP_PROP_FPS);

    //vc.set(5, 50);
    //System.out.println(vc.set(3, 1280));
    //vc.set(4, 720);
    double fps = 30;
    System.out.println(fps);

    Size frameSize = new Size((int) vc.get(Videoio.CV_CAP_PROP_FRAME_WIDTH),
            (int) vc.get(Videoio.CV_CAP_PROP_FRAME_HEIGHT));
    System.out.println(frameSize);

    VideoWriter vw = new VideoWriter(outputFile, VideoWriter.fourcc('X', '2', '6', '4'), fps, frameSize, true);
    //System.out.println(VideoWriter.fourcc('X', '2', '6', '4'));
    //System.out.println(vw.isOpened());
    Mat frame = new Mat();

    //para cargar fotos
    //Imgcodecs.imread(outputFile)
    //Imgcodecs.imwrite(outputFile, m);
    int numFramesRemaining = 5 * (int) fps;

    NewJFrame ventana = new NewJFrame();
    ventana.setVisible(true);
    g = ventana.getjPanel1().getGraphics();
    ventana.pack();
    ventana.setVisible(true);

    while (vc.read(frame) && numFramesRemaining > 0) {
        vw.write(frame);
        mostrarImagen(frame);
        numFramesRemaining--;
    }

    vw.release();
    vc.release();
    ventana.dispose();

}

From source file:edu.wpi.first.wpilibj.vision.GripRunner.java

License:Open Source License

/**
 * Make a connection to a camera.//from www.  j ava  2s.  co  m
 * 
 * @param device  Camera number.
 * @param width  Window width in pixels.
 * @param height Window height in pixels.
 * @param exposure Relative exposure.
 * @return
 */
public static VideoCapture makeCamera(int device, int width, int height, double exposure) {
    VideoCapture camera = new VideoCapture(0);
    camera.set(Videoio.CAP_PROP_FRAME_WIDTH, width);
    camera.set(Videoio.CAP_PROP_FRAME_HEIGHT, height);
    if (exposure > -1.0) {
        System.out.println("\t" + exposure);
        camera.set(Videoio.CAP_PROP_AUTO_EXPOSURE, 0);
        camera.set(Videoio.CAP_PROP_EXPOSURE, exposure);
    }
    if (!camera.isOpened()) {
        throw new RuntimeException("Camera will not open");
    }
    return camera;
}