0
我試圖用openCV連接一個D-Link相機型號DCS-932L。我認爲問題在於URL格式。 IP,端口,密碼和用戶都是正確的。OpenCV Java連接DCS-932L
這是我的代碼:
public static void main(String args[]) throws Exception {
String end = "http://USER:[email protected]:80/mjpeg.cgi?user=USERNAME&password=PWD&channel=0&.mjpg";
ContainerImagem toc = new ContainerImagem();
Button button = new Button();
button.addActionListener(null);
JFrame frame = new JFrame("Captura de face");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(600, 600);
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
CascadeClassifier faceDetector = new CascadeClassifier("C:\\Users\\leonardo\\Documents\\opencv\\sources\\data\\haarcascades\\haarcascade_frontalface_alt.xml");
toc.setSize(2000, 2000);
frame.add(toc);
frame.setVisible(true);
Mat webcam_image = new Mat();
MatToBufImg mat2Buf = new MatToBufImg();
VideoCapture capture = new VideoCapture();
capture.open(end);
if (capture.isOpened()) {
Thread.sleep(10000);
while (true) {
capture.read(webcam_image);
if (!webcam_image.empty()) {
frame.setSize(webcam_image.width(), webcam_image.height());
MatOfRect faceDetections = new MatOfRect();
faceDetector.detectMultiScale(webcam_image, faceDetections);
for (Rect rect : faceDetections.toArray()) {
Core.rectangle(webcam_image, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height), new Scalar(0, 255, 0));// mat2Buf, mat2Buf);
}
// System.out.println("...............face detected: " + faceDetections.toArray().length);
if (faceDetections.toArray().length == 0) {
// System.out.println("Sorry Face not detected!");
}
mat2Buf.setMatrix(webcam_image, ".jpg");
toc.setImage(mat2Buf.getBufferedImage());
toc.repaint();
} else {
System.out.println("problems with webcam image capture");
break;
}
}
} else {
JOptionPane.showMessageDialog(null, "O sistema não conseguiu se conectar com esta câmera.");
}
capture.release();
}