Connect D-link DCS-932L Camera with opencv

Asked

Viewed 297 times

0

I’m trying to connect 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 URL format. Below follows 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();
}
  • Please be more specific in the error that is happening, the term nada funciona is very comprehensive!

  • It turns out that there is no connection to the camera and the video is not displayed. "System failed to connect with this camera" message is displayed. For local Web cam, it works normally.

2 answers

1


I checked in Stackoverflow that Opencv does not work well with stream in mjpg format. I also found in the English forum an excerpt of code used 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);

}

  • Maybe it would be a good one to put the response link in the English OS.

0

The connection string was wrong, but anyway you’re forgetting to replace 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;
  • PORT by the connection port.
  • In fact, in my effective code this data was replaced by IP, port, user and password, real, however, not connected to the device.

  • But even so, there was a URL field that you omitted. Take a look again at my String...

  • At the end of the string you put "...user=Id&password=ID...". That is: user = <username>&password=<username>. Is that correct? I couldn’t connect.

  • ?user=ID&password=ID:PASSWORD

Browser other questions tagged

You are not signed in. Login or sign up in order to post.