• 海康威视热成像实时测温java - 23版


    在20年写了一篇实时测温demo博客,看来帮了不少人。今天刚好又有需求,需要采温。也碰到了不少问题,特此记录

    1、环境

    摄像头:海康 型号:DS-2TD2528T-7/Q  序列:EA0406775

    服务器:winServer 

    JDK8

    2、调试

    之前写的demo下载下来。

    先把lib 放在D盘下,这边的lib仅限于win64的,如果是其他平台。

    海康官网平台下载

    后续把账号密码一改,直接发布试一下。

    结果

    排查故障

    询问海康

    配置开启功能

    登录之后,配置

    有些用户会发现,没有本地这一项,那么请看下图。下载插件,刷新即可。

    等我配置好之后,重启之后还是code11。静下心来,自己研究程序。

    应该是哪里传值不对。

    海康的人让我下载Demo看下,其实就是他们的一个测试exe。间接了解海康测温原理,抓图分析。这个工具可以很明显是摄像头没有配置好,还是程序有问题。

    这边可以看到,是程序自己没有配置好。

    开始琢磨。byRuleID 规则ID是1,我不是很明白 ,dwChan通道ID 是2没有问题。

    最后查看相关文档,规则ID 普通模式下只能是0。专家模式下如果只获取对应ID的温度就输入对应规则ID。看图

    普通模式和专家模式是互斥的。

    最后程序调整下。成功了

    3、上代码

    runnable

    1. /**
    2. * @author cmy
    3. * @date 2023/9/14 14:03
    4. */
    5. @Slf4j
    6. public class ReadDataThread implements Runnable {
    7. HCNetSDK hCNetSDK;
    8. ThermInfoCallback thermInfoCallback;
    9. DeviceBean bean;
    10. public ReadDataThread(HCNetSDK hCNetSDK, ThermInfoCallback thermInfoCallback, DeviceBean bean){
    11. this.hCNetSDK = hCNetSDK;
    12. this.thermInfoCallback = thermInfoCallback;
    13. this.bean = bean;
    14. }
    15. @Override
    16. public void run() {
    17. HCNetSDK.NET_DVR_DEVICEINFO_V30 m_strDeviceInfo = new HCNetSDK.NET_DVR_DEVICEINFO_V30();
    18. NativeLong lUserID = new NativeLong(-1);
    19. lUserID = hCNetSDK.NET_DVR_Login_V30(bean.getIp(),
    20. bean.getPort(), bean.getUserName(), bean.getPassWord(), m_strDeviceInfo);
    21. if (lUserID.longValue() == -1){
    22. log.error(bean.getIp()+"登录失败,错误码为"+hCNetSDK.NET_DVR_GetLastError());
    23. return;
    24. }else{
    25. log.info(bean.getIp()+"登录成功!"+lUserID);
    26. }
    27. HCNetSDK.NET_DVR_REALTIME_THERMOMETRY_COND thermometry = new HCNetSDK.NET_DVR_REALTIME_THERMOMETRY_COND();
    28. thermometry.dwSize = thermometry.size();
    29. thermometry.byRuleID = 0;
    30. thermometry.dwChan = 2;
    31. thermometry.write();
    32. Pointer pUserData = new Memory(37);
    33. //TODO 传数据
    34. pUserData.setString(0, bean.getIp());
    35. pUserData.setInt(13,222);
    36. while (true){
    37. NativeLong lHandle = hCNetSDK.NET_DVR_StartRemoteConfig(lUserID, 3629, thermometry.getPointer(), thermometry.size(), thermInfoCallback, pUserData);
    38. if (lHandle.intValue() < 0){
    39. log.error(bean.getIp()+"NET_DVR_GET_REALTIME_THERMOMETRY failed, error code: "+ hCNetSDK.NET_DVR_GetLastError());
    40. break;
    41. }else{
    42. log.info(bean.getIp()+"NET_DVR_GET_REALTIME_THERMOMETRY is successful!");
    43. }
    44. try {
    45. Thread.sleep(2000);
    46. } catch (InterruptedException e) {
    47. e.printStackTrace();
    48. }
    49. }
    50. // if(!hCNetSDK.NET_DVR_StopRemoteConfig(lHandle)){
    51. // log.error(bean.getIp()+"NET_DVR_StopRemoteConfig failed, error code:"+ hCNetSDK.NET_DVR_GetLastError());
    52. // }
    53. //
    54. // boolean logoutStatus = hCNetSDK.NET_DVR_Logout(lUserID);
    55. // if(logoutStatus){
    56. // log.info(bean.getIp()+"Logout success");
    57. // }else{
    58. // log.error(bean.getIp()+"Logout fail");
    59. // }
    60. }
    61. }

    main

    1. static HCNetSDK hCNetSDK = HCNetSDK.INSTANCE;
    2. @Override
    3. public void run() {
    4. boolean initStatus = hCNetSDK.NET_DVR_Init();
    5. if(initStatus){
    6. log.info("初始化成功");
    7. }else{
    8. log.error("初始化失败"+hCNetSDK.NET_DVR_GetCardLastError_Card());
    9. }
    10. hCNetSDK.NET_DVR_SetConnectTime(2000, 1);
    11. hCNetSDK.NET_DVR_SetReconnect(10000, true);
    12. hCNetSDK.NET_DVR_SetLogToFile(3,"D:\\log",false);
    13. List deviceList = new ArrayList<>(3);
    14. deviceList.add(new DeviceBean("192.168.1.70",(short) 8000,"admin","a12345678"));
    15. deviceList.add(new DeviceBean("192.168.1.81",(short) 8000,"admin","a12345678"));
    16. deviceList.add(new DeviceBean("192.168.1.91",(short) 8000,"admin","a12345678"));
    17. for(DeviceBean bean : deviceList){
    18. new Thread(new ReadDataThread(hCNetSDK, new ThermInfoCallback(), bean)).start();
    19. }
    20. }

    callback

    1. @Slf4j
    2. public class ThermInfoCallback implements HCNetSDK.FRemoteConfigCallback {
    3. @Override
    4. public void invoke(int dwType, Pointer pBuffer, int dwBufLen, Pointer pUserData) {
    5. log.info("dwType:"+dwType+"dwBufLen:"+dwBufLen+"pUserData:"+pUserData.getString(0));
    6. switch (dwType){
    7. case 0:
    8. HCNetSDK.REMOTECONFIGSTATUS struCfgStatus = new HCNetSDK.REMOTECONFIGSTATUS();
    9. struCfgStatus.write();
    10. Pointer pCfgStatus = struCfgStatus.getPointer();
    11. pCfgStatus.write(0, pBuffer.getByteArray(0, struCfgStatus.size()), 0,struCfgStatus.size());
    12. struCfgStatus.read();
    13. int iStatus = 0;
    14. for(int i=0;i<4;i++)
    15. {
    16. int ioffset = i*8;
    17. int iByte = struCfgStatus.byStatus[i]&0xff;
    18. iStatus = iStatus + (iByte << ioffset);
    19. }
    20. switch (iStatus){
    21. case 1000:
    22. log.error("实时测温回调成功,dwStatus:" + iStatus);
    23. break;
    24. case 1001:
    25. log.error("正在获取实时测温回调数据中,dwStatus:" + iStatus);
    26. break;
    27. case 1002:
    28. int iErrorCode = 0;
    29. for(int i=0;i<4;i++)
    30. {
    31. int ioffset = i*8;
    32. int iByte = struCfgStatus.byErrorCode[i]&0xff;
    33. iErrorCode = iErrorCode + (iByte << ioffset);
    34. }
    35. log.error(pUserData.getString(0)+"获取实时测温回调数据失败, dwStatus:" + iStatus + "错误号:" + iErrorCode);
    36. break;
    37. default:
    38. break;
    39. }
    40. break;
    41. case 2:
    42. HCNetSDK.NET_DVR_THERMOMETRY_UPLOAD m_struThermometryInfo = new HCNetSDK.NET_DVR_THERMOMETRY_UPLOAD();
    43. m_struThermometryInfo.write();
    44. Pointer pInfoV30 = m_struThermometryInfo.getPointer();
    45. pInfoV30.write(0, pBuffer.getByteArray(0, m_struThermometryInfo.size()), 0,m_struThermometryInfo.size());
    46. m_struThermometryInfo.read();
    47. if(m_struThermometryInfo.byRuleCalibType == 0){
    48. System.out.println("点测温信息:"+ m_struThermometryInfo.struPointThermCfg.fTemperature);
    49. }
    50. if(m_struThermometryInfo.byRuleCalibType == 1 || m_struThermometryInfo.byRuleCalibType == 2){
    51. log.info("框/线测温信息:fMaxTemperature__"+m_struThermometryInfo.struLinePolygonThermCfg.fMaxTemperature);
    52. log.info(" fMinTemperature__"+m_struThermometryInfo.struLinePolygonThermCfg.fMinTemperature);
    53. log.info(" fAverageTemperature__"+m_struThermometryInfo.struLinePolygonThermCfg.fAverageTemperature);
    54. log.info(" fTemperatureDiff__"+m_struThermometryInfo.struLinePolygonThermCfg.fTemperatureDiff);
    55. log.info(" fCenterPointTemperature__"+m_struThermometryInfo.fCenterPointTemperature);
    56. }
    57. break;
    58. default:
    59. break;
    60. }
    61. }
    62. }

    在此说明一下pUserData传值到callback,看此博客Pointer传值

  • 相关阅读:
    required a bean of type …… that could not be found.
    java计算机毕业设计列车票务信息管理系统源程序+mysql+系统+lw文档+远程调试
    搭建Windows上的Qt桌面开发环境
    java 跨站攻击脚本过滤工具类
    jdk 管理工具比对 jEnv jabba SDKMAN
    技术层面上快速突破Servlet,带你快速上手HttpServlet,HttpServletRequest,HttpServletResponse
    2023-07-01:redis过期策略都有哪些?LRU 算法知道吗?
    SpringBoot3新特性
    新手如何用Airtest实现在图片范围内随机点击?
    北邮22级信通院数电:Verilog-FPGA(5)第四第五周实验 密码保险箱的设计
  • 原文地址:https://blog.csdn.net/zjy660358/article/details/132885952