简体   繁体   English

OpenCV-Java:VideoCapture读取框架与USB摄像机挂在一起

[英]OpenCV - Java: VideoCapture read frame hangs with usb camera

I'm quite new to OpenCV - Java programming, and I'm trying to setup an application to read video frames from USB WebCam, to start with something. 我对OpenCV刚起步-Java编程,因此我试图设置一个应用程序以从USB WebCam读取视频帧,并以此开始。

This is the document I followed up to now: https://opencv-java-tutorials.readthedocs.io/en/latest/03-first-javafx-application-with-opencv.html#video-capturing 这是我到目前为止所关注的文档: https : //opencv-java-tutorials.readthedocs.io/en/latest/03-first-javafx-application-with-opencv.html#video-capturing

The setup is the following: 设置如下:

  • Java version: 10.0.1 Java版本:10.0.1
  • OpenCV Version: 3.3.4 and 3.2.0, same error with both versions OpenCV版本:3.3.4和3.2.0,两个版本存在相同的错误
  • OS: Windows 10 x64 作业系统:Windows 10 x64
  • The .dll is placed under C:\\Windows, that is included in my java.library.path .dll放在C:\\ Windows下,包含在我的java.library.path中

I have some additional frameworks involved in the application, but I prepared an isolated test case to better check the issue: 我在应用程序中涉及一些其他框架,但是我准备了一个隔离的测试用例以更好地检查问题:

import org.junit.Test;
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.videoio.VideoCapture;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class CVCaptureTest {

    private static final Logger LOG = LoggerFactory.getLogger(CVCaptureTest.class);

    @Test
    public void testFrameRead() {
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
        VideoCapture capture = new VideoCapture();
        capture.open(0);

        for (int i = 0; i < 100; i ++) {
            if (capture.isOpened()) {
                Mat frame = new Mat();
                LOG.info("Capture open. Reading frame...");
                capture.retrieve(frame);

                LOG.info("Captured: {}", frame.dump());
            }
        }
    }
}

Output: 输出:

[INFO] Running i.m.r.b.r.c.CVCaptureTest
20:15:57.757 [main] INFO i.m.r.b.r.c.CVCaptureTest - Capture open. Reading frame...

After this log line the program just hangs, without throwing any exception. 在此日志行之后,程序将立即挂起,而不会引发任何异常。

Any help on understanding the cause of the freeze is welcome. 欢迎您对了解冻结原因的任何帮助。

Thanks & Regards, Mattia! 谢谢与问候,Mattia!

Try to use the capture.read(frame); 尝试使用capture.read(frame); .

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未考虑 Java OpenCV VideoCapture 属性。 需要避免最新帧的“当真”。 多相机环境 - Java OpenCV VideoCapture properties not being considered. Need to avoid “while true” for latest frame. Multi-camera environment 如果使用 nu.pattern.OpenCV.loadShared() 加载 openCV,则 Java 打开 CV 会挂在 VideoCapture 上以获取文件; - Java open CV hangs on VideoCapture for file if openCV is loaded with nu.pattern.OpenCV.loadShared(); OpenCV - VideoCapture(filename) 适用于 Java,但不适用于 Python (Windows 7) - OpenCV - VideoCapture(filename) works in Java but not in Python (Windows 7) OpenCV:VideoCapture :: get(CV_CAP_PROP_FPS)返回0 FPS直接视频输入,而无需在Java中使用相机 - OpenCV: VideoCapture::get(CV_CAP_PROP_FPS) returns 0 FPS direct video input without using camera in java 带Rapsberry Pi的OpenCV:VideoCapture IP摄像机不起作用 - OpenCV w/ Rapsberry Pi: VideoCapture IP camera not working 实时从我的 java openCV 应用程序通过 USB 访问安卓手机摄像头 - Accessing android phone Camera thru USB from my java openCV application in real time Java 中带有 OpenCv 的 IP 摄像机 - IP camera with OpenCv in Java Java OpenCv中的相机校准 - Camera Calibration in Java OpenCv OpenCV Android Java VideoCapture构造函数不采用字符串 - OpenCV Android Java VideoCapture constructor does not take a String OpenCV Java绑定VideoCapture从文件静默失败 - OpenCV Java binds VideoCapture from file failing silently
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM