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:
2. Create a Java project
Next, we will create a Java project to write the secondary development code of Hikvision SDK:
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:
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(); } }
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:
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!