Home > Java > javaTutorial > body text

Simple and easy-to-understand Java Hikvision SDK secondary development guide

王林
Release: 2023-09-06 14:01:53
Original
1731 people have browsed it

Simple and easy-to-understand Java Hikvision SDK secondary development guide

Simple and easy-to-understand Java Hikvision SDK secondary development guide

Introduction:
With the development of camera surveillance technology, Hikvision has become a global One of the leading security solution providers, the SDK (software development kit) it provides provides developers with rich functions and interfaces for secondary development and customized development.

This article will introduce how to use Java language for secondary development of Hikvision SDK, and provide some code examples to help readers better understand and apply.

1. Environment preparation
First of all, before carrying out secondary development of Hikvision SDK, we need to prepare the following environment:

  1. Install JDK (Java Development Kit): Make sure you Your computer has the JDK installed and environment variables configured correctly.
  2. Download Hikvision SDK: You can obtain the Hikvision SDK installation package from the official Hikvision website or other trusted channels. Install and configure the SDK.

2. Create a Java project
Next, we will create a Java project to write the secondary development code of Hikvision SDK:

  1. Open your Favorite integrated development environment (IDE), such as Eclipse, IntelliJ IDEA, etc.
  2. Create a new Java project and set the project name and location.

3. Import SDK library files
Import the SDK library files into your Java project so that you can use related functions and interfaces in your code. The specific steps are as follows:

  1. Create a lib folder in your Java project to store the SDK library files.
  2. Copy the SDK library files to the lib folder.
  3. In the IDE, right-click your Java project, select "Properties" or "Build Path", and then find the "Libraries" or "Build Path" option.
  4. Click the "Add JARs" or "Add External JARs" button, select the SDK library file just imported, and click "OK".

4. Writing code examples
Now, we can start writing the secondary development code of Hikvision SDK. The following is a simple example for implementing video surveillance related functions:

import com.sun.jna.Native;
import com.sun.jna.ptr.IntByReference;
import com.hikvision.netsdk.HCNetSDK;
import com.hikvision.netsdk.NET_DVR_DEVICEINFO_V30;
import com.hikvision.netsdk.NET_DVR_IPPARACFG_V40;
import com.hikvision.netsdk.NET_DVR_PREVIEWINFO;
import com.hikvision.netsdk.NET_DVR_USER_LOGIN_INFO;
import com.hikvision.netsdk.NET_DVR_VIDEOEFFECT;
import com.hikvision.netsdk.RealPlayCallBack;

public class VideoMonitor {
    public static void main(String[] args) {
        // 初始化SDK
        HCNetSDK.INSTANCE.NET_DVR_Init();

        // 登录设备
        NET_DVR_USER_LOGIN_INFO loginInfo = new NET_DVR_USER_LOGIN_INFO();
        loginInfo.sDeviceAddress = "192.168.1.100";
        loginInfo.wPort = 8000;
        loginInfo.sUserName = "admin";
        loginInfo.sPassword = "123456";
        loginInfo.write();
        IntByReference userID = new IntByReference(-1);
        NET_DVR_DEVICEINFO_V30 deviceInfo = new NET_DVR_DEVICEINFO_V30();
        userID.setValue(HCNetSDK.INSTANCE.NET_DVR_Login_V30(loginInfo.getPointer(), deviceInfo.getPointer()));
        if (userID.getValue() < 0) {
            System.out.println("登录设备失败");
            return;
        }

        // 设置视频预览参数
        NET_DVR_PREVIEWINFO previewInfo = new NET_DVR_PREVIEWINFO();
        previewInfo.lChannel = 1;
        previewInfo.dwStreamType = 0;
        previewInfo.dwLinkMode = 0;
        previewInfo.hPlayWnd = null;
        previewInfo.bBlocked = true;
        previewInfo.write();

        // 开始预览
        RealPlayCallBack fRealDataCallBack = (iRealHandle, iDataType, pDataBuffer, iDataSize) -> {
            // 处理实时视频数据
        };
        NativeLong handle = HCNetSDK.INSTANCE.NET_DVR_RealPlay_V40(userID.getValue(), previewInfo.getPointer(), fRealDataCallBack, null);
        if (handle.intValue() < 0) {
            System.out.println("预览失败");
            HCNetSDK.INSTANCE.NET_DVR_Logout(userID.getValue());
            HCNetSDK.INSTANCE.NET_DVR_Cleanup();
            return;
        }

        // 其他操作...

        // 关闭预览
        if (!HCNetSDK.INSTANCE.NET_DVR_StopRealPlay(handle)) {
            System.out.println("停止预览失败");
        }

        // 注销登录
        HCNetSDK.INSTANCE.NET_DVR_Logout(userID.getValue());

        // 释放SDK资源
        HCNetSDK.INSTANCE.NET_DVR_Cleanup();
    }
}
Copy after login

In this example, we use some interfaces of HCNetSDK, including initializing the SDK, logging in to the device, setting preview parameters, starting preview, Stop preview, log out and release SDK resources. You can continue to expand and customize these features to suit your needs.

5. Run the program
After completing the code writing, you can run the program and view the results. If everything goes well, you should be able to implement video surveillance related functions.

Conclusion:
In this article, we briefly introduce how to use Java language for secondary development of Hikvision SDK, and provide a code example for video surveillance related functions. I hope this article can help developers better understand and apply Hikvision SDK to implement customized security solutions.

References:

  1. Hikvision Developer Support Center - https://open.hikvision.com/
  2. Hikvision Developer Forum - https://bbs.hikvision.com/
  3. HCNetSDK Development Kit- https://github.com/hikvision-netsdk/HikSDK

The above is the detailed content of Simple and easy-to-understand Java Hikvision SDK secondary development guide. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!