1
我是OpenCV - Java的初學者,並嘗試通過從筆記本電腦中的攝像頭捕捉圖像來學習基礎知識。我在eclipse中運行以下代碼,我可以看到相機閃爍一秒鐘,表明它確實啓動了。但存儲的圖像是全黑的。OpenCV中的攝像頭捕捉的圖像是全黑的
import org.opencv.core.*;
import org.opencv.videoio.VideoCapture;
import org.opencv.imgcodecs.*;
public class VideoCap {
public static void main(String[] args){
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
VideoCapture camera = new VideoCapture(0);
if(!camera.isOpened()) {
System.out.println("Erro in opening camera");
}
else {
Mat frame = new Mat();
while(true) {
if(camera.read(frame)) {
System.out.println("Camera obtained");
System.out.println("Captured frame width" + frame.width()
+ " catured frame height " + frame.height());
Imgcodecs.imwrite("cam.jpg", frame);
break;
}
}
}
camera.release();
}
}
控制檯沒有錯誤,可能出了什麼問題?
是寬度和高度是否正確?你有沒有嘗試過'Imshow'(在'imwrite'之前),看看那裏有什麼? –