I'm trying to connect the OpenCV with a D-Link DCS-932L IP camera. IP, password, user and port are correct, but nothing works. I believe the error is in relation to the format of the URL. Below is the code.
public static void main(String args[]) throws Exception {
String end = "http://USER:PWD@IPADDRESS:8088/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();
}