Java Hikvision サーマルイメージングの温度取得、音声インターコム テスト、アクセス制御要員の機能セットの取得、温度測定の補助照明照明、テスト機器のキャプチャ、追加の全画面温度測定データ、およびその他の Java コード例

温度を取得するには、長期接続温度測定、手動温度測定、全画面温度測定など、いくつかの方法があります。温度を取得する方法は、デバイスによって異なります。注意: 友人によっては、異なる SDK を使用している可能性があります
。実行時にエラーが報告されます。

package Test1;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;

import Test1.GeneralFunction.*;
import Test1.ACS.*;
import Test1.PTZ.GetPreSetName;
import Test1.PTZ.PTZAbsoluteEX;
import Test1.Thermometry.*;
import com.sun.jna.NativeLong;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import com.sun.jna.Pointer;
import com.sun.jna.ptr.IntByReference;

/**
 * 
 */

public class Test1 {

	static HCNetSDK hCNetSDK = HCNetSDK.INSTANCE;
	public static int lUserID = -1;//用户句柄
	static int dwState = -1; //人员信息状态
	static int dwFaceState = -1; //下发人脸数据状态
	static int iCharEncodeType = 0;//设备字符集

	/**
	 * @param args
	 * @throws UnsupportedEncodingException 
	 * @throws InterruptedException 
	 * @throws JSONException
	 */
	public static void main(String[] args) throws UnsupportedEncodingException, InterruptedException, JSONException  {
		/*初始SDK*/
		hCNetSDK.NET_DVR_Init();
		hCNetSDK.NET_DVR_SetLogToFile(3, "C:\\第三方demo\\海康视频温度\\1-ClientDemo\\ClientDemo-NetBeansPro\\lib\\HCNetSDK.dll", true);
		//TODO 库加载代码 设置异常消息回调 报警分离

		/*登陆*/
		Login login = new Login();
		lUserID = login.getlUserID("192.168.1.92",(short)8000,"user","pwd");


		//获取门禁人员能力集
		//GetACSAbility getACSability = new GetACSAbility();
		//getACSability.getACSAbility(lUserID);

		/*测试语音对讲*/
//		VoiceTalk voiceTalk = new VoiceTalk();
//		voiceTalk.StartVoiceTalk(lUserID,1,true);
//		voiceTalk.StartVoiceTalk(lUserID,1,true);

		/*按时间下载文件*/
	//	GetFileByTime getFileByTime = new GetFileByTime();
	//	getFileByTime.getFileByTime(lUserID, "E://pic//video.mp4",1,2021,3,25,11,44,2,2021,3,25,11,44,12);

		/*获取高精度PTZ绝对位置配置*/
//		PTZAbsoluteEX getPTZAbsoluteEX = new PTZAbsoluteEX();
//		getPTZAbsoluteEX.ptzAbsoluteEX(lUserID);

		/*获取预置点名称配置*/
//		GetPreSetName getPreSetName = new GetPreSetName();
//		getPreSetName.getPreSetName(lUserID,new NativeLong(1),(short)3);

		/*测温补光灯点亮*/
		//LightPTZControlWithSpeed lightPTZControlWithSpeed = new LightPTZControlWithSpeed();
		//lightPTZControlWithSpeed.lightPTZControlWithSpeed(lUserID,1,2,1,2);

       /*测试测温基本参数配置和获取*/
//		BasicParam basicParam = new BasicParam();
//		basicParam.basicParam(lUserID,2);

        /*测专家测温获取及配置*/
//       SetROI setROI = new SetROI();
//       setROI.setROI(lUserID,2);

		/*测试手动获取测温规则温度信息*/
//		ThreadGetOnceTempData threadGetOnceTempData = new ThreadGetOnceTempData();
//		threadGetOnceTempData.threadGetOnceTempData(lUserID, new NativeLong(1));

		/*测试实时获取测温规则温度信息*/
		RealtimeThermometry realtimeThermometry = new RealtimeThermometry();
		realtimeThermometry.realtimeThermometry(lUserID,2,(byte)0,(byte)1,(short)1);
//		while (true)
//		{
//
//		}

		/*测试设备抓图附加全屏测温数据*/
//		JpegWithAppendData jpegWithAppendData = new JpegWithAppendData();
//		jpegWithAppendData.jpegWithAppendData(lUserID, 202);

		/*测试全屏测温*/
//		P2PRealData p2PRealData = new P2PRealData();
//		p2PRealData.p2PRealData(lUserID,2);

		/*测试获取专家测温配置参数*/
//		ThermometryPresetInfo thermometryPresetInfo = new ThermometryPresetInfo();
//		thermometryPresetInfo.thermometryPresetInfo(lUserID,2);

		/** 登出 **/
		if(hCNetSDK.NET_DVR_Logout(lUserID)){
			System.out.println("登出成功!!!");
		}
	}
	 
}//Test1  Class结束

