OpenCV 2.4.4 Java - 抓取网络摄像头图片/流(OSX) [英] OpenCV 2.4.4 Java - Grab Webcam picture/stream (OSX)

查看:113
本文介绍了OpenCV 2.4.4 Java - 抓取网络摄像头图片/流(OSX)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Stackoverflow和OpenCV编程领域的新手。
我用OpenCV Bindings for Java(opencv.org官员,而不是JavaCV)制作了一些项目,比如通过ORB和SURF功能进行对象识别,处理图像。一切还好。
现在我正在转向视频流中的对象识别。我想从网络摄像头抓取流并应用对象识别。
我不是Java大师,所以我在OpenCV中找到了VideoCapture类,但是我无法从相机中获取图片。

I'm new in the world of Stackoverflow and in OpenCV programming. I've made some projects with OpenCV Bindings for Java (the opencv.org officials, not JavaCV), like object recognition through ORB and SURF features, working with images. Everything ok. Now I'm moving to object recognition in video streams. I want to grab stream from webcam and apply object recognition. I'm not a Java guru, so I found in OpenCV the VideoCapture class, but I'm not able to obtain pictures from the camera.

I在OSX Mountain Lion中使用OpenCV 2.4.4绑定在Eclipse中运行我的项目。

I'm running my project in Eclipse with OpenCV 2.4.4 bindings, in OSX Mountain Lion.

控制台中的结果:

Hello, OpenCV
Camera OK?
Frame Obtained
Captured Frame Width 0
Invalid memory access of location 0x7fae00000000 rip=0x7fff8b4c5263

代码:

import org.opencv.core.Mat;
import org.opencv.highgui.Highgui;
import org.opencv.highgui.VideoCapture;

public class Webcam {

    public static void main (String args[]){

    System.out.println("Hello, OpenCV");
    // Load the native library.
    System.loadLibrary("opencv_java244");

    VideoCapture camera = new VideoCapture(0);
    camera.open(0); //Useless
    if(!camera.isOpened()){
        System.out.println("Camera Error");
    }
    else{
        System.out.println("Camera OK?");
    }

    Mat frame = new Mat();

    //camera.grab();
    //System.out.println("Frame Grabbed");
    //camera.retrieve(frame);
    //System.out.println("Frame Decoded");

    camera.read(frame);
    System.out.println("Frame Obtained");

    /* No difference
    camera.release();
    */

    System.out.println("Captured Frame Width " + frame.width());

    Highgui.imwrite("camera.jpg", frame);
    System.out.println("OK");
    }
}


推荐答案

问题只是相机需要时间来初始化。我添加了

The problem was simply that camera need time to initialize. I've added

Thread.sleep(1000);

VideoCapture camera = new VideoCapture(0);

这篇关于OpenCV 2.4.4 Java - 抓取网络摄像头图片/流(OSX)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