OpenCV VideoCapture无法读取帧

时间:2018-07-04 23:45:45

标签: java opencv

我正在尝试从USB摄像机读取帧, 我已经编译了GitHub

上可用的最新OpenCV
Core.VERSION = 4.0.0.dev

但是当我尝试运行此代码时,我得到了:

import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.videoio.VideoCapture;

public class OpenCVTest {

    static {
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
    }

    public static void main(String[] args) {
        Mat frame = new Mat();

        VideoCapture videoCapture = new VideoCapture();

        assert videoCapture.open(0);
        assert videoCapture.isOpened();

        while (!Thread.interrupted()) {
            assert videoCapture.read(frame);
        }
    }
}


[ WARN:0] videoio(MSMF): OnReadSample() is called with error status: -2147024809
[ WARN:0] videoio(MSMF): async ReadSample() call is failed with error status: -2147024809
[ WARN:1] videoio(MSMF): can't grab frame. Error: -2147024809
Exception in thread "main" java.lang.AssertionError
    at OpenCVTest.main(OpenCVTest.java:24)

我也尝试过3.4.2-dev branch,但是遇到了同样的错误,奇怪的是,当我使用可用的预构建版本here时,我的代码可以完美地工作了,我缺少了什么? / p>

1 个答案:

答案 0 :(得分:-1)

问题是Windows路径变量。可以在Windows的运行配置中的环境选项卡中进行设置。 (我将其设置为(示例)c:\ opencv \ opencv \ build \ x64 \ vc12 \ bin)