本文简单直接粗糙的介绍下海康工业相机常用的参数的设置方法与获取方法
1.海康工业SDK简介:
海康机器人工业相机sdk简介
2.海康工业相机参数设置获取通用方法:
海康工业相机参数设置与获取
如果不心急,就先简单阅读上述两篇博客,可以更加熟悉海康的工业相机sdk的整体构成
参数实在是太多,有空慢慢更新啦…
MVCC_STRINGVALUE stStrValue;
memset(&stStrValue, 0, sizeof(MVCC_STRINGVALUE));
nRet = MV_CC_GetStringValue(handle, "DeviceSerialNumber", &stStrValue);
if (MV_OK != nRet)
printf("Get DeviceSerialNumber fail! nRet [0x%x]\n", nRet);
printf("Current DeviceSerialNumber [%s]\n", stStrValue.chCurValue);
nRet = MV_CC_SetStringValue(handle, "DeviceUserID", "UserIDChanged");
if (MV_OK != nRet)
printf("Set DeviceUserID fail! nRet [0x%x]\n", nRet);
MVCC_STRINGVALUE stStrValue;
memset(&stStrValue, 0, sizeof(MVCC_STRINGVALUE));
nRet = MV_CC_GetStringValue(handle, "DeviceUserID", &stStrValue);
if (MV_OK != nRet)
printf("Get DeviceUserID fail! nRet [0x%x]\n", nRet);
printf("Rename DeviceUserID [%s]\n", stStrValue.chCurValue);
MVCC_INTVALUE_EX stIntValue = {0};
nRet = MV_CC_GetIntValueEx(handle, "DeviceUptime", &stIntValue);
if (MV_OK != nRet)
printf("Get DeviceUptime fail! nRet [0x%x]\n", nRet);
printf("DeviceUptime [%d]\n", stIntValue.nCurValue);
MVCC_INTVALUE_EX nWidthMaxValue= = {0},nHeightMaxValue = {0};
nRet = MV_CC_GetIntValueEx(handle, "WidthMax", &nWidthMaxValue);
if (MV_OK != nRet)
printf("Get WidthMax fail! nRet [0x%x]\n", nRet);
nRet = MV_CC_GetIntValueEx(handle, "HeightMax", &nHeightMaxValue);
if (MV_OK != nRet)
printf("Get HeightMax fail! nRet [0x%x]\n", nRet);
注意事项:相机设置图像宽高时,相机不能取流:需要在startgrabing之前设置或者stopgrabing之后设置
unsigned int m_Width=1000,m_Height=1000;
unsigned int m_OffsetX=256,m_OffsetY=256;
MVCC_INTVALUE_EX nWidthValue= {0},nHeightValue = {0};
nRet = MV_CC_GetIntValueEx(handle, "Width", &nWidthValue);
nRet = MV_CC_GetIntValueEx(handle, "Height", &nHeightValue);
if(m_Width>nWidthValue.nMax||
m_Height > nHeightValue.nMax||
m_Width<nWidthValue.nMin||
m_Height < nHeightValue.nMin||
(m_Width+m_OffsetX)>nWidthValue.nMax||
(m_Height +m_OffsetY)>nHeightValue.nMax||)
printf("Set Image Width or Height out of range !!\n", nRet);
}else
nRet = MV_CC_SetIntValue(handle,"OffsetX",0);
nRet = MV_CC_SetIntValue(handle,"OffsetY",0);
if((m_Width%nWidthValue.nInc)==0&&(m_Height%nHeightValue.nInc)==0)
nRet = MV_CC_SetIntValue(handle,"Width",m_Width);
if(nRet != MV_OK)
printf("Warning: Set Width fail nRet [0x%x]!", nRet);
nRet = MV_CC_SetIntValue(handle,"Height",m_Height);
if(nRet != MV_OK)
printf("Warning: Set Height fail nRet [0x%x]!", nRet);
nRet = MV_CC_SetIntValue(handle,"OffsetX",m_OffsetX);
if(nRet != MV_OK)
printf("Warning: Set OffsetX fail nRet [0x%x]!", nRet);
nRet = MV_CC_SetIntValue(handle,"OffsetY",m_OffsetY);
if(nRet != MV_OK)
printf("Warning: Set OffsetY fail nRet [0x%x]!", nRet);
}else
nRet = MV_CC_SetIntValue(handle,"Width",m_Width-m_Width%nWidthValue.nInc);
if(nRet != MV_OK)
printf("Warning: Set Width fail nRet [0x%x]!", nRet);
nRet = MV_CC_SetIntValue(handle,"Height",m_Height-m_Height%nHeightValue.nInc);
if(nRet != MV_OK)
printf("Warning: Set Height fail nRet [0x%x]!", nRet);
nRet = MV_CC_SetIntValue(handle,"OffsetX",m_OffsetX);
if(nRet != MV_OK)
printf("Warning: Set OffsetX fail nRet [0x%x]!", nRet);
nRet = MV_CC_SetIntValue(handle,"OffsetY",m_OffsetY);
if(nRet != MV_OK)
printf("Warning: Set OffsetY fail nRet [0x%x]!", nRet);
MVCC_INTVALUE_EX nWidthMaxValue= {0},nHeightMaxValue = {0};
nRet = MV_CC_GetIntValueEx(handle, "WidthMax", &nWidthMaxValue);
if (MV_OK != nRet)
printf("Get WidthMax fail! nRet [0x%x]\n", nRet);
nRet = MV_CC_GetIntValueEx(handle, "HeightMax", &nHeightMaxValue);
if (MV_OK != nRet)
printf("Get HeightMax fail! nRet [0x%x]\n", nRet);
nRet = MV_CC_SetIntValue(handle,"OffsetX",0);
nRet = MV_CC_SetIntValue(handle,"OffsetY",0);
nRet = MV_CC_SetIntValue(handle,"Width",nWidthMaxValue.nCurValue);
if(nRet != MV_OK)
printf("Warning: Set Width fail nRet [0x%x]!", nRet);
nRet = MV_CC_SetIntValue(handle,"Height",nHeightMaxValue.nCurValue);
if(nRet != MV_OK)
printf("Warning: Set Height fail nRet [0x%x]!", nRet);
MV_XML_NODE_FEATURE stNodeFeature;
MV_XML_FEATURE_Enumeration stFeatureEnm;
memset(&stNodeFeature,0,sizeof(MV_XML_NODE_FEATURE));
memset(&stFeatureEnm, 0, sizeof(MV_XML_FEATURE_Enumeration));
strncpy(stNodeFeature.strName, "PixelFormat", strlen("PixelFormat"));
stNodeFeature.enType = IFT_IEnumeration;
nRet = MV_XML_GetNodeFeature(handle,&stNodeFeature,&stFeatureEnm);
if (MV_OK != nRet)
return nRet;
}else
for (int i = 0; i < stFeatureEnm.nSymbolicNum; i++)
printf("PixelFormat:%s \r\n", stFeatureEnm.strSymbolic[i]);
for (int i = 0; i < stFeatureEnm.nSymbolicNum; i++)
if (strcmp(stFeatureEnm.strSymbolic[i] ,"BayerBG8")==0||
strcmp(stFeatureEnm.strSymbolic[i], "BayerRG8")==0||
strcmp(stFeatureEnm.strSymbolic[i], "BayerGB8")==0||
strcmp(stFeatureEnm.strSymbolic[i], "BayerGR8")==0||
strcmp(stFeatureEnm.strSymbolic[i], "RGB8Packed")==0||
strcmp(stFeatureEnm.strSymbolic[i], "BGR8Packed")==0)
printf("This is a Color camera \n");
break;
nRet = MV_CC_SetEnumValue(handle, "PixelFormat", PixelType_Gvsp_Mono12);
if (MV_OK != nRet)
printf("error: Set PixelFormat fail [%x]\n", nRet);
nRet = MV_CC_SetEnumValue(handle, "TestPattern", 0);
if (MV_OK != nRet)
printf("Set TestPattern fail! nRet [0x%x]\n", nRet);
break;
nRet = MV_CC_SetEnumValue(handle, "TestPattern", 9);
if (MV_OK != nRet)
printf("Set TestPattern fail! nRet [0x%x]\n", nRet);
break;
nRet = MV_CC_SetBoolValue(handle, "ReverseX", true);
if (MV_OK != nRet)
printf("Set ReverseX fail! nRet [0x%x]\n", nRet);
nRet = MV_CC_SetBoolValue(handle, "ReverseY", true);
if (MV_OK != nRet)
printf("Set ReverseY fail! nRet [0x%x]\n", nRet);
相机的图像水印信息,用于打印记录相机内部信息,水印信息在取流接口中,图像结构体里面获取
相机水印的本质原理是取代图像头部开始的小部分有效信息,占用约40个字节的真实数据信息,供信息传输,不造成图像数据大小的变化
参数 | 关键词 | 参数值 |
---|
时间戳 | Timestamp | 0 |
增益 | Gain | 1 |
曝光 | Exposure | 2 |
平均亮度 | BrightnessInfo | 3 |
白平衡 | WhiteBalance | 4 |
帧号 | Framecounter | 5 |
触发计数 | ExtTriggerCount | 6 |
IO输入输出电平状态 | LineInputOutput | 7 |
ROI区域 | ROIPosition | 8 |
nRet = MV_CC_SetEnumValue(handle, "FrameSpecInfoSelector", 2);
nRet = MV_CC_SetBoolValue(handle, "FrameSpecInfo", true);
nRet = MV_CC_SetEnumValue(handle, "FrameSpecInfoSelector", 3);
nRet = MV_CC_SetBoolValue(handle, "FrameSpecInfo", true);
nRet = MV_CC_SetEnumValue(handle, "FrameSpecInfoSelector", 5);
nRet = MV_CC_SetBoolValue(handle, "FrameSpecInfo", true);
if (MV_OK != nRet)
printf("Set FrameSpecInfofail! nRet [0x%x]\n", nRet);
效果:
主动取流中,图像结构体中获取水印信息
关闭水印功能
nRet = MV_CC_SetEnumValue(handle, "FrameSpecInfoSelector", 5);
nRet = MV_CC_SetBoolValue(handle, "FrameSpecInfo", false);
参数 | 关键词 | 参数值 | 说明 |
---|
单帧采集 | SingleFrame | 0 | 一般用于visionpro等特殊软件,正常不推荐使用这个模式 |
连续采集 | Continuous | 2 | 常用的模式,软触发的单帧采集,硬触发采集,连续拍照,都使用这个模式 |
nRet = MV_CC_SetEnumValue(handle, "AcquisitionMode", 2);
if (MV_OK != nRet)
printf("Set FrameSpecInfofail! nRet [0x%x]\n", nRet);
AcquisitionBurstFrameCount:在触发模式下,触发一次,采集多少帧,默认为1;
假设设置为2,相机收到一个信号,自动采集两帧,采集频率根据帧率变化
nRet = MV_CC_SetIntValue(handle,"AcquisitionBurstFrameCount",1);
if(nRet != MV_OK)
printf("Warning: Set AcquisitionBurstFrameCountfail nRet [0x%x]!", nRet);
nRet =MV_CC_SetFloatValue(handle, "AcquisitionFrameRate", 5);
if(nRet != MV_OK)
printf("Warning: Set AcquisitionBurstFrameCountfail nRet [0x%x]!", nRet);
nRet = MV_CC_SetBoolValue(handle, "AcquisitionFrameRateEnable", true);
if(nRet != MV_OK)
printf("Warning: Set AcquisitionBurstFrameCountfail nRet [0x%x]!", nRet);
nRet = MV_CC_SetEnumValue(handle, "TriggerMode", MV_TRIGGER_MODE_ON);
if (MV_OK != nRet)
printf("Set Trigger Mode fail! nRet [0x%x]\n", nRet);
nRet = MV_CC_SetEnumValue(handle, "TriggerSource",MV_TRIGGER_SOURCE_SOFTWARE);
if (MV_OK != nRet)
printf("Set Trigger Source fail! nRet [0x%x]\n", nRet);
在需要拍摄图片的时刻,执行command命令,执行一次,相机拍摄一张图片(需在startgrabing命令开启后才行)
nRet = MV_CC_SetCommandValue(handle, "TriggerSoftware");
if (MV_OK != nRet)
printf("TriggerSoftware fail! nRet [0x%x]\n", nRet);
硬触发要配合硬触发接线,配合的参数还有很多,参考:海康工业相机功能模块-IO输入输出控制
包括:
1、触发模式:TriggerMode设置为1,开启触发模式
2、触发源选择:TriggerSource设置为0,选择line0,也可以选择line2,或者选择anyway;line0、line2取决于硬件电路接线,anyway支持软触发、硬触发同时使用,需要看相机是否支持
3、沿信号TriggerActivation:默认上升沿触发(可以不设置)
4、触发缓存TriggerCacheEnable:默认不开启。当相机同时收到两个触发信号时,不开启此功能,相机只会响应1个信号,出一张图;开启后,相机会自动缓存第二个信号,上个信号处理完毕后,立即处理缓存信号
5、触发延时TriggerDelay:收到信号后,固定延迟一段时间再曝光
6、滤波设置 LineDebouncerTime:去除信号毛刺抖动,根据实际情况进行调节
nRet = MV_CC_SetEnumValue(handle, "TriggerMode", MV_TRIGGER_MODE_ON);
if (MV_OK != nRet)
printf("Set Trigger Mode fail! nRet [0x%x]\n", nRet);
nRet = MV_CC_SetEnumValue(handle, "TriggerSource",MV_TRIGGER_SOURCE_LINE0);
if (MV_OK != nRet)
printf("Set Trigger Source fail! nRet [0x%x]\n", nRet);
Anyway即相机可以响应软触发命令,也可以响应line0、line2的硬触发信号
注意需要使用此功能时,需要了解相机是否支持该功能
nRet = MV_CC_SetEnumValue(handle, "TriggerMode", MV_TRIGGER_MODE_ON);
if (MV_OK != nRet)
printf("Set Trigger Mode fail! nRet [0x%x]\n", nRet);
nRet = MV_CC_SetEnumValue(handle, "TriggerSource",24);
if (MV_OK != nRet)
printf("Set Trigger Source fail! nRet [0x%x]\n", nRet);
nRet = MV_CC_SetEnumValue(handle, "ExposureMode",0);
nRet = MV_CC_SetFloatValue(handle, "ExposureTime", 1000);
if (MV_OK != nRet)
printf("Set ExposureTime fail nRet [0xd%]\n!", nRet);
nRet = MV_CC_SetEnumValue(handle, "ExposureMode",0);
nRet = MV_CC_SetFloatValue(handle, "ExposureAuto", 2);
if (MV_OK != nRet)
printf("Set ExposureAuto fail nRet [0xd%]\n!", nRet);
}else{
nRet = MV_CC_SetIntValue(handle,"Brightness",160);
if(nRet != MV_OK)
printf("Set BrightnessnRet [0x%x]!", nRet);
nRet = MV_CC_SetEnumValue(handle, "ExposureMode",0);
nRet = MV_CC_SetEnumValue(handle, "ExposureTimeMode", 0);
if (MV_OK != nRet)
printf("Set Trigger Mode fail! nRet [0x%x]\n", nRet);
}else
printf("ExposureTimeMode :Standard\n");
nRet = MV_CC_SetFloatValue(handle, "ExposureTime", 1000);
if (MV_OK != nRet)
printf("Set ExposureTime fail nRet [0xd%]\n!", nRet);
nRet = MV_CC_SetEnumValue(handle, "ExposureTimeMode", 1);
if (MV_OK != nRet)
printf("Set Trigger Mode fail! nRet [0x%x]\n", nRet);
}else
printf("ExposureTimeMode :UltraShort\n");
nRet = MV_CC_SetFloatValue(handle, "ExposureTime", 12);
if (MV_OK != nRet)
printf("Set ExposureTime fail nRet [0xd%]\n!", nRet);
unsigned ExpValue[4]={2000,3000,2500,1300};
unsigned GainValue[4]={0,1,2,3};
for (int i = 0; i < 4; i++)
nRet = MV_CC_SetIntValue(handle,"HDRSelector",i);
if(nRet != MV_OK)
printf("Warning: Set HDRSelector fail nRet [0x%x]!", nRet);
nRet = MV_CC_SetIntValue(handle,"HDRShutter",ExpValue[i]);
if(nRet != MV_OK)
printf("Warning: Set HDRShutter fail nRet [0x%x]!", nRet);
nRet =MV_CC_SetFloatValue(handle, "HDRGain", GainValue[i]);
if(nRet != MV_OK)
printf("Warning: Set HDRGain nRet [0x%x]!", nRet);
nRet = MV_CC_SetFloatValue(handle, "Gain", 1;
if (MV_OK != nRet)
printf("Set Gainfail fail nRet [0xd%]\n", nRet);
nRet = MV_CC_SetBoolValue(handle, "DigitalShiftEnable", true);
if (MV_OK != nRet)
printf("Set DigitalShiftEnable fail! nRet [0x%x]\n", nRet);
nRet = MV_CC_SetFloatValue(handle, "DigitalShift", 1);
if (MV_OK != nRet)
printf("Set DigitalShift fail !nRet [0xd%]\n", nRet);
nRet = MV_CC_SetBoolValue(handle, "GammaEnable", true);
if (MV_OK != nRet)
printf("Set GammaEnable fail! nRet [0x%x]\n", nRet);
nRet = MV_CC_SetEnumValue(handle, "GammaSelector", 1);
if (MV_OK != nRet)
printf("Set GammaSelector fail! nRet [0x%x]\n", nRet);
nRet = MV_CC_SetFloatValue(handle, "Gamma", 1);
if (MV_OK != nRet)
printf("Set Gamma failed! nRet [0xd%]\n", nRet);
工业相机本身内部处理,支持锐度设置(相机硬件ISP处理)
锐度需要注意相机图像格式,例如YUV、RGB、MONO10、MONO12等格式就不支持锐度,就需要通过其他方式实现
nRet = MV_CC_SetBoolValue(handle, "SharpnessEnable", true);
if (MV_OK != nRet)
printf("Set SharpnessEnable failed! nRet [0x%x]\n", nRet);
nRet = MV_CC_SetFloatValue(handle, "Sharpness", 1);
if (MV_OK != nRet)
printf("Set Sharpness failed nRet [0xd%]\n", nRet);
当相机硬件在某些情况不支持锐度处理时,海康SDK提供了软件层面的锐度接口调用
仅支持mono8格式与RGB格式,其他图像格式需要先行转化成这两种格式
static unsigned int __stdcall WorkThread(void* pUser)
int nRet = MV_OK;
unsigned char *pConvertData = NULL;
unsigned char *pSharpenData = NULL;
unsigned int nConvertDataSize = 0;
MV_FRAME_OUT stImageInfo = {0};
MV_DISPLAY_FRAME_INFO stDisplayInfo = {0};
MV_CC_PIXEL_CONVERT_PARAM stConvertParam = {0};
MV_CC_SHARPEN_PARAM stSharpenParam ={0};
while(1)
nRet = MV_CC_GetImageBuffer(pUser, &stImageInfo, 1000);
if (nRet == MV_OK)
printf("Get Image Buffer: Width[%d], Height[%d], FrameNum[%d]\n",
stImageInfo.stFrameInfo.nWidth, stImageInfo.stFrameInfo.nHeight, stImageInfo.stFrameInfo.nFrameNum);
MvGvspPixelType enDstPixelType = PixelType_Gvsp_Undefined;
unsigned int nChannelNum = 0;
char chFileName[MAX_PATH] = {0};
if (IsColor(stImageInfo.stFrameInfo.enPixelType))
nChannelNum = 3;
enDstPixelType = PixelType_Gvsp_RGB8_Packed;
sprintf(chFileName, "AfterConvert.rgb");
else if (IsMono(stImageInfo.stFrameInfo.enPixelType))
nChannelNum = 1;
enDstPixelType = PixelType_Gvsp_Mono8;
sprintf(chFileName, "AfterConvert.gray");
printf("Don't need to convert!\n");
if (enDstPixelType != PixelType_Gvsp_Undefined)
if (NULL == pConvertData)
pConvertData = (unsigned char*)malloc(stImageInfo.stFrameInfo.nWidth * stImageInfo.stFrameInfo.nHeight * nChannelNum);
if (NULL == pConvertData)
printf("malloc pConvertData fail!\n");
nRet = MV_E_RESOURCE;
break;
nConvertDataSize = stImageInfo.stFrameInfo.nWidth * stImageInfo.stFrameInfo.nHeight * nChannelNum;
stConvertParam.nWidth = stImageInfo.stFrameInfo.nWidth;
stConvertParam.nHeight = stImageInfo.stFrameInfo.nHeight;
stConvertParam.pSrcData = stImageInfo.pBufAddr;
stConvertParam.nSrcDataLen = stImageInfo.stFrameInfo.nFrameLen;
stConvertParam.enSrcPixelType = stImageInfo.stFrameInfo.enPixelType;
stConvertParam.enDstPixelType = enDstPixelType;
stConvertParam.pDstBuffer = pConvertData;
stConvertParam.nDstBufferSize = nConvertDataSize;
nRet = MV_CC_ConvertPixelType(pUser, &stConvertParam);
if (MV_OK != nRet)
printf("Convert Pixel Type fail! nRet [0x%x]\n", nRet);
break;
}else
printf("Convert Pixel Type ok!\n");
if(g_Sharpen)
if (NULL == pSharpenData)
pSharpenData = (unsigned char*)malloc(stImageInfo.stFrameInfo.nWidth * stImageInfo.stFrameInfo.nHeight * nChannelNum);
if (NULL == pSharpenData)
printf("malloc pConvertData fail!\n");
nRet = MV_E_RESOURCE;
break;
stSharpenParam.nWidth = stImageInfo.stFrameInfo.nWidth;
stSharpenParam.nHeight = stImageInfo.stFrameInfo.nHeight;
stSharpenParam.enPixelType = enDstPixelType;
stSharpenParam.pSrcBuf = stConvertParam.pDstBuffer;
stSharpenParam.nSrcBufLen = stConvertParam.nDstBufferSize;
stSharpenParam.pDstBuf = pSharpenData;
stSharpenParam.nDstBufSize = stConvertParam.nDstBufferSize;
stSharpenParam.nSharpenAmount = m_nSharpenAmount;
stSharpenParam.nSharpenRadius = m_nSharpenRadius;
stSharpenParam.nSharpenThreshold = m_nSharpenThreshold;
nRet = MV_CC_ImageSharpen(pUser, &stSharpenParam);
if (MV_OK != nRet)
printf("Image Sharpen fail! nRet [0x%x]\n", nRet);
break;
}else
printf("Sharpen :50 ok!\n");
T2=qMyMilliseconds();
printf("Grab ok!,costtime:%f\n",T2-T1);
if (g_hwnd)
stDisplayInfo.hWnd = g_hwnd;
stDisplayInfo.pData = pSharpenData;
stDisplayInfo.nDataLen = nConvertDataSize;
stDisplayInfo.nWidth = stImageInfo.stFrameInfo.nWidth;
stDisplayInfo.nHeight = stImageInfo.stFrameInfo.nHeight;
stDisplayInfo.enPixelType = enDstPixelType;
nRet =MV_CC_DisplayOneFrame(pUser, &stDisplayInfo);
MV_SAVE_IMG_TO_FILE_PARAM stSaveFileParam;
memset(&stSaveFileParam, 0, sizeof(MV_SAVE_IMG_TO_FILE_PARAM));
stSaveFileParam.enImageType = MV_Image_Bmp;
stSaveFileParam.enPixelType = enDstPixelType;
stSaveFileParam.nWidth = stImageInfo.stFrameInfo.nWidth;
stSaveFileParam.nHeight = stImageInfo.stFrameInfo.nHeight;
stSaveFileParam.nDataLen = nConvertDataSize;
stSaveFileParam.pData = pSharpenData;
stSaveFileParam.iMethodValue = 0;
if (MV_Image_Bmp == stSaveFileParam.enImageType)
sprintf_s(stSaveFileParam.pImagePath, 256, "Image_w%d_h%d_fn%03d_%d_%d_%d.bmp", stSaveFileParam.nWidth, stSaveFileParam.nHeight, stImageInfo.stFrameInfo.nFrameNum,m_nSharpenAmount,m_nSharpenAmount,m_nSharpenThreshold);
nRet = MV_CC_SaveImageToFile(pUser,&stSaveFileParam);
if(nRet != MV_OK)
printf("MV_CC_SaveImageToFile fail! nRet [0x%x]\n", nRet);
}else
printf("MV_CC_SaveImageToFile ok!\n");
nRet = MV_CC_FreeImageBuffer(pUser, &stImageInfo);
if(nRet != MV_OK)
printf("Free Image Buffer fail! nRet [0x%x]\n", nRet);
if(g_bExit)
break;
return 0;
nRet = MV_CC_SetEnumValue(handle, "BalanceWhiteAuto", 1);
if (MV_OK != nRet)
printf("Set BalanceWhiteAuto fail! nRet [0x%x]\n", nRet);
sleep(2000);
nRet = MV_CC_SetEnumValue(handle, "BalanceWhiteAuto", 0);
if (MV_OK != nRet)
printf("Set BalanceWhiteAuto fail! nRet [0x%x]\n", nRet);
nRet = MV_CC_SetEnumValue(handle, "BalanceWhiteAuto", 0);
if (MV_OK != nRet)
printf("Set BalanceWhiteAuto fail! nRet [0x%x]\n", nRet);
break;
int BalanceRatio_Value[3]={1100,1024,1800};
for (int i = 0; i < 3; i++)
nRet = MV_CC_SetEnumValue(handle, "BalanceRatioSelector", i);
nRet = MV_CC_SetIntValue(handle, "BalanceRatio",BalanceRatio_Value[i]);
相机IO控制,主要用于控制IO信号输出,详情参考文章IO输出部分:海康工业相机功能模块-IO输入输出控制
IO输出也可以由相机控制,在相机工作的不同的时间段,给出一个输出信号,控制外部设备,海康工业相机支持的IO事件包括如下几种
事件源名称 | 关键词 | 参数值 | 功能说明 |
---|
曝光开始 | ExposureStartActive | 0 | sensor开始曝光时,输出信号 |
采集开始 | AcquisitionStartActive | 1 | 数据开始读出时输出信号,帧读出开始时刻 |
采集结束 | AcquisitionStopActive | 2 | 数据结束读出时输出信号,帧读出结束时刻 |
出图开始 | FrameBurstStartActive | 3 | 图像数据开始通过链路发送时刻输出信号,brust>2才有信号输出,往往没啥用 |
出图结束 | FrameBurstEndActive | 4 | 图像数据通过链路发送结束时刻输出信号,brust>2才有信号输出,往往没啥用 |
软触发输出 | SoftTriggerActive | 5 | 软件调用command命令时刻,输出,用户自主可控 |
硬触发输出 | HardTriggerActive | 6 | 相机输入信号line0\2收到输入信号时,输出一个输出信号 |
计数器输出 | TimerActive | 7 | 计时器,计算line0、line2收到指定信号个数,输出一个输出信号 |
触发等待输出 | FrameTriggerWait | 8 | 相机可以被触发,可以曝光采集时,触发信号 |
常用的有曝光开始、软触发输出、硬触发输出
举例:
nRet = MV_CC_SetEnumValue(handle, "LineSelector", 2);
nRet = MV_CC_SetEnumValue(handle, "LineMode", 8);
nRet = MV_CC_SetEnumValue(handle, "LineSource", 5);
int DurationValue=1000,DelayValue=100,PreDelayValue=0;
nRet = MV_CC_SetIntValue(handle, "StrobeLineDuration",DurationValue);
nRet = MV_CC_SetIntValue(handle, "StrobeLineDelay",DelayValue);
nRet = MV_CC_SetIntValue(handle, "StrobeLinePreDelay",PreDelayValue);
nRet = MV_CC_SetBoolValue(handle, "StrobeEnable",TRUE);
nRet = MV_CC_SetCommandValue(m_handle, "LineTriggerSoftware");
nRet = MV_CC_SetIntValue(handle,"GevHeartbeatTimeout",3000);
if(nRet != MV_OK)
printf("Warning: Set Width fail nRet [0x%x]!", nRet);
保存参数到userset,确保相机掉电后,参数不消失
nRet = MV_CC_SetEnumValue(handle, "UserSetSelector", 1);
if (MV_OK != nRet)
printf("error: SetEnumValue UserSetSelector fail [%x]\n", nRet);
nRet = MV_CC_SetEnumValue(handle, "UserSetDefault", 1);
if (MV_OK != nRet)
printf("error: SetEnumValue UserSetDefault fail [%x]\n", nRet);
nRet = MV_CC_SetCommandValue(m_handle, "UserSetSave");
if (MV_OK != nRet)
printf("error: SetCommandValue fail [%x]\n", nRet);
nRet = MV_CC_SetEnumValue(handle, "UserSetSelector", 0);
if (MV_OK != nRet)
printf("error: SetEnumValue UserSetSelector fail [%x]\n", nRet);
nRet = MV_CC_SetCommandValue(m_handle, "UserSetLoad");
if (MV_OK != nRet)
printf("error: SetCommandValue fail [%x]\n", nRet);
海康机器人工业相机常用参数功能设置与获取(C语言)前言DeviceControlImageFormatControlAcquisitionControlDigitalIOControlActionControlFileAccessControlEventControlChunkDataControlTransportLayerControlUserSetControl前言DeviceControlImageFormatControlAcquisitionControlDigitalIOContro