Ask Your Question

Revision history [back]

How to connect and authenticate Tenvis IP camera from java application using OpenCV

I have Tenvis IP camera with a username and password. I want to capture live photo or video from it in a simple java application developed in Eclipse IDE using OpenCV.

I am using following code to serve my purpose.

public class Hello {

  public static void main( String[] args )
 {
   try
   {
        System.out.println("Welcome to OpenCV " + Core.VERSION);
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
        Mat m  = Mat.eye(3, 3, CvType.CV_8UC1);
        System.out.println("m = " + m.dump());

  // VideoCapture cap= new VideoCapture("D:/css/pizzavideo.mp4");

 VideoCapture cap = new VideoCapture("http://192.168.2.106:7777/video/livesp.asp? 
user=admin&pwd=admin&resolution=32"); 

       if(cap.isOpened())
       {
           System.out.println(" camera found----"+cap);   

                Mat frame = new Mat();
                while(true){
                    if (cap.read(frame)){
                        System.out.println("Frame Obtained");
                        System.out.println("Captured Frame Width " + frame.width() + " Height " + frame.height());
                        Highgui.imwrite("img1.jpg", frame);

                        System.out.println("OK");
                        break;
                    }
                }      
       }
       else
       {   
           System.out.println("Did not connect to camera");   
       }
           cap.release();
   }
   catch(Exception e)
   {
       System.out.println("Exception---"+e.getMessage());
   }
 }
}

Result :When using http://192.168.2.106:7777/video/livesp.asp? user=admin&pwd=admin&resolution=32

Welcome to OpenCV 2.4.8.0
m = [1, 0, 0;
     0, 1, 0;
     0, 0, 1]
Did not connect to camera

Result (I am successfully getting a frame of video as img1.jpg): When using D:/css/pizzavideo.mp4

Welcome to OpenCV 2.4.8.0
m = [1, 0, 0;
     0, 1, 0;
     0, 0, 1]
 camera found----org.opencv.highgui.VideoCapture@87816d
 Frame Obtained
 Captured Frame Width 480 Height 262
 OK

Please tell some way to connect to my IP Camera and take photos or video form java application?