网络摄像头从不开启
WebCam is never ON
我正在尝试打开外部摄像头以使用 opencv 捕获图像。我写了下面的代码,我也检查了一些与这个问题相关的问题,但是,当我 运行 代码时,外部网络摄像头不会打开绿色 LED
- 指示网络摄像头打开的 LED - 屏幕上打印 "Opened" 字样。正如您在下面的代码中看到的,单词 "Opened" 表示凸轮已打开。
请告诉我为什么在网络摄像头的 LED 未亮起时我收到 "Opened" 字样。
代码:
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();
}
}
尝试使用 WEBCAM_EXTERNAL = 1;而不是 WEBCAM_EXTERNAL = 2;
我想知道你的硬件是什么,PC/MAC?
我以前遇到过这个问题,我意识到的是以下两行:
VideoCapture vidCap = new VideoCapture();
vidCap.open(WEBCAM_EXTERNAL);
是实例化VideoCapture的一个对象Class和打开一个特定的设备
并且由于.isOpened 返回true,这意味着您选择的设备已成功打开。 ypur 设备的 LED 在调用 .isOpened() 之前亮起,在调用 .isOpened() 之后熄灭,这并不意味着您选择打开的设备未打开或打开失败,但实际上它是打开的但您没有执行任何源自您选择打开的设备的操作。
例如,在 .isOpened 之后尝试调用 vidCap.grap() 或进行视频流,然后 eLED 应该再次打开。
我正在尝试打开外部摄像头以使用 opencv 捕获图像。我写了下面的代码,我也检查了一些与这个问题相关的问题,但是,当我 运行 代码时,外部网络摄像头不会打开绿色 LED - 指示网络摄像头打开的 LED - 屏幕上打印 "Opened" 字样。正如您在下面的代码中看到的,单词 "Opened" 表示凸轮已打开。
请告诉我为什么在网络摄像头的 LED 未亮起时我收到 "Opened" 字样。
代码:
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();
}
}
尝试使用 WEBCAM_EXTERNAL = 1;而不是 WEBCAM_EXTERNAL = 2;
我想知道你的硬件是什么,PC/MAC?
我以前遇到过这个问题,我意识到的是以下两行:
VideoCapture vidCap = new VideoCapture();
vidCap.open(WEBCAM_EXTERNAL);
是实例化VideoCapture的一个对象Class和打开一个特定的设备
并且由于.isOpened 返回true,这意味着您选择的设备已成功打开。 ypur 设备的 LED 在调用 .isOpened() 之前亮起,在调用 .isOpened() 之后熄灭,这并不意味着您选择打开的设备未打开或打开失败,但实际上它是打开的但您没有执行任何源自您选择打开的设备的操作。
例如,在 .isOpened 之后尝试调用 vidCap.grap() 或进行视频流,然后 eLED 应该再次打开。