


Use Java Hikvision SDK secondary development to build a powerful video surveillance system
Use Java Hikvision SDK for secondary development to build a powerful video surveillance system
Abstract:
This article will introduce how to use Java Hikvision SDK for secondary development , build a powerful video surveillance system. Through the rich interfaces and functions provided by Hikvision SDK, we can easily implement video recording, real-time preview, remote control and other functions, and add customized business logic. This article will introduce in detail how to use Java Hikvision SDK for secondary development, and provide some sample code to help readers better understand.
Part One: Environment Preparation
Before starting, we need to make the following preparations:
- Download and install Java JDK.
- Download and install IDE, such as Eclipse.
- Download and install Hikvision SDK.
Part 2: Project Creation and Configuration
- Create a Java project and import the jar package of Hikvision SDK.
- Configure the relevant parameters of Hikvision SDK, such as device IP, port number, user name, password, etc.
- Create a main class to initialize the SDK and perform related operations.
Part 3: Real-time preview function
Real-time preview is one of the most basic functions in the video surveillance system. The following is a sample code that demonstrates how to use Hikvision SDK for real-time preview:
import com.sun.jna.NativeLong; import com.sun.jna.Pointer; import com.sun.jna.ptr.NativeLongByReference; import com.sun.jna.ptr.PointerByReference; import com.hikvision.netsdk.HCNetSDK; import com.hikvision.netsdk.NET_DVR_DEVICEINFO_V30; import com.hikvision.netsdk.NET_DVR_PREVIEWINFO; public class RealTimePreview { private static HCNetSDK hikSDK = HCNetSDK.INSTANCE; public static void main(String[] args) { // 初始化SDK hikSDK.NET_DVR_Init(); // 登录设备 NativeLong lUserID; NET_DVR_DEVICEINFO_V30 deviceInfo = new NET_DVR_DEVICEINFO_V30(); lUserID = hikSDK.NET_DVR_Login_V30("192.168.1.100", (short) 8000, "admin", "password", deviceInfo); if (lUserID.intValue() == -1) { System.out.println("登录失败,错误码:" + hikSDK.NET_DVR_GetLastError()); return; } // 设置预览参数 NativeLong lRealPlayHandle; NET_DVR_PREVIEWINFO previewInfo = new NET_DVR_PREVIEWINFO(); previewInfo.lChannel = 1; previewInfo.dwStreamType = 0; previewInfo.dwLinkMode = 0; previewInfo.hPlayWnd = null; // 开始预览 lRealPlayHandle = hikSDK.NET_DVR_RealPlay_V40(lUserID, previewInfo, null); if (lRealPlayHandle.intValue() == -1) { System.out.println("预览失败,错误码:" + hikSDK.NET_DVR_GetLastError()); return; } // 等待预览停止 System.out.println("按任意键停止预览..."); try { System.in.read(); } catch (Exception e) { e.printStackTrace(); } // 停止预览 if (!hikSDK.NET_DVR_StopRealPlay(lRealPlayHandle)) { System.out.println("停止预览失败,错误码:" + hikSDK.NET_DVR_GetLastError()); return; } // 退出登录 hikSDK.NET_DVR_Logout(lUserID); hikSDK.NET_DVR_Cleanup(); System.out.println("退出成功"); } }
Part 4: Video recording function
In addition to real-time preview, the video surveillance system also needs to provide video recording function. The following is a sample code that demonstrates how to use Hikvision SDK for video recording:
import com.sun.jna.NativeLong; import com.sun.jna.ptr.NativeLongByReference; import com.hikvision.netsdk.HCNetSDK; import com.hikvision.netsdk.NET_DVR_DEVICEINFO_V30; import com.hikvision.netsdk.NET_DVR_PREVIEWINFO; import com.hikvision.netsdk.NET_DVR_TIME; public class VideoRecording { private static HCNetSDK hikSDK = HCNetSDK.INSTANCE; public static void main(String[] args) { // 初始化SDK hikSDK.NET_DVR_Init(); // 登录设备 NativeLong lUserID; NET_DVR_DEVICEINFO_V30 deviceInfo = new NET_DVR_DEVICEINFO_V30(); lUserID = hikSDK.NET_DVR_Login_V30("192.168.1.100", (short) 8000, "admin", "password", deviceInfo); if (lUserID.intValue() == -1) { System.out.println("登录失败,错误码:" + hikSDK.NET_DVR_GetLastError()); return; } // 设置预览参数 NativeLong lRealPlayHandle; NET_DVR_PREVIEWINFO previewInfo = new NET_DVR_PREVIEWINFO(); previewInfo.lChannel = 1; previewInfo.dwStreamType = 0; previewInfo.dwLinkMode = 0; previewInfo.hPlayWnd = null; // 开始预览 lRealPlayHandle = hikSDK.NET_DVR_RealPlay_V40(lUserID, previewInfo, null); if (lRealPlayHandle.intValue() == -1) { System.out.println("预览失败,错误码:" + hikSDK.NET_DVR_GetLastError()); return; } // 开始录像 NativeLongByReference lRecordHandle = new NativeLongByReference(); NET_DVR_TIME startTime = new NET_DVR_TIME(); startTime.dwYear = 2022; startTime.dwMonth = 12; startTime.dwDay = 1; startTime.dwHour = 0; startTime.dwMinute = 0; startTime.dwSecond = 0; if (!hikSDK.NET_DVR_SetFileTime(0, startTime)) { System.out.println("设置录像时间失败,错误码:" + hikSDK.NET_DVR_GetLastError()); return; } lRecordHandle.setValue(hikSDK.NET_DVR_RealPlay_V40(lUserID, previewInfo, null)); if (lRecordHandle.intValue() == -1) { System.out.println("录像失败,错误码:" + hikSDK.NET_DVR_GetLastError()); return; } // 等待录像停止 System.out.println("按任意键停止录像..."); try { System.in.read(); } catch (Exception e) { e.printStackTrace(); } // 停止录像 if (!hikSDK.NET_DVR_StopRealPlay(lRecordHandle.getValue())) { System.out.println("停止录像失败,错误码:" + hikSDK.NET_DVR_GetLastError()); return; } // 退出登录 hikSDK.NET_DVR_Logout(lUserID); hikSDK.NET_DVR_Cleanup(); System.out.println("退出成功"); } }
Summary:
This article introduces how to use Java Hikvision SDK for secondary development to build a powerful video surveillance system. Through the interfaces and functions provided by Hikvision SDK, we can implement functions such as real-time preview and video recording, and add customized business logic. I hope this article can help readers learn and use Java Hikvision SDK.
The above is the detailed content of Use Java Hikvision SDK secondary development to build a powerful video surveillance system. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Guide to Perfect Number in Java. Here we discuss the Definition, How to check Perfect number in Java?, examples with code implementation.

Guide to Random Number Generator in Java. Here we discuss Functions in Java with examples and two different Generators with ther examples.

Guide to Weka in Java. Here we discuss the Introduction, how to use weka java, the type of platform, and advantages with examples.

Guide to Smith Number in Java. Here we discuss the Definition, How to check smith number in Java? example with code implementation.

In this article, we have kept the most asked Java Spring Interview Questions with their detailed answers. So that you can crack the interview.

Java 8 introduces the Stream API, providing a powerful and expressive way to process data collections. However, a common question when using Stream is: How to break or return from a forEach operation? Traditional loops allow for early interruption or return, but Stream's forEach method does not directly support this method. This article will explain the reasons and explore alternative methods for implementing premature termination in Stream processing systems. Further reading: Java Stream API improvements Understand Stream forEach The forEach method is a terminal operation that performs one operation on each element in the Stream. Its design intention is

Guide to TimeStamp to Date in Java. Here we also discuss the introduction and how to convert timestamp to date in java along with examples.

Java is a popular programming language that can be learned by both beginners and experienced developers. This tutorial starts with basic concepts and progresses through advanced topics. After installing the Java Development Kit, you can practice programming by creating a simple "Hello, World!" program. After you understand the code, use the command prompt to compile and run the program, and "Hello, World!" will be output on the console. Learning Java starts your programming journey, and as your mastery deepens, you can create more complex applications.
