Haikang industrial camera parameter setting and acquisition

General interface introduction

After getting the Hikvision industrial camera, through its official MVS client, we can set the relevant camera parameters to adjust the image to achieve the effect we want, but how do we integrate so many camera parameters into our software?
Insert picture description here
From querying the SDK documentation, it can be found that they provide a set of common interfaces to obtain and set
Insert picture description here
the camera parameters. The camera parameters are divided into seven categories, except for the command parameter, each category provides a Set/Get interface. To set and get related nodes

Types of description
Int Integer parameter
Enum Enumerated parameter
float Floating-point parameter
bool Boolean parameter
float Floating-point parameter
string String parameter
Command Command parameter

Take MV_CC_GeIntValue as an example: Insert picture description here
code example, get Width:

//获取int型参数
     MVCC_INTVALUE struIntValue = {
    
    0}; 
    nRet = MV_CC_GetIntValue(handle, "Width", &struIntValue);
    if (MV_OK != nRet)
    {
    
    
        printf("error: GetIntValue fail [%x]\n", nRet);
        return;
    }

The second parameter here, "Width", is the key parameter of the entire interface. The document tells us to look up the xml attribute table, and then set the parameters for the lookup table. The xml table is as follows:
Insert picture description here

Features Name (GetNode: key parameter) type of data Value range definition Access mode description
Image Format Control Width IInteger >0 R/(W) ROI width

By looking up the table, we can know what to fill in the key value and what the attribute of the key value is. However, this is too slow. How do I know the position of the parameter I adjusted in the xml table?
By observing the MVS client, there is A simpler way to know the attributes, types, etc. of the camera parameters, and to operate the parameters quickly and conveniently

  • Find the parameter you want in MVS, select it with the mouse, and in the lower right corner of the MVS, in the parameter description, you can look at the node name, type, value range, step and other information
    Insert picture description here
    of the parameter . The picture above shows that the image width "Width" ", the node name is "Width", the type is "int", the value range is 32~2048, and the step is 16;
    according to the type, we can choose MV_CC_SetIntValue/MV_CC_GetIntValue to operate on this property;
    also note the following Two points:
  • Different camera parameters have different types, value ranges and steps
  • Different cameras, the same parameters, have different value ranges and steps

Get common camera parameter settings

Int type parameters-image width, image height

//获取int型参数-Width值
MVCC_INTVALUE struIntValue = {
    
    0}; 
nRet = MV_CC_GetIntValue(handle, "Width", &struIntValue);
if (MV_OK != nRet)
{
    
    
	printf("error: GetIntValue fail [%x]\n", nRet);
}
//打印当前宽度,宽带最大值,最小值,步进
printf("Width;%d,Width_Max:%d,Width_min:%d,Width_Inc:%d\n", 
struIntValue.nCurValue,struIntValue.nMax,struIntValue.nMin,struIntValue.nInc);
//设置int型参数-Width值
unsigned int nValue = 752;
//注意点1:value值需要是步进值的整数倍,否则会失败
//注意点2:宽度、高度等参数设置时,只有在MV_CC_Startgrab接口调用前才能设置,取流过程中,不能修改宽高
//注意点3:宽度、高度等参数设置时,若有Offset X、Y偏移,应当先调用相关接口,将偏移量置0
nRet = MV_CC_SetIntValue(handle, "Width", nValue);
if (MV_OK != nRet)
{
    
    
	printf("error: SetIntValue fail [%x]\n", nRet);
}

Enum type parameters-image format, trigger mode settings

//获取Enum型参数-相机图像格式
MVCC_ENUMVALUE struEnumValue = {
    
    0}; 
nRet = MV_CC_GetEnumValue(handle, "PixelFormat", &struEnumValue);
if (MV_OK != nRet)
{
    
    
	printf("error: GetEnumValue fail [%x]\n", nRet);
}
 //设置Enum型参数-相机图像格式
 //注意点1:相机图像格式设置时,只有在MV_CC_Startgrab接口调用前才能设置,取流过程中,不能修改图像格式
 nRet = MV_CC_SetEnumValue(handle, "PixelFormat", PixelType_Gvsp_Mono12);
if (MV_OK != nRet)
{
    
    
	printf("error: SetEnumValue fail [%x]\n", nRet);
}
//设置Enum型参数-设置触发模式为on 
nRet = MV_CC_SetEnumValue(handle, "TriggerMode", MV_TRIGGER_MODE_ON);
if (MV_OK != nRet)
{
    
    
	printf("Set Trigger Mode fail! nRet [0x%x]\n", nRet);
}

