我正在尝试打开外部摄像头,用opencv捕捉图像。我写了下面的代码,我也检查了一些与这个问题有关的问题,但是,当我运行代码时,外部网络摄像头没有在-the上打开显示网络摄像头的绿色LED,并且屏幕上印着“打开”字样。“打开”这个词,如你在下面的代码中所看到的,表示凸轮是开着的。
请让我知道为什么我收到“打开”这个词,而网络摄像头的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();
}
}发布于 2015-04-12 10:45:57
我以前曾面对过这个问题,而我意识到的是,以下两句话:
VideoCapture vidCap = new VideoCapture();
vidCap.open(WEBCAM_EXTERNAL);是实例化VideoCapture类的对象并打开特定的设备。
由于.isOpened返回true,这意味着您选择的设备已成功打开。作为.isOpened()设备的LED在.isOpened()之前打开,在调用.isOpened()之后关闭,这并不意味着您选择打开的设备没有打开或未能打开,但实际上,它是打开的,但您没有执行从您选择打开的设备派生的任何操作。
例如,在.isOpened尝试调用vidCap.grap()或进行视频流之后,eLED应该再次打开。
发布于 2015-04-12 10:24:31
尝试使用WEBCAM_EXTERNAL = 1;而不是WEBCAM_EXTERNAL = 2;
我想知道你的硬件是什么,个人电脑/MAC?
https://stackoverflow.com/questions/29588224
复制相似问题