我想打开外部摄像头以使用opencv捕获图像。我写了下面的代码,我也检查了一些与这个问题有关的问题,但是,当我运行代码时,外部网络摄像头不会打开绿色指示灯 - 指示网络摄像头为ON的LED和单词“Opened “被打印在屏幕上。正如您在代码中看到的那样,单词“已打开”表示凸轮已打开。WebCam永远不会ON
请让我知道为什么我在网络摄像头的LED不亮时收到“打开”一词。
代码:
public class MainClass {
static {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
}
private final static int WEBCAM_SELECT = -1;
private final static int WEBCAM_BUILTIN = 0;
private final static int WEBCAM_EXTERNAL = 2;
static JFrame mediaFrame = new JFrame("Media");
public static void main(String[] args) throws InterruptedException {
Thread camThread = new Thread(new ThreadCam(), "CamThread");
camThread.setDaemon(true);
VideoCapture vidCap = new VideoCapture(WEBCAM_EXTERNAL);
vidCap.open(WEBCAM_EXTERNAL);
Thread.sleep(10000);// wait 10 sec to initilize the device;
if (vidCap.isOpened()) {
System.out.println("opened");//after 10 seconds this word will be printed
camThread.start();
}
}
更新
亲切讨好的Thread.sleep(10000);线和旁边的评论。
static {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
}
private final static int WEBCAM_SELECT = -1;
private final static int WEBCAM_BUILTIN = 0;
private final static int WEBCAM_EXTERNAL = 1;
static JFrame mediaFrame = new JFrame("Media");
public static void main(String[] args) throws InterruptedException {
Thread camThread = new Thread(new ThreadCam(), "CamThread");
camThread.setDaemon(true);
VideoCapture vidCap = new VideoCapture();
vidCap.open(WEBCAM_EXTERNAL);
Thread.sleep(10000);// wait 10 sec to initilize the device; upto this line the Cam is ON, but after the 10 secs, it is OFF again and the word "Opened" is printed
if (vidCap.isOpened()) {
System.out.println("opened");//after 10 seconds this word will be printed
camThread.start();
}
}
您可以尝试抓取一个框架来查看结果。如果它表示它被打开,那应该是。 –