float type parameters-exposure, gain settings

//获取float型参数-曝光参数获取
MVCC_FLOATVALUE struFloatValue = {
    
    0}; 
nRet = MV_CC_GetFloatValue(handle, "ExposureTime", &struFloatValue);
if (MV_OK != nRet)
{
    
    
    printf("error: GetFloatValue fail [%x]\n", nRet);
}
//打印曝光当前值,可设置的最大值、最小值
printf("Exp;%d,Exp_Max:%d,Exp_min:%d\n", struFloatValue.fCurValue,struFloatValue.fMax,struFloatValue.fMin);
//获取float型参数-增益参数获取
MVCC_FLOATVALUE struFloatValue = {
    
    0}; 
nRet = MV_CC_GetFloatValue(handle, "Gain", &struFloatValue);
if (MV_OK != nRet)
{
    
    
    printf("error: GetFloatValue fail [%x]\n", nRet);
}
//打印增益当前值,可设置的最大值、最小值
printf("Gain;%d,Gain_Max:%d,Gain_min:%d\n", struFloatValue.fCurValue,struFloatValue.fMax,struFloatValue.fMin);
//获取float型参数-曝光值
//注意点1:曝光设置有前置条件需要注意,例如自动曝光、曝光模式等,前置条件是否调用,可以再MVS里面观察,设置曝光时,是否提前勾选了其他参数
float fValue = 1000; 
nRet = MV_CC_SetFloatValue(handle, "ExposureTime", fValue);
if (MV_OK != nRet)
{
    
    
	printf("error: SetFloatValue fail [%x]\n", nRet);
}
//获取float型参数-增益值
//注意点1:增益设置有前置条件需要注意,例如自动增益,前置条件是否调用,可以再MVS里面观察,设置增益时,是否提前勾选了其他参数
//注意点2:海康小部分相机增益节点不叫“Gain”,也不是用float节点进行设置,如果遇到了,就在MVS里面观察使用对应接口吧
float fValue = 5; 
nRet = MV_CC_SetFloatValue(handle, "Gain", fValue);
if (MV_OK != nRet)
{
    
    
	printf("error: SetFloatValue fail [%x]\n", nRet);
}

string parameter-user name

//获取string型参数
MVCC_STRINGVALUE struStringValue = {
    
    0}; 
nRet = MV_CC_GetStringValue(handle, "DeviceUserID", &struStringValue);
if (MV_OK != nRet)
{
    
    
	printf("error: GetStringValue fail [%x]\n", nRet);
}
printf("DeviceUserID:[%s]\n", struStringValue.chCurValue);
//设置string型参数-自定义用户名称
 nRet = MV_CC_SetStringValue(handle, "DeviceUserID", "HikCamera");
if (MV_OK != nRet)
{
    
    
    printf("error: SetStringValue fail [%x]\n", nRet);
}

Command type parameter-soft trigger, parameter save command

//设置Command型节点-发送软触发命令
nRet = MV_CC_SetCommandValue(m_handle, "TriggerSoftware");
if (MV_OK != nRet)
{
    
    
	printf("error: SetCommandValue fail [%x]\n", nRet);
}

Parameter saving, some combination parameters need to be used

//设置Enum型参数-相机参数保存/默认加载项
//仅需在opendevice之后,初始化执行一次 UserSetSelector/UserSetDefault即可
nRet = MV_CC_SetEnumValue(handle, "UserSetSelector", 1);
if (MV_OK != nRet)
{
    
    
	printf("Set UserSetSelector 1! nRet [0x%x]\n", nRet);
}
nRet = MV_CC_SetEnumValue(handle, "UserSetDefault", 1);
if (MV_OK != nRet)
{
    
    
	printf("Set UserSetDefault 1! nRet [0x%x]\n", nRet);
}
//设置Command型节点-发送参数保存命令-参数会保存到相机内部ROM里面
//当修改参数完成后,可以调用该节点进行参数保存
//执行成功后,掉电不会消失
nRet = MV_CC_SetCommandValue(m_handle, "UserSetSave");
if (MV_OK != nRet)
{
    
    
	printf("Set UserSetSave fail [%x]\n", nRet);
}

Other participating parameters and functions, query
different functions of the MVS interface , need to combine different parameters, pay attention to the calling sequence and function location

Guess you like

Origin blog.csdn.net/qq_23107577/article/details/113757126