我是 StackOverflow 和 OpenCV 编程领域的新手。我用一些 Java 代码打开了我的相机,它可以工作,因为相机的灯亮着,但是当我试图关闭相机时,我失败了。
代码:
public class camera {
public static void main(String[] args) {
System.loadLibrary("opencv_java244");
VideoCapture camera = new VideoCapture(0);
if (camera.isOpened())
System.out.println("Camera is ready!");
else {
System.out.println("Camera Error!");
return;
}
Mat newMat = new Mat();
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
//e.printStackTrace();
}
camera.read(newMat);
Highgui.imwrite("testfile.jpg", newMat);
camera.release();
if (camera.isOpened()) {
System.out.println("Camera is running!");
}
else {
System.out.println("Camera closed!");
}
}
}
结果:
Camera is ready!
Camera closed!
我真的得到了照片,但灯仍然亮着!PS每次打开相机时,电脑都会打开一个叫YouCam的驱动软件,我必须手动关闭它才能释放相机。