温度測定ルールの温度情報をリアルタイムで取得します。

package Test1.Thermometry;

import Test1.HCNetSDK;
import com.sun.jna.Pointer;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class RealtimeThermometry {
    
    
    static HCNetSDK hCNetSDK = HCNetSDK.INSTANCE;
    public FileOutputStream thermometryupload = null;
    public static FRemoteConfigCallback fRemoteConfigCallback = null;

    public void realtimeThermometry(int lUserID, int iChannelNum, byte RuleID, byte Mode, short Interval) {
    
    
        long lHandle = 0;
        HCNetSDK.NET_DVR_REALTIME_THERMOMETRY_COND m_strRealtimeThermometryCond = new HCNetSDK.NET_DVR_REALTIME_THERMOMETRY_COND();
        m_strRealtimeThermometryCond.dwSize = m_strRealtimeThermometryCond.size();
        m_strRealtimeThermometryCond.dwChan = iChannelNum;
        m_strRealtimeThermometryCond.byRuleID = RuleID;//规则ID,0代表获取全部规则,具体规则ID从1开始
        m_strRealtimeThermometryCond.byMode = Mode;//长连接模式:0-保留;1-定时模式;2-温差模式
        m_strRealtimeThermometryCond.wInterval = Interval;//上传间隔(仅温差模式支持),取值范围:1-3600 秒,填0则默认3600S上传一次

        fRemoteConfigCallback = new FRemoteConfigCallback();
        Pointer pUserData = null;
        m_strRealtimeThermometryCond.write();

        lHandle = hCNetSDK.NET_DVR_StartRemoteConfig(lUserID, HCNetSDK.NET_DVR_GET_REALTIME_THERMOMETRY, m_strRealtimeThermometryCond.getPointer(), m_strRealtimeThermometryCond.dwSize, fRemoteConfigCallback, pUserData);
        if (lHandle < 0) {
    
    
            System.out.println("建立实时测温规则获取长连接失败,错误号:" + hCNetSDK.NET_DVR_GetLastError());
            return;
        }
        System.out.println("建立实时测温规则获取长连接成功!");
        try {
    
    
            Thread.sleep(10000);
        } catch (InterruptedException e) {
    
    
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    /******************************************************************************
     * 内部类:   FRemoteConfigCallback
     * 状态回调函数
     ******************************************************************************/

    public class FRemoteConfigCallback implements HCNetSDK.FRemoteConfigCallback {
    
    
        //状态回调函数
        public void invoke(int dwType, Pointer lpBuffer, int dwBufferLen, Pointer pUserData) {
    
    
            System.out.println("长连接回调获取数据类型:" + dwType);
            switch (dwType) {
    
    
                case 0://NET_SDK_CALLBACK_TYPE_STATUS
                    HCNetSDK.REMOTECONFIGSTATUS_THERMOMETRY struCfgStatus = new HCNetSDK.REMOTECONFIGSTATUS_THERMOMETRY();
                    struCfgStatus.write();
                    Pointer pCfgStatus = struCfgStatus.getPointer();
                    pCfgStatus.write(0, lpBuffer.getByteArray(0, struCfgStatus.size()), 0, struCfgStatus.size());
                    struCfgStatus.read();
                    int iStatus = 0;
                    for (int i = 0; i < 4; i++) {
    
    
                        int ioffset = i * 8;
                        int iByte = struCfgStatus.byStatus[i] & 0xff;
                        iStatus = iStatus + (iByte << ioffset);
                    }

                    switch (iStatus) {
    
    
                        case 1000:// NET_SDK_CALLBACK_STATUS_SUCCESS
                            System.out.println("手动测温实时获取成功,dwStatus:" + iStatus);
                            try {
    
    
                                thermometryupload.close();
                            } catch (IOException e) {
    
    
                                e.printStackTrace();
                            }
                            break;
                        case 1001:
                            System.out.println("正在实时获取手动测温,dwStatus:" + iStatus);
                            break;
                        case 1002:
                            int iErrorCode = 0;
                            for (int i = struCfgStatus.size() - 3; i <= struCfgStatus.size(); i++) {
    
    
                                int ioffset = i * 8;
                                int iByte = struCfgStatus.byErrorCode[i] & 0xff;
                                iErrorCode = iErrorCode + (iByte << ioffset);
                            }
                            System.out.println("手动测温实时获取失败, dwStatus:" + iStatus + "错误号:" + iErrorCode);
                            break;
                    }
                    break;
                case 2://NET_SDK_CALLBACK_TYPE_DATA
                    HCNetSDK.NET_DVR_THERMOMETRY_UPLOAD m_struThermometryUpload = new HCNetSDK.NET_DVR_THERMOMETRY_UPLOAD();
                    m_struThermometryUpload.write();
                    Pointer pmt = m_struThermometryUpload.getPointer();
                    pmt.write(0, lpBuffer.getByteArray(0, m_struThermometryUpload.size()), 0, m_struThermometryUpload.size());
                    m_struThermometryUpload.read();

                    try {
    
    
                        if (thermometryupload == null) {
    
    
                            thermometryupload = new FileOutputStream(".\\pic\\" + "thermometryupload" + ".txt");
                        }

                        for (int i = 0; i <= 21; i++) {
    
    
                            String strTemp = "规则ID:" + m_struThermometryUpload.byRuleID + "规则名称:" + m_struThermometryUpload.szRuleName
                                    + "规则类型:" + m_struThermometryUpload.byRuleCalibType + "预置点号:" + m_struThermometryUpload.wPresetNo
                                    + "点温度:" + m_struThermometryUpload.struPointThermCfg.fTemperature + "点坐标:" + m_struThermometryUpload.struPointThermCfg.struPoint.fX + "," + m_struThermometryUpload.struPointThermCfg.struPoint.fY
                                    + "区域最高温度:" + m_struThermometryUpload.struLinePolygonThermCfg.fMaxTemperature + "区域最低温度:" + m_struThermometryUpload.struLinePolygonThermCfg.fMinTemperature
                                    + "区域平均温度:" + m_struThermometryUpload.struLinePolygonThermCfg.fAverageTemperature + "区域温差:" + m_struThermometryUpload.struLinePolygonThermCfg.fTemperatureDiff
                                    + "区域边界点坐标:" + m_struThermometryUpload.struLinePolygonThermCfg.struRegion.struPos[0].fX + "," + m_struThermometryUpload.struLinePolygonThermCfg.struRegion.struPos[0].fY
                                    + m_struThermometryUpload.struLinePolygonThermCfg.struRegion.struPos[1].fX + "," + m_struThermometryUpload.struLinePolygonThermCfg.struRegion.struPos[1].fY + "/"
                                    + m_struThermometryUpload.struLinePolygonThermCfg.struRegion.struPos[2].fX + "," + m_struThermometryUpload.struLinePolygonThermCfg.struRegion.struPos[2].fY + "/"
                                    + m_struThermometryUpload.struLinePolygonThermCfg.struRegion.struPos[3].fX + "," + m_struThermometryUpload.struLinePolygonThermCfg.struRegion.struPos[3].fY + "/"
                                    + m_struThermometryUpload.struLinePolygonThermCfg.struRegion.struPos[4].fX + "," + m_struThermometryUpload.struLinePolygonThermCfg.struRegion.struPos[4].fY + "/"
                                    + m_struThermometryUpload.struLinePolygonThermCfg.struRegion.struPos[5].fX + "," + m_struThermometryUpload.struLinePolygonThermCfg.struRegion.struPos[5].fY + "/"
                                    + m_struThermometryUpload.struLinePolygonThermCfg.struRegion.struPos[6].fX + "," + m_struThermometryUpload.struLinePolygonThermCfg.struRegion.struPos[6].fY + "/"
                                    + m_struThermometryUpload.struLinePolygonThermCfg.struRegion.struPos[7].fX + "," + m_struThermometryUpload.struLinePolygonThermCfg.struRegion.struPos[7].fY + "/"
                                    + "\n";
                            System.out.println(strTemp);
                            byte[] byte1 = strTemp.getBytes();
                            thermometryupload.write(byte1);
                        }

                    } catch (FileNotFoundException e) {
    
    
                        System.out.println("路径不存在");
                    } catch (IOException e) {
    
    
                        System.out.println("异常");
                    }
            }
        }
    }
}

温度測定ルールの温度情報を手動で取得します。

package Test1.Thermometry;

import Test1.HCNetSDK;
import com.sun.jna.NativeLong;
import com.sun.jna.ptr.IntByReference;

import javax.swing.*;


public class ThreadGetOnceTempData {
    
    

    static HCNetSDK hCNetSDK = HCNetSDK.INSTANCE;

    public void threadGetOnceTempData(int lUserID, NativeLong RuleID)
    {
    
    
        HCNetSDK.NET_DVR_THERMOMETRYRULE_TEMPERATURE_INFO m_TherTemInfo = new HCNetSDK.NET_DVR_THERMOMETRYRULE_TEMPERATURE_INFO();
        IntByReference lpBytesReturned = new IntByReference(0);
        if(!hCNetSDK.NET_DVR_GetDVRConfig(lUserID,HCNetSDK.NET_DVR_GET_THERMOMETRYRULE_TEMPERATURE_INFO,RuleID,m_TherTemInfo.getPointer(),16*1024,lpBytesReturned))
        {
    
    
            System.out.println( "手动获取测温规则温度信息失败,错误号:" + hCNetSDK.NET_DVR_GetLastError());
        }
        else
        {
    
    
            m_TherTemInfo.read();
            System.out.println( "手动获取测温规则温度信息成功!");

            System.out.println("最高温:" + m_TherTemInfo.fMaxTemperature + " 最低温:" + m_TherTemInfo.fMinTemperature + " 平均温:"+m_TherTemInfo.fAverageTemperature
                    + " 最高温点坐标:(" + m_TherTemInfo.struHighestPoint.fX + "," + m_TherTemInfo.struHighestPoint.fY + ")"
                    + " 最低温点坐标:(" + m_TherTemInfo.struLowestPoint.fX + "," + m_TherTemInfo.struLowestPoint.fY + ")");
        }
    }

}

アクセス制御担当者の機能セットを取得します。

package Test1.ACS;

import Test1.HCNetSDK;

public class GetACSAbility {
    
    
    static HCNetSDK hCNetSDK = HCNetSDK.INSTANCE;
    public static final int ISAPI_DATA_LEN = 1024*1024;
    public static final int ISAPI_STATUS_LEN = 4*4096;
    public static final int BYTE_ARRAY_LEN = 1024;

    public void getACSAbility(int lUserID)
    {
    
    
        String strURL = "GET /ISAPI/AccessControl/UserInfo/capabilities?format=json";
        HCNetSDK.BYTE_ARRAY ptrUrl = new HCNetSDK.BYTE_ARRAY(BYTE_ARRAY_LEN);
        System.arraycopy(strURL.getBytes(), 0, ptrUrl.byValue, 0, strURL.length());
        ptrUrl.write();

        //获取能力集时输入参数为空即可
        /*HCNetSDK.BYTE_ARRAY ptrInBuffer = new HCNetSDK.BYTE_ARRAY(ISAPI_DATA_LEN);
        ptrInBuffer.read();
        String strInbuffer = "";
        ptrInBuffer.byValue = strInbuffer.getBytes();
        ptrInBuffer.write();
        */

        HCNetSDK.NET_DVR_XML_CONFIG_INPUT struXMLInput = new HCNetSDK.NET_DVR_XML_CONFIG_INPUT();
        struXMLInput.read();
        struXMLInput.dwSize = struXMLInput.size();
        struXMLInput.lpRequestUrl = ptrUrl.getPointer();
        struXMLInput.dwRequestUrlLen = ptrUrl.byValue.length;
        struXMLInput.lpInBuffer = null;//ptrInBuffer.getPointer();
        struXMLInput.dwInBufferSize = 0;//ptrInBuffer.byValue.length;
        struXMLInput.write();

        HCNetSDK.BYTE_ARRAY ptrStatusByte = new HCNetSDK.BYTE_ARRAY(ISAPI_STATUS_LEN);
        ptrStatusByte.read();

        HCNetSDK.BYTE_ARRAY ptrOutByte = new HCNetSDK.BYTE_ARRAY(ISAPI_DATA_LEN);
        ptrOutByte.read();

        HCNetSDK.NET_DVR_XML_CONFIG_OUTPUT struXMLOutput = new HCNetSDK.NET_DVR_XML_CONFIG_OUTPUT();
        struXMLOutput.read();
        struXMLOutput.dwSize = struXMLOutput.size();
        struXMLOutput.lpOutBuffer = ptrOutByte.getPointer();
        struXMLOutput.dwOutBufferSize = ptrOutByte.size();
        struXMLOutput.lpStatusBuffer = ptrStatusByte.getPointer();
        struXMLOutput.dwStatusSize  = ptrStatusByte.size();
        struXMLOutput.write();

        if(!hCNetSDK.NET_DVR_STDXMLConfig(lUserID, struXMLInput, struXMLOutput))
        {
    
    
            int iErr = hCNetSDK.NET_DVR_GetLastError();
            System.out.println("NET_DVR_STDXMLConfig失败,错误号:" + iErr);
            return;

        }
        else
        {
    
    
            struXMLOutput.read();
            ptrOutByte.read();
            ptrStatusByte.read();
            String strOutXML = new String(ptrOutByte.byValue).trim();
            System.out.println("获取设备能力集输出结果:" + strOutXML);
            String strStatus = new String(ptrStatusByte.byValue).trim();
            System.out.println("获取设备能力集返回状态:" + strStatus);
        }
    }
}

フィルライトをオンにする:

package Test1.GeneralFunction;

import Test1.HCNetSDK;
import com.sun.jna.NativeLong;

public class LightPTZControlWithSpeed {
    
    
    static HCNetSDK hCNetSDK = HCNetSDK.INSTANCE;

    public void lightPTZControlWithSpeed(int lUserID, int iChannelNum,int dwPTZCommand,int dwStop,int dwSpeed)
    {
    
    
        if(!hCNetSDK.NET_DVR_PTZControlWithSpeed_Other(lUserID,iChannelNum,dwPTZCommand,dwStop,dwSpeed))
        {
    
    
            System.out.println( "PTZ控制参数设置失败,错误号:" + hCNetSDK.NET_DVR_GetLastError());
        }
        else
        {
    
    
            System.out.println( "PTZ控制参数设置成功,为:" + dwPTZCommand + ":"+dwStop);
        }
    }
}

おすすめ

転載: blog.csdn.net/LetMeKangKang/article/details/119489850