fpompermaier / onvif

Java ONVIF library
Apache License 2.0
191 stars 88 forks source link

how to open onvif camera in java #11

Closed sachinrke closed 5 years ago

sachinrke commented 5 years ago

hiii, i want to open my ptz camera in java using your library. please tell me how to open camera. thank you in advance.

fpompermaier commented 5 years ago

If you want to use an Ovif device try to have a look at https://github.com/fpompermaier/onvif/blob/master/udoo-bot/src/main/java/org/udoo/telegram/bot/TelegramMsgHandler.java.

You need to write something like:

try {
    System.out.println("Connect to camera, please wait ...");
    OnvifDevice cam = new OnvifDevice(deviceIp, user, password);
    System.out.printf("Connected to device %s (%s)\n", cam.getDeviceInfo(), deviceName);
} catch (ConnectException | SOAPException e1) {
    System.err.println("No connection to device with ip " + deviceIp + ", please try again.");
    System.exit(0);
}

Then you can take a picture from the camera with:

MediaUri sceenshotUri = cam.getMedia().getSnapshotUri(profileToken);
File tempFile = File.createTempFile("tmp", ".jpg");
FileUtils.copyURLToFile(new URL(sceenshotUri.getUri()), tempFile);