cvCreateFileCapture() Error: Could not create camera capture with JavaCV

社会主义新天地 提交于 2019-12-11 03:03:43

问题


At this moment I worked on recognition forms. It's perfect with camera of my computer, but now I would like test with a camera on network. I use JavaCV (OpenCV apply to Java).

This is my code:

public static void main(String[] args) throws Exception {

    OpenCVFrameGrabber grabber = new OpenCVFrameGrabber("http://192.168.1.210:5500/snapshot.cgi?user=admin&pwd=123456"); 
    grabber.setFormat("mjpeg");
    grabber.start();
    for (int k=0; k<20000; k++){
        System.out.print(k);
    }
    IplImage frame = grabber.grab();
    CanvasFrame canvasFrame = new CanvasFrame("Camera");
    canvasFrame.setCanvasSize(frame.width(), frame.height());
    while (canvasFrame.isVisible() && (frame = grabber.grab()) != null) {
        canvasFrame.showImage(frame);
    }
    grabber.stop();
    canvasFrame.dispose();
    System.exit(0);
}

And i have a error but i don't understand.

Exception in thread "main" com.googlecode.javacv.FrameGrabber$Exception: cvCreateFileCapture() Error: Could not create camera capture. at com.googlecode.javacv.OpenCVFrameGrabber.start(OpenCVFrameGrabber.java:171) at Test.FrameRecorderTest.main(FrameRecorderTest.java:12) warning: Could not find codec parameters (../../modules/highgui/src/cap_ffmpeg_impl.hpp:375)

in starting i thought it was my address for take my picture of camera but i tested in Mozilla/IE and i can have the image. So i think the address is OK. And if i change my adress by a video it's ok. I think... Maybe it's because i take picture of my camera and not a video.. i think... If it's this how i can choose between video and picture ?


UPDATE: I now changed my method and now it's ok. I think that it was because I took a picture with a code for a video.

package Test;

import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import javax.imageio.ImageIO;
import com.googlecode.javacv.CanvasFrame;
public class TestconnectionCamera {

    /**
     * @param args
     * @throws IOException 
     */
    public static void main(String[] args) throws IOException {
        CanvasFrame CamWindow = new CanvasFrame("Camera");

        String Cam1Jpeg_url = "http://192.168.1.210:5500/snapshot.cgi?user=admin&pwd=123456";
        URL url = new URL(Cam1Jpeg_url);

        while(true){
        InputStream is = url.openStream();
        BufferedImage image = ImageIO.read(is);
        CamWindow.showImage(image);
        is.close();
        }
    }
}

来源:https://stackoverflow.com/questions/14251290/cvcreatefilecapture-error-could-not-create-camera-capture-with-javacv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!