├── hikvision ├── __init__.py ├── hk_define.py ├── hikvision_infrared.py ├── hk_struct.py └── hikvision.py ├── hklib ├── libiconv.so.2 ├── libssl.so.1.0.0 ├── libNPQos.so ├── libhpr.so ├── libssl.so ├── libHCAlarm.so ├── libHCCore.so ├── libcrypto.so ├── libiconv2.so ├── libHCDisplay.so ├── libHCIndustry.so ├── libHCPlayBack.so ├── libHCPreview.so ├── libPlayCtrl.so ├── libhcnetsdk.so ├── libAudioRender.so ├── libHCCoreDevCfg.so ├── libHCVoiceTalk.so ├── libSuperRender.so ├── libanalyzedata.so ├── libcrypto.so.1.0.0 ├── libtemperature.so ├── libHCGeneralCfgMgr.so ├── libSystemTransform.so ├── HCNetSDK_Log_Switch.xml ├── libStreamTransClient.so └── readme.md ├── .gitignore ├── docs ├── 参数配置流程.png └── 设备网络SDK编程指南(CVR).pdf ├── setup.py ├── test ├── 03-testmain.py ├── 02-拍照.py └── 01-设置相机变焦.py ├── README.md └── LICENSE /hikvision/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hklib/libiconv.so.2: -------------------------------------------------------------------------------- 1 | libiconv2.so -------------------------------------------------------------------------------- /hklib/libssl.so.1.0.0: -------------------------------------------------------------------------------- 1 | libssl.so -------------------------------------------------------------------------------- /hikvision/hk_define.py: -------------------------------------------------------------------------------- 1 | NET_DVR_GET_FOCUSMODECFG = 3305 2 | NET_DVR_SET_FOCUSMODECFG = 3306 -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .venv/ 2 | .idea/ 3 | # Python: 4 | *.py[cod] 5 | *.egg 6 | *.egg-info 7 | dist 8 | build -------------------------------------------------------------------------------- /docs/参数配置流程.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byte-voyager/HCNetPythonSDK-Linux/HEAD/docs/参数配置流程.png -------------------------------------------------------------------------------- /hklib/libNPQos.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byte-voyager/HCNetPythonSDK-Linux/HEAD/hklib/libNPQos.so -------------------------------------------------------------------------------- /hklib/libhpr.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byte-voyager/HCNetPythonSDK-Linux/HEAD/hklib/libhpr.so -------------------------------------------------------------------------------- /hklib/libssl.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byte-voyager/HCNetPythonSDK-Linux/HEAD/hklib/libssl.so -------------------------------------------------------------------------------- /hklib/libHCAlarm.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byte-voyager/HCNetPythonSDK-Linux/HEAD/hklib/libHCAlarm.so -------------------------------------------------------------------------------- /hklib/libHCCore.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byte-voyager/HCNetPythonSDK-Linux/HEAD/hklib/libHCCore.so -------------------------------------------------------------------------------- /hklib/libcrypto.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byte-voyager/HCNetPythonSDK-Linux/HEAD/hklib/libcrypto.so -------------------------------------------------------------------------------- /hklib/libiconv2.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byte-voyager/HCNetPythonSDK-Linux/HEAD/hklib/libiconv2.so -------------------------------------------------------------------------------- /hklib/libHCDisplay.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byte-voyager/HCNetPythonSDK-Linux/HEAD/hklib/libHCDisplay.so -------------------------------------------------------------------------------- /hklib/libHCIndustry.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byte-voyager/HCNetPythonSDK-Linux/HEAD/hklib/libHCIndustry.so -------------------------------------------------------------------------------- /hklib/libHCPlayBack.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byte-voyager/HCNetPythonSDK-Linux/HEAD/hklib/libHCPlayBack.so -------------------------------------------------------------------------------- /hklib/libHCPreview.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byte-voyager/HCNetPythonSDK-Linux/HEAD/hklib/libHCPreview.so -------------------------------------------------------------------------------- /hklib/libPlayCtrl.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byte-voyager/HCNetPythonSDK-Linux/HEAD/hklib/libPlayCtrl.so -------------------------------------------------------------------------------- /hklib/libhcnetsdk.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byte-voyager/HCNetPythonSDK-Linux/HEAD/hklib/libhcnetsdk.so -------------------------------------------------------------------------------- /hklib/libAudioRender.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byte-voyager/HCNetPythonSDK-Linux/HEAD/hklib/libAudioRender.so -------------------------------------------------------------------------------- /hklib/libHCCoreDevCfg.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byte-voyager/HCNetPythonSDK-Linux/HEAD/hklib/libHCCoreDevCfg.so -------------------------------------------------------------------------------- /hklib/libHCVoiceTalk.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byte-voyager/HCNetPythonSDK-Linux/HEAD/hklib/libHCVoiceTalk.so -------------------------------------------------------------------------------- /hklib/libSuperRender.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byte-voyager/HCNetPythonSDK-Linux/HEAD/hklib/libSuperRender.so -------------------------------------------------------------------------------- /hklib/libanalyzedata.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byte-voyager/HCNetPythonSDK-Linux/HEAD/hklib/libanalyzedata.so -------------------------------------------------------------------------------- /hklib/libcrypto.so.1.0.0: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byte-voyager/HCNetPythonSDK-Linux/HEAD/hklib/libcrypto.so.1.0.0 -------------------------------------------------------------------------------- /hklib/libtemperature.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byte-voyager/HCNetPythonSDK-Linux/HEAD/hklib/libtemperature.so -------------------------------------------------------------------------------- /docs/设备网络SDK编程指南(CVR).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byte-voyager/HCNetPythonSDK-Linux/HEAD/docs/设备网络SDK编程指南(CVR).pdf -------------------------------------------------------------------------------- /hklib/libHCGeneralCfgMgr.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byte-voyager/HCNetPythonSDK-Linux/HEAD/hklib/libHCGeneralCfgMgr.so -------------------------------------------------------------------------------- /hklib/libSystemTransform.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byte-voyager/HCNetPythonSDK-Linux/HEAD/hklib/libSystemTransform.so -------------------------------------------------------------------------------- /hklib/HCNetSDK_Log_Switch.xml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byte-voyager/HCNetPythonSDK-Linux/HEAD/hklib/HCNetSDK_Log_Switch.xml -------------------------------------------------------------------------------- /hklib/libStreamTransClient.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byte-voyager/HCNetPythonSDK-Linux/HEAD/hklib/libStreamTransClient.so -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | import setuptools 2 | 3 | setuptools.setup( 4 | name='hikvision', 5 | version='0.1', 6 | install_requires=['numpy'], 7 | packages=setuptools.find_packages() 8 | ) -------------------------------------------------------------------------------- /test/03-testmain.py: -------------------------------------------------------------------------------- 1 | import random 2 | from hikvision.hikvision import HIKVisionSDK 3 | 4 | LIB_DIR = '/home/baloneo/PythonProject/HCNetPythonSDK-Linux/hklib' 5 | 6 | sdk = HIKVisionSDK(lib_dir=LIB_DIR, 7 | username='admin', 8 | ip='192.168.1.124', 9 | password='Admin12345') 10 | try: 11 | sdk.init() 12 | except Exception as e: 13 | print(e) 14 | print('Errcode ', sdk.err_code) 15 | else: 16 | ok = sdk.take_picture('/tmp/jjjj.jpg', release_resources=False) 17 | print('ok1', ok) 18 | ok = sdk.take_picture('/tmp/jjjj3.jpg', release_resources=False) 19 | print('ok2', ok) 20 | value = sdk.get_zoom(release_resources=False) 21 | print('zoom value', value) 22 | ok = sdk.set_zoom(zoom=10, release_resources=True) 23 | print('zoom ok', ok) 24 | 25 | 26 | print(sdk.get_infrared_value()) 27 | -------------------------------------------------------------------------------- /hikvision/hikvision_infrared.py: -------------------------------------------------------------------------------- 1 | import ctypes 2 | from ctypes import * 3 | import numpy as np 4 | from numpy.ctypeslib import ndpointer 5 | 6 | 7 | def str2arg(path): 8 | path_string = path.encode('utf-8') 9 | arg = c_char_p(path_string) 10 | return arg 11 | 12 | 13 | def get_temper_info(ip='192.168.1.65', username='admin', password='Admin12345'): 14 | f = ctypes.CDLL('./libtemperature.so').getTemperature 15 | f.argtypes = [c_char_p, c_char_p, c_char_p] # 定义输入类型 16 | f.restype = ndpointer(dtype=ctypes.c_float, shape=(288 * 384)) # 定义输出类型 17 | 18 | res = f(str2arg(ip), str2arg(username), str2arg(password)) 19 | res1 = res.reshape(288, 384) # 得到的温度图是个numpy二维数组 20 | xmin = 0 21 | xmax = 384 22 | ymin = 0 23 | ymax = 288 24 | 25 | part = res1[ymin:ymax, xmin:xmax] 26 | 27 | min_temper = np.min(part) 28 | max_temper = np.max(part) 29 | aver_temp = np.mean(part) 30 | 31 | return min_temper, max_temper, aver_temp 32 | 33 | 34 | if __name__ == '__main__': 35 | print(get_temper_info()) 36 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 海康威视Python封装 2 | 3 | ## Usage 4 | 将此代码复制或安装到你的项目即可 5 | 6 | ## Example 7 | ``` 8 | from hikvision.hikvision import HIKVisionSDK 9 | 10 | LIB_DIR = '/home/root/PythonProject/HCNetPythonSDK-Linux/hklib' 11 | 12 | sdk = HIKVisionSDK(lib_dir=LIB_DIR, 13 | username='admin', 14 | ip='192.168.1.124', 15 | password='Admin12345') 16 | try: 17 | sdk.init() 18 | except Exception as e: 19 | print(e) 20 | print('Errcode ', sdk.err_code) 21 | else: 22 | ok = sdk.take_picture('/tmp/jjjj.jpg', release_resources=False) 23 | print('ok1', ok) 24 | ok = sdk.take_picture('/tmp/jjjj3.jpg', release_resources=False) 25 | print('ok2', ok) 26 | value = sdk.get_zoom(release_resources=False) 27 | print('zoom value', value) 28 | ok = sdk.set_zoom(zoom=10, release_resources=True) 29 | print('zoom ok', ok) 30 | 31 | 32 | print(sdk.get_infrared_value()) 33 | ``` 34 | ## Bugs 35 | * 如果不在和`setup.py`同级目录执行`install`会失败 36 | * 使用python的logging模块可能会出现bug 37 | * libiconv.so.2 链接的时候可能会失败 删掉即可 38 | 39 | -------------------------------------------------------------------------------- /hklib/readme.md: -------------------------------------------------------------------------------- 1 | ## 库文件加载说明 2 | 1. lib文件夹里面所有库文件libhcnetsdk.so、libHCCore.so、libssl.so、libcrypto.so、libcrypto.so.1.0.0以及HCNetSDKCom文件夹都需要加载到工程中。 3 | 4 | 2. HCNetSDKCom文件夹如果和libhcnetsdk.so、libhpr.so、libHCCore文件、可执行文件不在同级目录,或者加载失败,可以调用NET_DVR_SetSDKInitCfg(enumType类型赋值为2,lpInBuff对应结构体NET_DVR_LOCAL_SDK_PATH)设置组件库所在路径。 5 | 6 | 3. libcrypto.so、libcrypto.so.1.0.0和libssl.so是开源库,如果库文件加载失败,可以调用NET_DVR_SetSDKInitCfg(enumType类型赋值为3,lpInBuff对应libcrypto.so所在的路径字符串)、NET_DVR_SetSDKInitCfg(enumType类型赋值为4,lpInBuff对应libssl.so所在的路径字符串)指定下这些库文件加载路径。 7 | 8 | 【路径设置的Java示例代码】 9 | //这里是库的绝对路径,请根据实际情况修改,注意改路径必须有访问权限 10 | 11 | //设置HCNetSDKCom组件库所在路径 12 | String strPathCom = "/home/hik/Desktop/JavaDemoLinux64/lib/HCNetSDKCom"; 13 | HCNetSDK.NET_DVR_LOCAL_SDK_PATH struComPath = new HCNetSDK.NET_DVR_LOCAL_SDK_PATH(); 14 | System.arraycopy(strPathCom.getBytes(), 0, struComPath.sPath, 0, strPathCom.length()); 15 | struComPath.write(); 16 | hCNetSDK.NET_DVR_SetSDKInitCfg(2, struComPath.getPointer()); 17 | 18 | //设置libcrypto.so所在路径 19 | HCNetSDK.BYTE_ARRAY ptrByteArrayCrypto = new HCNetSDK.BYTE_ARRAY(256); 20 | String strPathCrypto = "/home/hik/Desktop/JavaDemoLinux64/lib/libcrypto.so"; 21 | System.arraycopy(strPathCrypto.getBytes(), 0, ptrByteArrayCrypto.byValue, 0, strPathCrypto.length()); 22 | ptrByteArrayCrypto.write(); 23 | hCNetSDK.NET_DVR_SetSDKInitCfg(3, ptrByteArrayCrypto.getPointer()); 24 | 25 | //设置libssl.so所在路径 26 | HCNetSDK.BYTE_ARRAY ptrByteArraySsl = new HCNetSDK.BYTE_ARRAY(256); 27 | String strPathSsl = "/home/hik/Desktop/JavaDemoLinux64/lib/libssl.so"; 28 | System.arraycopy(strPathSsl.getBytes(), 0, ptrByteArraySsl.byValue, 0, strPathSsl.length()); 29 | ptrByteArraySsl.write(); 30 | hCNetSDK.NET_DVR_SetSDKInitCfg(4, ptrByteArraySsl.getPointer()); 31 | 32 | 33 | ## Version 34 | `CH-HCNetSDKV6.0.2.35_build20190411_Linux64` -------------------------------------------------------------------------------- /hikvision/hk_struct.py: -------------------------------------------------------------------------------- 1 | import ctypes 2 | 3 | 4 | # 登录需要的结构体 5 | class LPNET_DVR_DEVICEINFO_V30(ctypes.Structure): 6 | _fields_ = [ 7 | ("sSerialNumber", ctypes.c_byte * 48), 8 | ("byAlarmInPortNum", ctypes.c_byte), 9 | ("byAlarmOutPortNum", ctypes.c_byte), 10 | ("byDiskNum", ctypes.c_byte), 11 | ("byDVRType", ctypes.c_byte), 12 | ("byChanNum", ctypes.c_byte), 13 | ("byStartChan", ctypes.c_byte), 14 | ("byAudioChanNum", ctypes.c_byte), 15 | ("byIPChanNum", ctypes.c_byte), 16 | ("byZeroChanNum", ctypes.c_byte), 17 | ("byMainProto", ctypes.c_byte), 18 | ("bySubProto", ctypes.c_byte), 19 | ("bySupport", ctypes.c_byte), 20 | ("bySupport1", ctypes.c_byte), 21 | ("bySupport2", ctypes.c_byte), 22 | ("wDevType", ctypes.c_uint16), 23 | ("bySupport3", ctypes.c_byte), 24 | ("byMultiStreamProto", ctypes.c_byte), 25 | ("byStartDChan", ctypes.c_byte), 26 | ("byStartDTalkChan", ctypes.c_byte), 27 | ("byHighDChanNum", ctypes.c_byte), 28 | ("bySupport4", ctypes.c_byte), 29 | ("byLanguageType", ctypes.c_byte), 30 | ("byVoiceInChanNum", ctypes.c_byte), 31 | ("byStartVoiceInChanNo", ctypes.c_byte), 32 | ("byRes3", ctypes.c_byte * 2), 33 | ("byMirrorChanNum", ctypes.c_byte), 34 | ("wStartMirrorChanNo", ctypes.c_uint16), 35 | ("byRes2", ctypes.c_byte * 2)] 36 | 37 | 38 | # 光学变倍结构体 39 | class NET_DVR_FOCUSMODE_CFG(ctypes.Structure): 40 | _fields_ = [ 41 | ("dwSize", ctypes.c_uint16), 42 | ("byFocusMode", ctypes.c_byte), 43 | ("byAutoFocusMode", ctypes.c_byte), 44 | ("wMinFocusDistance", ctypes.c_uint16), 45 | ("byZoomSpeedLevel", ctypes.c_byte), 46 | ("byFocusSpeedLevel", ctypes.c_byte), 47 | ("byOpticalZoom", ctypes.c_byte), 48 | ("byDigtitalZoom", ctypes.c_byte), 49 | ("fOpticalZoomLevel", ctypes.c_float), 50 | ("dwFocusPos", ctypes.c_uint16), 51 | ("byFocusDefinitionDisplay", ctypes.c_byte), 52 | ("byFocusSensitivity", ctypes.c_byte), 53 | ("byRes1", ctypes.c_byte * 2), 54 | ("dwRelativeFocusPos", ctypes.c_uint16), 55 | ("byRes", ctypes.c_byte * 48), ] 56 | 57 | 58 | # 拍照结构体 59 | class NET_DVR_JPEGPARA(ctypes.Structure): 60 | _fields_ = [ 61 | ("wPicSize", ctypes.c_ushort), 62 | ("wPicQuality", ctypes.c_ushort)] -------------------------------------------------------------------------------- /test/02-拍照.py: -------------------------------------------------------------------------------- 1 | """ 2 | 1 初始化SDK资源 3 | bool NET_DVR_Init() 4 | 2 用户登录 5 | LONG NET_DVR_Login_V30(LPNET_DVR_USER_LOGIN_INFO pLoginInfo, LPNET_DVR_DEVICEINFO_V30 lpDeviceInfo) 6 | 3 获取参数 7 | BOOL NET_DVR_GetDVRConfig(LONG lUserID, DWORD dwCommand,LONG lChannel, LPVOID lpOutBuffer, DWORD dwOutBufferSize, 8 | LPDWORD lpBytesReturned) 9 | 10 | 4 设置参数 11 | BOOL NET_DVR_SetDVRConfig(LONG lUserID, DWORD dwCommand,LONG lChannel, LPVOID 12 | lpInBuffer, DWORD dwInBufferSize) 13 | 14 | #define NET_DVR_GET_FOCUSMODECFG 3305//获取快球聚焦模式信息 15 | 16 | 5 注销用户 17 | 6 释放SDK资源 18 | """ 19 | 20 | import ctypes 21 | import os 22 | import random 23 | 24 | l_user_id = None 25 | l_channel = 1 26 | user_name = 'admin' 27 | user_password = 'Admin12345' 28 | camera_ip = '192.168.1.123' 29 | port = 8000 30 | NET_DVR_GET_FOCUSMODECFG = 3305 31 | NET_DVR_SET_FOCUSMODECFG = 3306 32 | 33 | print(os.getcwd()) 34 | 35 | class NET_DVR_JPEGPARA(ctypes.Structure): 36 | _fields_ = [ 37 | ("wPicSize", ctypes.c_ushort), 38 | ("wPicQuality", ctypes.c_ushort)] 39 | 40 | class LPNET_DVR_DEVICEINFO_V30(ctypes.Structure): 41 | _fields_ = [ 42 | ("sSerialNumber", ctypes.c_byte * 48), 43 | ("byAlarmInPortNum", ctypes.c_byte), 44 | ("byAlarmOutPortNum", ctypes.c_byte), 45 | ("byDiskNum", ctypes.c_byte), 46 | ("byDVRType", ctypes.c_byte), 47 | ("byChanNum", ctypes.c_byte), 48 | ("byStartChan", ctypes.c_byte), 49 | ("byAudioChanNum", ctypes.c_byte), 50 | ("byIPChanNum", ctypes.c_byte), 51 | ("byZeroChanNum", ctypes.c_byte), 52 | ("byMainProto", ctypes.c_byte), 53 | ("bySubProto", ctypes.c_byte), 54 | ("bySupport", ctypes.c_byte), 55 | ("bySupport1", ctypes.c_byte), 56 | ("bySupport2", ctypes.c_byte), 57 | ("wDevType", ctypes.c_uint16), 58 | ("bySupport3", ctypes.c_byte), 59 | ("byMultiStreamProto", ctypes.c_byte), 60 | ("byStartDChan", ctypes.c_byte), 61 | ("byStartDTalkChan", ctypes.c_byte), 62 | ("byHighDChanNum", ctypes.c_byte), 63 | ("bySupport4", ctypes.c_byte), 64 | ("byLanguageType", ctypes.c_byte), 65 | ("byVoiceInChanNum", ctypes.c_byte), 66 | ("byStartVoiceInChanNo", ctypes.c_byte), 67 | ("byRes3", ctypes.c_byte * 2), 68 | ("byMirrorChanNum", ctypes.c_byte), 69 | ("wStartMirrorChanNo", ctypes.c_uint16), 70 | ("byRes2", ctypes.c_byte * 2)] 71 | 72 | 73 | def load_so(so_dir): 74 | print('切换工作目录和库文件所在路径:', so_dir) 75 | os.chdir(so_dir) 76 | lib_hc_net_sdk = ctypes.cdll.LoadLibrary("./libhcnetsdk.so") 77 | ok = lib_hc_net_sdk.NET_DVR_Init() 78 | print("NET_DVR_Init: ", ok) 79 | out_device_info = LPNET_DVR_DEVICEINFO_V30() 80 | l_user_id = lib_hc_net_sdk.NET_DVR_Login_V30(bytes(camera_ip, 'ascii'), 81 | port, 82 | bytes(user_name, 'ascii'), 83 | bytes(user_password, 'ascii'), 84 | ctypes.byref(out_device_info)) 85 | print('out_device_info', out_device_info) 86 | if l_user_id == -1: # 登录失败 87 | error_num = lib_hc_net_sdk.NET_DVR_GetLastError() 88 | if error_num == 7: 89 | print("连接设备失败设备不在线或网络原因引起的连接超时等") 90 | print('err_num', error_num) 91 | res = lib_hc_net_sdk.NET_DVR_Cleanup() 92 | print('NET_DVR_Cleanup', res) 93 | return 94 | else: 95 | print('登录成功') 96 | print("NET_DVR_Login_V30:", l_user_id) 97 | 98 | # 拍照 99 | name = "/tmp/你好阿斯顿aaa.jpg" 100 | obj = NET_DVR_JPEGPARA() 101 | res = lib_hc_net_sdk.NET_DVR_CaptureJPEGPicture(l_user_id, l_channel, ctypes.byref(obj), bytes(name, 'utf-8')) 102 | if not res: 103 | print('拍照失败') 104 | else: 105 | print('拍照成功 %s ' % name) 106 | 107 | # 释放资源 108 | res = lib_hc_net_sdk.NET_DVR_Logout(l_user_id) 109 | if not res: 110 | print('退出失败', lib_hc_net_sdk.NET_DVR_GetLastError()) 111 | res = lib_hc_net_sdk.NET_DVR_Cleanup() 112 | print('NET_DVR_Cleanup', res) 113 | print('NET_DVR_Logout', res) 114 | 115 | 116 | load_so('/home/baloneo/PythonProject/HCNetPythonSDK-Linux/hklib') 117 | -------------------------------------------------------------------------------- /test/01-设置相机变焦.py: -------------------------------------------------------------------------------- 1 | """ 2 | 1 初始化SDK资源 3 | bool NET_DVR_Init() 4 | 2 用户登录 5 | LONG NET_DVR_Login_V30(LPNET_DVR_USER_LOGIN_INFO pLoginInfo, LPNET_DVR_DEVICEINFO_V30 lpDeviceInfo) 6 | 3 获取参数 7 | BOOL NET_DVR_GetDVRConfig(LONG lUserID, DWORD dwCommand,LONG lChannel, LPVOID lpOutBuffer, DWORD dwOutBufferSize, 8 | LPDWORD lpBytesReturned) 9 | 10 | 4 设置参数 11 | BOOL NET_DVR_SetDVRConfig(LONG lUserID, DWORD dwCommand,LONG lChannel, LPVOID 12 | lpInBuffer, DWORD dwInBufferSize) 13 | 14 | #define NET_DVR_GET_FOCUSMODECFG 3305//获取快球聚焦模式信息 15 | 16 | 5 注销用户 17 | 6 释放SDK资源 18 | """ 19 | 20 | import ctypes 21 | import os 22 | import random 23 | 24 | l_user_id = None 25 | l_channel = 1 26 | user_name = 'admin' 27 | user_password = 'Admin12345' 28 | camera_ip = '192.168.1.123' 29 | port = 8000 30 | NET_DVR_GET_FOCUSMODECFG = 3305 31 | NET_DVR_SET_FOCUSMODECFG = 3306 32 | 33 | print(os.getcwd()) 34 | 35 | 36 | class LPNET_DVR_DEVICEINFO_V30(ctypes.Structure): 37 | _fields_ = [ 38 | ("sSerialNumber", ctypes.c_byte * 48), 39 | ("byAlarmInPortNum", ctypes.c_byte), 40 | ("byAlarmOutPortNum", ctypes.c_byte), 41 | ("byDiskNum", ctypes.c_byte), 42 | ("byDVRType", ctypes.c_byte), 43 | ("byChanNum", ctypes.c_byte), 44 | ("byStartChan", ctypes.c_byte), 45 | ("byAudioChanNum", ctypes.c_byte), 46 | ("byIPChanNum", ctypes.c_byte), 47 | ("byZeroChanNum", ctypes.c_byte), 48 | ("byMainProto", ctypes.c_byte), 49 | ("bySubProto", ctypes.c_byte), 50 | ("bySupport", ctypes.c_byte), 51 | ("bySupport1", ctypes.c_byte), 52 | ("bySupport2", ctypes.c_byte), 53 | ("wDevType", ctypes.c_uint16), 54 | ("bySupport3", ctypes.c_byte), 55 | ("byMultiStreamProto", ctypes.c_byte), 56 | ("byStartDChan", ctypes.c_byte), 57 | ("byStartDTalkChan", ctypes.c_byte), 58 | ("byHighDChanNum", ctypes.c_byte), 59 | ("bySupport4", ctypes.c_byte), 60 | ("byLanguageType", ctypes.c_byte), 61 | ("byVoiceInChanNum", ctypes.c_byte), 62 | ("byStartVoiceInChanNo", ctypes.c_byte), 63 | ("byRes3", ctypes.c_byte * 2), 64 | ("byMirrorChanNum", ctypes.c_byte), 65 | ("wStartMirrorChanNo", ctypes.c_uint16), 66 | ("byRes2", ctypes.c_byte * 2)] 67 | 68 | 69 | # 光学变倍结构体 70 | class NET_DVR_FOCUSMODE_CFG(ctypes.Structure): 71 | _fields_ = [ 72 | ("dwSize", ctypes.c_uint16), 73 | ("byFocusMode", ctypes.c_byte), 74 | ("byAutoFocusMode", ctypes.c_byte), 75 | ("wMinFocusDistance", ctypes.c_uint16), 76 | ("byZoomSpeedLevel", ctypes.c_byte), 77 | ("byFocusSpeedLevel", ctypes.c_byte), 78 | ("byOpticalZoom", ctypes.c_byte), 79 | ("byDigtitalZoom", ctypes.c_byte), 80 | ("fOpticalZoomLevel", ctypes.c_float), 81 | ("dwFocusPos", ctypes.c_uint16), 82 | ("byFocusDefinitionDisplay", ctypes.c_byte), 83 | ("byFocusSensitivity", ctypes.c_byte), 84 | ("byRes1", ctypes.c_byte * 2), 85 | ("dwRelativeFocusPos", ctypes.c_uint16), 86 | ("byRes", ctypes.c_byte * 48), ] 87 | 88 | def test_load(): 89 | pass 90 | 91 | 92 | def load_sdk(): 93 | sos = os.listdir('/home/baloneo/PythonProject/HCNetPythonSDK-Linux/lib/HCNetSDKCom') 94 | so_path = [] 95 | for i in sos: 96 | so_path.append('/home/baloneo/PythonProject/HCNetPythonSDK-Linux/lib/HCNetSDKCom/'+i) 97 | 98 | # for i in so_path: 99 | # print(ctypes.cdll.LoadLibrary(i)) 100 | 101 | sos = os.listdir('/home/baloneo/PythonProject/HCNetPythonSDK-Linux/lib') 102 | so2_path = [] 103 | for i in sos: 104 | if str(i).endswith('.so'): 105 | so2_path.append('/home/baloneo/PythonProject/HCNetPythonSDK-Linux/lib/'+i) 106 | 107 | print('soss', so2_path) 108 | for i in so2_path: 109 | print(ctypes.cdll.LoadLibrary(i)) 110 | # ctypes.cdll.LoadLibrary('/home/baloneo/PythonProject/HCNetPythonSDK-Linux/lib/libAudioRender.so') 111 | 112 | 113 | def load_so(so_dir): 114 | print('切换工作目录和库文件所在路径:', so_dir) 115 | os.chdir(so_dir) 116 | # lib_hc_core = ctypes.cdll.LoadLibrary("./libHCCore.so") 117 | # print(dir(lib_hc_core)) 118 | # lib_hc_core.NET_DVR_Init() 119 | # ctypes.cdll.LoadLibrary("/home/baloneo/PythonProject/HCNetPythonSDK-Linux/lib/libcrypto.so.1.0.0") 120 | # ctypes.cdll.LoadLibrary("/home/baloneo/PythonProject/HCNetPythonSDK-Linux/lib/libcrypto.so") 121 | 122 | # ctypes.cdll.LoadLibrary("/home/baloneo/PythonProject/HCNetPythonSDK-Linux/lib/libssl.so") 123 | 124 | lib_hc_net_sdk = ctypes.cdll.LoadLibrary("./libhcnetsdk.so") 125 | ok = lib_hc_net_sdk.NET_DVR_Init() 126 | print("NET_DVR_Init: ", ok) 127 | out_device_info = LPNET_DVR_DEVICEINFO_V30() 128 | l_user_id = lib_hc_net_sdk.NET_DVR_Login_V30(bytes(camera_ip, 'ascii'), 129 | port, 130 | bytes(user_name, 'ascii'), 131 | bytes(user_password, 'ascii'), 132 | ctypes.byref(out_device_info)) 133 | print('out_device_info', out_device_info) 134 | if l_user_id == -1: # 登录失败 135 | error_num = lib_hc_net_sdk.NET_DVR_GetLastError() 136 | if error_num == 7: 137 | print("连接设备失败设备不在线或网络原因引起的连接超时等") 138 | print('err_num', error_num) 139 | res = lib_hc_net_sdk.NET_DVR_Cleanup() 140 | print('NET_DVR_Cleanup', res) 141 | return 142 | else: 143 | print('登录成功') 144 | print("NET_DVR_Login_V30:", l_user_id) 145 | 146 | # 获取变倍数值 147 | struct_docus_cfg = NET_DVR_FOCUSMODE_CFG() 148 | dw_returned = ctypes.c_uint16(0) 149 | res = lib_hc_net_sdk.NET_DVR_GetDVRConfig(l_user_id, 150 | NET_DVR_GET_FOCUSMODECFG, 151 | l_channel, 152 | ctypes.byref(struct_docus_cfg), 153 | 255, 154 | ctypes.byref(dw_returned)) 155 | if not res: 156 | print('获取变倍失败') 157 | print('获取到的变焦值:', struct_docus_cfg.fOpticalZoomLevel, "dw_returned", dw_returned) 158 | 159 | # 设置变倍 160 | new_zoom = random.randint(1, 12) 161 | if struct_docus_cfg.fOpticalZoomLevel == new_zoom: 162 | print('忽略 已经是这个值') 163 | struct_docus_cfg.fOpticalZoomLevel = new_zoom 164 | res = lib_hc_net_sdk.NET_DVR_SetDVRConfig(l_user_id, 165 | NET_DVR_SET_FOCUSMODECFG, 166 | l_channel, 167 | ctypes.byref(struct_docus_cfg), 168 | 255) 169 | if not res: 170 | print('变倍失败') 171 | print('变倍成功 值为', struct_docus_cfg.fOpticalZoomLevel) 172 | 173 | # 释放资源 174 | res = lib_hc_net_sdk.NET_DVR_Logout(l_user_id) 175 | if not res: 176 | print('退出失败', lib_hc_net_sdk.NET_DVR_GetLastError()) 177 | res = lib_hc_net_sdk.NET_DVR_Cleanup() 178 | print('NET_DVR_Cleanup', res) 179 | print('NET_DVR_Logout', res) 180 | 181 | 182 | # load_sdk() 183 | load_so('/home/baloneo/PythonProject/HCNetPythonSDK-Linux/hklib') 184 | -------------------------------------------------------------------------------- /hikvision/hikvision.py: -------------------------------------------------------------------------------- 1 | import os 2 | import ctypes 3 | import functools 4 | from .hk_define import * 5 | from .hk_struct import LPNET_DVR_DEVICEINFO_V30, NET_DVR_FOCUSMODE_CFG, NET_DVR_JPEGPARA 6 | from .hikvision_infrared import get_temper_info 7 | 8 | 9 | # 禁止使用logging模块 10 | 11 | 12 | def _release_wrapper(func): 13 | @functools.wraps(func) 14 | def inner(*args, **kwargs): 15 | res = func(*args, **kwargs) 16 | if kwargs.get('release_resources', True): 17 | if args[0].user_id != -1: 18 | args[0]._destroy() 19 | return res 20 | 21 | return inner 22 | 23 | 24 | class HIKVisionSDK(object): 25 | def __init__(self, lib_dir, ip, username, password, port=8000, channel=1, debug=True): 26 | self.lib_dir = lib_dir 27 | self.old_cwd = os.getcwd() 28 | self.ip = ip 29 | self.username = username 30 | self.password = password 31 | self.port = port 32 | self.user_id = -1 33 | self.hk_so_lib = None 34 | self.channel = channel 35 | self.err_code = 0 36 | self.debug = debug 37 | 38 | def print_log(self, msg): 39 | if self.debug: 40 | print(msg) 41 | 42 | def init(self): 43 | """raise a exception if error""" 44 | self.print_log('开始改变工作目录 %s' % self.lib_dir) 45 | os.chdir(self.lib_dir) 46 | self.print_log('开始加载libhcnetsdk.so') 47 | self.hk_so_lib = ctypes.cdll.LoadLibrary("./libhcnetsdk.so") 48 | ok = self.hk_so_lib.NET_DVR_Init() 49 | if not ok: 50 | self.err_code = -1 51 | raise Exception("<<<海康sdk初始化失败") 52 | self._login() 53 | return self 54 | 55 | def _login(self): 56 | self.print_log('开始登录') 57 | device_info = LPNET_DVR_DEVICEINFO_V30() 58 | result = self.hk_so_lib.NET_DVR_Login_V30(bytes(self.ip, 'ascii'), 59 | self.port, 60 | bytes(self.username, 'ascii'), 61 | bytes(self.password, 'ascii'), 62 | ctypes.byref(device_info)) 63 | if result == -1: 64 | error_num = self.hk_so_lib.NET_DVR_GetLastError() 65 | self.err_code = error_num 66 | self._destroy(logout=False) 67 | raise Exception("<<<海康SDK调用错误 ERRCODE: %s" % error_num) 68 | self.print_log('登录成功') 69 | self.user_id = result 70 | 71 | def _destroy(self, logout=True): 72 | if logout: 73 | self.print_log('>>>开始注销资源') 74 | res = self.hk_so_lib.NET_DVR_Logout(self.user_id) 75 | if not res: 76 | self.print_log('<<>>开始释放资源') 78 | res = self.hk_so_lib.NET_DVR_Cleanup() 79 | if not res: 80 | self.print_log('<<<释放资源失败') 81 | os.chdir(self.old_cwd) 82 | self.print_log('>>>成功还原工作目录 %s' % os.getcwd()) 83 | 84 | @_release_wrapper 85 | def take_picture(self, pic_pathname, release_resources=True) -> bool: 86 | if self.user_id == -1: 87 | self.print_log('未初始化或者初始化失败') 88 | return False 89 | self.print_log('开始拍照 %s' % pic_pathname) 90 | obj = NET_DVR_JPEGPARA() 91 | result = self.hk_so_lib.NET_DVR_CaptureJPEGPicture(self.user_id, 92 | self.channel, 93 | ctypes.byref(obj), 94 | bytes(pic_pathname, 'utf-8')) 95 | 96 | if not result: 97 | error_num = self.hk_so_lib.NET_DVR_GetLastError() 98 | self.print_log('<<<拍照失败 ERRCODE: %s' % error_num) 99 | return False 100 | self.print_log('拍照成功') 101 | return True 102 | 103 | @_release_wrapper 104 | def get_zoom(self, release_resources=True) -> int: 105 | """-1 if failure""" 106 | if self.user_id == -1: 107 | self.print_log('<<<未初始化或者初始化失败 user_id %s' % self.user_id) 108 | return False 109 | self.print_log('开始获取变焦') 110 | struct_cfg = NET_DVR_FOCUSMODE_CFG() 111 | dw_returned = ctypes.c_uint16(0) 112 | result = self.hk_so_lib.NET_DVR_GetDVRConfig(self.user_id, 113 | NET_DVR_GET_FOCUSMODECFG, 114 | self.channel, 115 | ctypes.byref(struct_cfg), 116 | 255, 117 | ctypes.byref(dw_returned)) 118 | if not result: 119 | self.print_log('<<<获取变焦失败') 120 | return -1 121 | self.print_log('value %s' % struct_cfg.fOpticalZoomLevel) 122 | return struct_cfg.fOpticalZoomLevel 123 | 124 | @_release_wrapper 125 | def set_zoom(self, zoom, release_resources=True) -> bool: 126 | if self.hk_so_lib == -1: 127 | self.print_log('<<<未初始化或者初始化失败') 128 | return False 129 | self.print_log('开始设置变倍 zoom %s' % zoom) 130 | struct_cfg = NET_DVR_FOCUSMODE_CFG() 131 | dw_returned = ctypes.c_uint16(0) 132 | result = self.hk_so_lib.NET_DVR_GetDVRConfig(self.user_id, 133 | NET_DVR_GET_FOCUSMODECFG, 134 | self.channel, 135 | ctypes.byref(struct_cfg), 136 | 255, 137 | ctypes.byref(dw_returned)) 138 | if not result: 139 | self.print_log('<<<获取变倍失败') 140 | return False 141 | cur_zoom = struct_cfg.fOpticalZoomLevel 142 | self.print_log("当前变倍值为 {} ".format(cur_zoom)) 143 | 144 | if cur_zoom == zoom: 145 | self.print_log('已经是相同的倍值 %s' % cur_zoom) 146 | return True 147 | 148 | if cur_zoom == 0: 149 | self.print_log('此摄像头不支持变焦') 150 | return False 151 | 152 | struct_cfg.fOpticalZoomLevel = ctypes.c_float(zoom) 153 | result = self.hk_so_lib.NET_DVR_SetDVRConfig(self.user_id, 154 | NET_DVR_SET_FOCUSMODECFG, 155 | self.channel, 156 | ctypes.byref(struct_cfg), 157 | 255) 158 | if not result: 159 | self.print_log('<<<变倍失败') 160 | return False 161 | self.print_log('success %s' % zoom) 162 | return True 163 | 164 | def get_infrared_value(self) -> tuple: 165 | os.chdir(self.lib_dir) 166 | self.print_log('开始获取红外') 167 | try: 168 | min_temper, max_temper, aver_temp = get_temper_info(ip=self.ip, username=self.username, 169 | password=self.password) 170 | except Exception as e: 171 | self.print_log(e) 172 | min_temper, max_temper, aver_temp = -1, -1, -1 173 | self.print_log(" min_temper {0}, max_temper {1}, aver_temp {2}".format(min_temper, max_temper, aver_temp)) 174 | os.chdir(self.old_cwd) 175 | return min_temper, max_temper, aver_temp 176 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------