2
    import org.opencv.core.Core;        
    import org.opencv.core.Mat;        
    import org.opencv.core.Size;        
    import org.opencv.highgui.Highgui;        
    import org.opencv.highgui.VideoCapture;        
    import org.opencv.imgproc.Imgproc;        

    public class Video        
    {        
        public static void main(String[] args)        
        {        
            System.loadLibrary(Core.NATIVE_LIBRARY_NAME);        

    VideoCapture cap = new VideoCapture(0);

    cap.open(1);

    if(!cap.isOpened())
    {
        System.out.println("No camera");
    }

    else
    {
        System.out.println("Yes. Camera");
    }

    Mat frame = new Mat();
    cap.retrieve(frame);

    Highgui.imwrite("me1.jpg", frame);
    Mat frameBlur = new Mat();

    Imgproc.blur(frame, frameBlur, new Size(5,5));
    Highgui.imwrite("me2-blurred.jpg", frameBlur);

    Imgproc.GaussianBlur(frame, frameBlur, new Size(25, 25), 20);
    Highgui.imwrite("me3-blurred.jpg", frameBlur);

    cap.release();
        }
    }

我已使用此代码打开我的相机设备并捕获 3 个不同的帧并对其进行了一些操作。但是,我无法使用 VideoCapture 的 {n_open} 方法打开像 .avi/.mpg/.mp4 等文件。这里的 VideoCapture 实现中有一个方法。但是因为它是一个私有的本地方法,所以不能使用 VideoCapture 的对象访问该方法。

有人可以帮助如何使用纯 OpenCV 2.4.6 和 Java 做到这一点
(请不要建议使用处理库的解决方案)

4

2 回答 2

2

看看 OpenCV 2.4.8。API已VideoCapture扩展public VideoCapture(String filename)方法。问题仍然是为什么这么晚才实施此功能。

如果由于某种原因您不能使用最新版本的 OpenCV,您有以下几种选择:

  • 使用标记为公共的此方法自行重建 OpenCV

  • VideoCapture(String)HACKY ONE:使用公共构造函数制作 VideoCapture 类的副本(或扩展原始类并使用反射) 。然后通过使用 C++ OpenCV API 创建您自己的 DLL 来支持本机方法private static native long n_VideoCapture(java.lang.String filename)。(经过测试!)

于 2014-01-17T14:33:07.650 回答
1

我遇到了同样的问题,这对我有用:

  1. 加载ffmpeg

System.loadLibrary("opencv_ffmpeg300_64");

  1. 打开文件:

    VideoCapture vC = new VideoCapture("res/video.mp4");

  2. opencv_ffmpeg300_64.dll从复制opencv\build\x64\vc11\binopencv\build\java\x64

请注意64并且.dll可能因操作系统而异,这些是用于Windows x64

于 2016-06-28T10:55:16.363 回答