Master the necessary skills for secondary development of Java Hikvision SDK
Introduction:
With the rapid development of information technology, video surveillance systems have been widely used in various fields. a wide range of applications. As the leading domestic video surveillance solution provider, Hikvision’s products and technologies have always occupied an important position in the market. In order to meet the needs of different projects, Hikvision provides SDK for developers to carry out secondary development. This article will introduce some essential skills for mastering the secondary development of Java Hikvision SDK, and attach corresponding code examples.
1. Understand the functions and interfaces of Hikvision SDK
Before carrying out secondary development of Java Hikvision SDK, you first need to understand the functions and interfaces of Hikvision SDK. Hikvision provides a rich SDK interface, covering functions such as video surveillance, face recognition, and intelligent analysis. Developers can choose the corresponding interface for development according to specific needs. After mastering the basic functions of the SDK, we can start the practice of secondary development.
2. Configure the development environment and import the SDK package
Before carrying out secondary development of Java Hikvision SDK, we need to configure the development environment and import the SDK package. First download the Java development package of Hikvision SDK and import it into the development tool. Next, we need to configure the relevant dependent libraries and operating environment. For specific configuration steps, please refer to Hikvision official documentation.
3. Implementation of the video surveillance function
Before carrying out the secondary development of the video surveillance function, we need to initialize the SDK first. The specific code is as follows:
HCNetSDK.INSTANCE.NET_DVR_Init();
Logging in to the device is a key step for the video surveillance function. We can log in using the administrator account and obtain the login handle for subsequent operations. The specific code is as follows:
HCNetSDK.NET_DVR_USER_LOGIN_INFO loginInfo = new HCNetSDK.NET_DVR_USER_LOGIN_INFO(); loginInfo.sDeviceAddress = "192.168.1.100"; loginInfo.sUserName = "admin"; loginInfo.sPassword = "123456"; loginInfo.wPort = 8000; HCNetSDK.NET_DVR_DEVICEINFO_V40 deviceInfo = new HCNetSDK.NET_DVR_DEVICEINFO_V40(); IntByReference errorCode = new IntByReference(); int loginHandle = HCNetSDK.INSTANCE.NET_DVR_Login_V40(loginInfo, deviceInfo); if (loginHandle < 0) { int error = HCNetSDK.INSTANCE.NET_DVR_GetLastError(); System.out.println("登录失败,错误码:" + error); } else { System.out.println("登录成功,登录句柄:" + loginHandle); }
Real-time preview is one of the commonly used functions in video surveillance functions. We can preview in real time by specifying the channel number and preview window. The specific code is as follows:
HCNetSDK.NET_DVR_PREVIEWINFO previewInfo = new HCNetSDK.NET_DVR_PREVIEWINFO(); previewInfo.lChannel = 1;//通道号 previewInfo.hPlayWnd = hWnd;//预览窗口句柄 HCNetSDK.PlayCtrl.INSTANCE.PlayM4_SetDecodeThreadNum(2); IntByReference previewHandle = new IntByReference(); previewHandle.setValue(HCNetSDK.INSTANCE.NET_DVR_RealPlay_V40(loginHandle, previewInfo, null)); if (previewHandle.getValue() == -1) { int error = HCNetSDK.INSTANCE.NET_DVR_GetLastError(); System.out.println("实时预览失败,错误码:" + error); } else { System.out.println("实时预览成功,预览句柄:" + previewHandle.getValue()); }
When the preview is no longer needed, we need to stop the preview and log out of the device. The specific code is as follows:
HCNetSDK.INSTANCE.NET_DVR_StopRealPlay(previewHandle.getValue()); HCNetSDK.INSTANCE.NET_DVR_Logout_V30(loginHandle); HCNetSDK.INSTANCE.NET_DVR_Cleanup();
4. Implementation of face recognition function
Similar to the video surveillance function, we need to initialize it first SDK. The specific code is as follows:
HikvisionLibrary.INSTANCE.NET_DVR_Init();
Logging in to the device is a key step for the face recognition function. We can log in using the administrator account and obtain the login handle for subsequent operations. The specific code is as follows:
HikvisionLibrary.NET_DVR_USER_LOGIN_INFO loginInfo = new HikvisionLibrary.NET_DVR_USER_LOGIN_INFO(); loginInfo.sDeviceAddress = "192.168.1.100"; loginInfo.sUserName = "admin"; loginInfo.sPassword = "123456"; loginInfo.wPort = 8000; HikvisionLibrary.NET_DVR_DEVICEINFO_V40 deviceInfo = new HikvisionLibrary.NET_DVR_DEVICEINFO_V40(); IntByReference errorCode = new IntByReference(); int loginHandle = HikvisionLibrary.INSTANCE.NET_DVR_Login_V40(loginInfo, deviceInfo); if (loginHandle < 0) { int error = HikvisionLibrary.INSTANCE.NET_DVR_GetLastError(); System.out.println("登录失败,错误码:" + error); } else { System.out.println("登录成功,登录句柄:" + loginHandle); }
The core of the face recognition function is face detection and face comparison. We can perform face detection by specifying the image path and perform face comparison through the comparison algorithm. The specific code is as follows:
HikvisionLibrary.NET_DVR_FACE_COND faceCond = new HikvisionLibrary.NET_DVR_FACE_COND(); faceCond.dwFaceNum = 1; HikvisionLibrary.NET_DVR_FACE_RECORD[] faceRecord = (HikvisionLibrary.NET_DVR_FACE_RECORD[]) new HikvisionLibrary.NET_DVR_FACE_RECORD().toArray(1); faceRecord[0].byCardNo = "001".getBytes(); faceRecord[0].byFacePicNum = 1; faceRecord[0].struFacePicInfo[0].byFaceQuality = 50; faceRecord[0].struFacePicInfo[0].wFacePicLen = facePicData.length; System.arraycopy(facePicData, 0, faceRecord[0].struFacePicInfo[0].byFacePicBuffer, 0, facePicData.length); HikvisionLibrary.NET_DVR_FACE_STATUS status = new HikvisionLibrary.NET_DVR_FACE_STATUS(); int handle = HikvisionLibrary.INSTANCE.NET_DVR_StartRemoteConfig(loginHandle, HikvisionLibrary.NET_DVR_SET_FACE_RECORD, faceCond.getPointer(), faceCond.size(), null, null); if (handle == -1) { int error = HikvisionLibrary.INSTANCE.NET_DVR_GetLastError(); System.out.println("开始远程配置失败,错误码:" + error); return; } IntByReference bytesReturned = new IntByReference(); HikvisionLibrary.INSTANCE.NET_DVR_SendRemoteConfig(handle, faceRecord, faceRecord[0].size(), bytesReturned); HikvisionLibrary.INSTANCE.NET_DVR_StopRemoteConfig(handle); int error = HikvisionLibrary.INSTANCE.NET_DVR_GetLastError(); if (error != 0) { System.out.println("人脸比对失败,错误码:" + error); } else { System.out.println("人脸比对成功"); }
5. Summary
This article introduces the necessary skills to master the secondary development of Java Hikvision SDK, and also provides instructions for functions such as video surveillance and face recognition. Code examples. Through learning and practice, developers can flexibly use Hikvision SDK for secondary development to meet the needs of different projects. Of course, there are more functions and interfaces waiting for developers to explore and apply. I hope this article will be helpful to the learning and practice of secondary development of Java Hikvision SDK.
The above is the detailed content of Master the essential skills for secondary development of Java Hikvision SDK. For more information, please follow other related articles on the PHP Chinese website!