[英]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: 设置如下:
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.