Connect DCS-932L D-Link Camera with opencv

0

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();
}
    
asked by anonymous 18.12.2014 / 18:32

2 answers

1

I checked in StackOverFlow in English that OpenCV does not work well with stream in mjpg format. I also found in the English forum a piece of code used in JavaCV. This worked perfectly for me, with the same URL I was using before.

public static void main(String[] args) throws Exception {

OpenCVFrameGrabber grabber = new OpenCVFrameGrabber("http://USER:[email protected]:80/mjpeg.cgi?user=USER&password=PASSWORD&channel=0&.mjpg"); 
grabber.setFormat("mjpeg");
grabber.start();

IplImage frame = grabber.grab();
CanvasFrame canvasFrame = new CanvasFrame("Camera");
canvasFrame.setCanvasSize(frame.width(), frame.height());
while (canvasFrame.isVisible() && (frame = grabber.grab()) != null) {
    canvasFrame.showImage(frame);
}
grabber.stop();
canvasFrame.dispose();
System.exit(0);

}

    
22.12.2014 / 19:00
0

The connection string was wrong, but anyway you're forgetting to replace it in the string:

String end = "http://ID:PASSWORD@IPADDRESS:PORTNO/mjpeg.cgi?user=ID&password=ID:PASSWORD&channel=0&.mjpg";

The following information:

  • ID by user name;
  • PASSWORD by password;
  • IPADDRESS by the camera's IP address;
  • PORTNO by the connection port.
19.12.2014 / 00:32