#include "hikcamera.h"
//静态成员初始化
vector<HikCamera*> HikCamera::devices = vector<HikCamera*>();
HikCamera::HikCamera()
{
}
HikCamera::~HikCamera()
{
// if (devHandle)
// {
// MV_CC_DestroyHandle(devHandle);
// devHandle = nullptr;
// }
}
// ch:获取SDK版本号 | en:Get SDK Version
int HikCamera::GetSDKVersion()
{
return MV_CC_GetSDKVersion();
}
// ch:判断设备是否可达 | en:Is the device accessible
bool HikCamera::IsDeviceAccessible(MV_CC_DEVICE_INFO* pstDevInfo, unsigned int nAccessMode)
{
return MV_CC_IsDeviceAccessible(pstDevInfo, nAccessMode);
}
// ch:打开设备 | en:Open Device
int HikCamera::Open()
{
int nRet = MV_CC_CreateHandle(&devHandle, devInfo);
if (MV_OK != nRet)
{
return nRet;
}
nRet = MV_CC_OpenDevice(devHandle);
if (MV_OK != nRet)
{
MV_CC_DestroyHandle(devHandle);
devHandle = nullptr;
}
return nRet;
}
// ch:关闭设备 | en:Close Device
int HikCamera::Close()
{
if (nullptr == devHandle)
{
return MV_E_HANDLE;
}
MV_CC_CloseDevice(devHandle);
int nRet = MV_CC_DestroyHandle(devHandle);
devHandle = nullptr;
return nRet;
}
// ch:设置曝光时间
int HikCamera::setExposureTime()
{
return MV_CC_SetFloatValue(devHandle,"ExposureTime",devExposure);
}
// ch:判断相机是否处于连接状态 | en:Is The Device Connected
bool HikCamera::IsDeviceConnected()
{
return MV_CC_IsDeviceConnected(devHandle);
}
// ch:注册图像数据回调 | en:Register Image Data CallBack
int HikCamera::RegisterImageCallBack(void(__stdcall* cbOutput)(unsigned char * pData, MV_FRAME_OUT_INFO_EX* pFrameInfo, void* pUser), void* pUser)
{
return MV_CC_RegisterImageCallBackEx(devHandle, cbOutput, pUser);
}
// ch:开启抓图 | en:Start Grabbing
int HikCamera::StartGrabbing()
{
return MV_CC_StartGrabbing(devHandle);
}
// ch:停止抓图 | en:Stop Grabbing
int HikCamera::StopGrabbing()
{
return MV_CC_StopGrabbing(devHandle);
}
// ch:主动获取一帧图像数据 | en:Get one frame initiatively
int HikCamera::GetImageBuffer(MV_FRAME_OUT* pFrame, int nMsec)
{
return MV_CC_GetImageBuffer(devHandle, pFrame, nMsec);
}
// ch:释放图像缓存 | en:Free image buffer
int HikCamera::FreeImageBuffer(MV_FRAME_OUT* pFrame)
{
return MV_CC_FreeImageBuffer(devHandle, pFrame);
}
// ch:主动获取一帧图像数据 | en:Get one frame initiatively
int HikCamera::GetOneFrameTimeout(unsigned char* pData, unsigned int nDataSize, MV_FRAME_OUT_INFO_EX* pFrameInfo, int nMsec)
{
return MV_CC_GetOneFrameTimeout(devHandle, pData, nDataSize, pFrameInfo, nMsec);
}
// ch:设置显示窗口句柄 | en:Set Display Window Handle
int HikCamera::DisplayOneFrame(MV_DISPLAY_FRAME_INFO* pDisplayInfo)
{
return MV_CC_DisplayOneFrame(devHandle, pDisplayInfo);
}
// ch:设置SDK内部图像缓存节点个数 | en:Set the number of the internal image cache nodes in SDK
int HikCamera::SetImageNodeNum(unsigned int nNum)
{
return MV_CC_SetImageNodeNum(devHandle, nNum);
}
// ch:获取设备信息 | en:Get device information
int HikCamera::GetDeviceInfo(MV_CC_DEVICE_INFO* pstDevInfo)
{
return MV_CC_GetDeviceInfo(devHandle, pstDevInfo);
}
// ch:获取GEV相机的统计信息 | en:Get detect info of GEV camera
int HikCamera::GetGevAllMatchInfo(MV_MATCH_INFO_NET_DETECT* pMatchInfoNetDetect)
{
if (nullptr == pMatchInfoNetDetect)
{
return MV_E_PARAMETER;
}
MV_CC_DEVICE_INFO stDevInfo = {0};
GetDeviceInfo(&stDevInfo);
if (stDevInfo.nTLayerType != MV_GIGE_DEVICE)
{
return MV_E_SUPPORT;
}
MV_ALL_MATCH_INFO struMatchInfo = {0};
struMatchInfo.nType = MV_MATCH_TYPE_NET_DETECT;
struMatchInfo.pInfo = pMatchInfoNetDetect;
struMatchInfo.nInfoSize = sizeof(MV_MATCH_INFO_NET_DETECT);
memset(struMatchInfo.pInfo, 0, sizeof(MV_MATCH_INFO_NET_DETECT));
return MV_CC_GetAllMatchInfo(devHandle, &struMatchInfo);
}
// ch:获取U3V相机的统计信息 | en:Get detect info of U3V camera
int HikCamera::GetU3VAllMatchInfo(MV_MATCH_INFO_USB_DETECT* pMatchInfoUSBDetect)
{
if (nullptr == pMatchInfoUSBDetect)
{
return MV_E_PARAMETER;
}
MV_CC_DEVICE_INFO stDevInfo = {0};
GetDeviceInfo(&stDevInfo);
if (stDevInfo.nTLayerType != MV_USB_DEVICE)
{
return MV_E_SUPPORT;
}
MV_ALL_MATCH_INFO struMatchInfo = {0};
struMatchInfo.nType = MV_MATCH_TYPE_USB_DETECT;
struMatchInfo.pInfo = pMatchInfoUSBDetect;
struMatchInfo.nInfoSize = sizeof(MV_MATCH_INFO_USB_DETECT);
memset(struMatchInfo.pInfo, 0, sizeof(MV_MATCH_INFO_USB_DETECT));
return MV_CC_GetAllMatchInfo(devHandle, &struMatchInfo);
}
// ch:获取和设置Int型参数,如 Width和Height,详细内容参考SDK安装目录下的 HikCameraNode.xlsx 文件
// en:Get Int type parameters, such as Width and Height, for details please refer to HikCameraNode.xlsx file under SDK installation directory
int HikCamera::GetIntValue(IN const char* strKey, OUT MVCC_INTVALUE_EX *pIntValue)
{
return MV_CC_GetIntValueEx(devHandle, strKey, pIntValue);
}
int HikCamera::SetIntValue(IN const char* strKey, IN int64_t nValue)
{
return MV_CC_SetIntValueEx(devHandle, strKey, nValue);
}
// ch:获取和设置Enum型参数,如 PixelFormat,详细内容参考SDK安装目录下的 HikCameraNode.xlsx 文件
// en:Get Enum type parameters, such as PixelFormat, for details please refer to HikCameraNode.xlsx file under SDK installation directory
int HikCamera::GetEnumValue(IN const char* strKey, OUT MVCC_ENUMVALUE *pEnumValue)
{
return MV_CC_GetEnumValue(devHandle, strKey, pEnumValue);
}
int HikCamera::SetEnumValue(IN const char* strKey, IN unsigned int nValue)
{
return MV_CC_SetEnumValue(devHandle, strKey, nValue);
}
int HikCamera::SetEnumValueByString(IN const char* strKey, IN const char* sValue)
{
return MV_CC_SetEnumValueByString(devHandle, strKey, sValue);
}
// ch:获取和设置Float型参数,如 ExposureTime和Gain,详细内容参考SDK安装目录下的 HikCameraNode.xlsx 文件
// en:Get Float type parameters, such as ExposureTime and Gain, for details please refer to HikCameraNode.xlsx file under SDK installation directory
int HikCamera::GetFloatValue(IN const char* strKey, OUT MVCC_FLOATVALUE *pFloatValue)
{
return MV_CC_GetFloatValue(devHandle, strKey, pFloatValue);
}
int HikCamera::SetFloatValue(IN const char* strKey, IN float fValue)
{
return MV_CC_SetFloatValue(devHandle, strKey, fValue);
}
// ch:获取和设置Bool型参数,如 ReverseX,详细内容参考SDK安装目录下的 HikCameraNode.xlsx 文件
// en:Get Bool type parameters, such as ReverseX, for details please refer to HikCameraNode.xlsx file under SDK installation directory
int HikCamera::GetBoolValue(IN const char* strKey, OUT bool *pbValue)
{
return MV_CC_GetBoolValue(devHandle, strKey, pbValue);
}
int HikCamera::SetBoolValue(IN const char* strKey, IN bool bValue)
{
return MV_CC_SetBoolValue(devHandle, strKey, bValue);
}
// ch:获取和设置String型参数,如 DeviceUserID,详细内容参考SDK安装目录下的 HikCameraNode.xlsx 文件UserSetSave
// en:Get String type parameters, such as DeviceUserID, for details please refer to HikCameraNode.xlsx file under SDK installation directory
int HikCamera::GetStringValue(IN const char* strKey, MVCC_STRINGVALUE *pStringValue)
{
return MV_CC_GetStringValue(devHandle, strKey, pStringValue);
}
int HikCamera::SetStringValue(IN const char* strKey, IN const char* strValue)
{
return MV_CC_SetStringValue(devHandle, strKey, strValue);
}
// ch:执行一次Command型命令,如 UserSetSave,详细内容参考SDK安装目录下的 HikCameraNod