海康工业相机二次开发获取温度
时间: 2023-09-24 15:11:39 浏览: 353
如果想要通过海康工业相机二次开发获取温度,需要使用支持温度测量功能的海康相机,并使用对应的SDK进行开发。以下是一个简单的获取海康相机温度的C++示例代码:
```c++
#include <iostream>
#include "HCNetSDK.h"
using namespace std;
void CALLBACK fRealDataCallBack(LONG lRealHandle, DWORD dwDataType, BYTE* pBuffer, DWORD dwBufSize, void* pUser)
{
// 处理图像数据
}
int main()
{
NET_DVR_Init();
// 登录相机
LONG lUserID = NET_DVR_Login_V30("192.168.1.100", 8000, "admin", "password", NULL);
if (lUserID < 0)
{
cout << "Login failed, error code: " << NET_DVR_GetLastError() << endl;
NET_DVR_Cleanup();
return 0;
}
// 启用温度测量功能
NET_DVR_THERMOMETRY_COND struCond = {0};
struCond.dwSize = sizeof(NET_DVR_THERMOMETRY_COND);
struCond.byMode = THERMOMETRY_MODE_PLANAR;
struCond.struPoint.byThermometryUnit = 1;
struCond.struPoint.byEnableAlarmTemp = 1;
struCond.struPoint.fAlarmTemp = 30.0;
struCond.struPoint.struPoint.fX = 0.5;
struCond.struPoint.struPoint.fY = 0.5;
LONG lHandle = NET_DVR_StartRemoteConfig(lUserID, NET_DVR_SET_THERMOMETRY_COND, &struCond, sizeof(NET_DVR_THERMOMETRY_COND), NULL, NULL);
if (lHandle < 0)
{
cout << "StartRemoteConfig failed, error code: " << NET_DVR_GetLastError() << endl;
NET_DVR_Logout(lUserID);
NET_DVR_Cleanup();
return 0;
}
DWORD dwRetLen = 0;
NET_DVR_THERMOMETRY_COND struCondRet = {0};
if (!NET_DVR_GetNextRemoteConfig(lHandle, &struCondRet, sizeof(NET_DVR_THERMOMETRY_COND), &dwRetLen))
{
cout << "GetNextRemoteConfig failed, error code: " << NET_DVR_GetLastError() << endl;
NET_DVR_StopRemoteConfig(lHandle);
NET_DVR_Logout(lUserID);
NET_DVR_Cleanup();
return 0;
}
// 开始实时预览
NET_DVR_PREVIEWINFO struPreviewInfo = {0};
struPreviewInfo.hPlayWnd = NULL;
struPreviewInfo.lChannel = 1;
struPreviewInfo.dwStreamType = 0;
struPreviewInfo.dwLinkMode = 0;
LONG lRealHandle = NET_DVR_RealPlay_V40(lUserID, &struPreviewInfo, fRealDataCallBack, NULL);
if (lRealHandle < 0)
{
cout << "RealPlay failed, error code: " << NET_DVR_GetLastError() << endl;
NET_DVR_StopRemoteConfig(lHandle);
NET_DVR_Logout(lUserID);
NET_DVR_Cleanup();
return 0;
}
// 获取温度
NET_DVR_THERMOMETRY_ALARM struAlarm = {0};
if (NET_DVR_GetTempAlarm(lRealHandle, &struAlarm))
{
float fTemp = struAlarm.struPoint.fTempValue;
cout << "Temperature: " << fTemp << endl;
}
else
{
cout << "GetTempAlarm failed, error code: " << NET_DVR_GetLastError() << endl;
}
// 停止实时预览
NET_DVR_StopRealPlay(lRealHandle);
// 停用温度测量功能
NET_DVR_StopRemoteConfig(lHandle);
// 注销相机
NET_DVR_Logout(lUserID);
NET_DVR_Cleanup();
return 0;
}
```
需要注意的是,以上代码仅供参考,实际开发中需要根据具体情况进行修改和优化。同时,使用海康相机进行温度测量需要满足一定的硬件和环境条件,否则可能会影响测量结果的准确性和稳定性。
阅读全文