機器視覺康耐視智能相機Insight-缺失外觀檢測
相機參數類型可分為六類,除 command 參數外,每一類都有其對應的設定與擷取函數接口。
表 1 參數類型及對應函數接口介紹
*詳細函數接口可參考 SDK 手冊:
C:\Program Files (x86)\MVS\Development\Documentations
相機參數類型查詢
對于相機的每一個參數,在 MVS 用戶端中都可以找到相應的類型、節點名稱、取值範圍、步進等資訊,從圖 1 可以看出,相機高度節點名稱為”Height”,節點類型”Integer”,取值範圍 ”32-1080” , 步 進 值 為 4 。 通 過 節 點 類 型 我 們 可 以 看 出 , 應 該 使 用MV_CC_GetIntValueEx()擷取參數值,使用 MV_CC_SetIntValueEx()設定參數值。其他參數用法類似。
常用參數設定擷取示例
1) Integer 型參數設定與擷取—以圖像寬度擷取設定為例
MVS 檢視參數類型及節點名稱
調用對應函數接口
//擷取int型參數
MVCC_INTVALUE_EX struIntValue = { 0 };
nRet = MV_CC_GetIntValueEx(handle, "Width", &struIntValue);
if (MV_OK != nRet)
{
printf("Error: GetIntValue fail [%x]\n", nRet);
}
//列印目前寬度的最大值、最小值、步進
printf("Width:%I64d,Width_Max:%I64d,Width_min:%I64d,Width_Inc:%I64d\n", struIntValue.nCurValue,
struIntValue.nMax, struIntValue.nMin, struIntValue.nInc);
//設定int型參數
/*value值必須是步進值(Inc)的整數倍,否則會失敗
寬度、高度等參數設定時,隻有在MV_CC_OpenDevice之後,MV_CC_Startgrab接口調用前才能
設定,取流過程中,不能修改寬高
寬度、高度等參數設定時,若有Offset X、Y偏移,應當先調用相關接口,将偏移量置0
int64_t nValue = 1000;
nRet = MV_CC_SetIntValueEx(handle, "Width", nValue);
if (MV_OK != nRet)
{
printf("Error: SetIntValue fail [%x]\n", nRet);
}
2) Command 型參數——以軟觸發設定為例
//設定Command型節點-發送軟觸發指令
//需要先打開【觸發模式】,觸發源選擇【軟觸發】後才可以設定軟觸發指令
nRet = MV_CC_SetCommandValue(handle, "TriggerSoftware");
if (MV_OK != nRet)
{
printf("Error: SetCommandValue fail [%x]\n", nRet);
}
3) Float 型參數設定與擷取—以曝光擷取、設定為例
//曝光參數擷取
MVCC_FLOATVALUE struFloatValue = { 0 };
nRet = MV_CC_GetFloatValue(handle, "ExposureTime", &struFloatValue);
if (MV_OK != nRet) { printf("Error: GetFloatValue fail [%x]\n", nRet); }
//設定float型參數-曝光值
//設定曝光時,需要注意是否已經開啟自動曝光、曝光模式,它們都會影響曝光參數的設定範圍及是否可 以設定,可在MVS中進行觀察
float fValue = 1000; nRet = MV_CC_SetFloatValue(handle, "ExposureTime", fValue);
if (MV_OK != nRet)
{
printf("Error: SetFloatValue fail [%x]\n", nRet);
}
4) Enumeration 型參數設定與擷取—以相機圖像格式擷取、設定為例
MVS 檢視參數類型及節點名稱
調用對應函數接口
//開啟水印資訊需要按照步驟,才能一步步進行操作
//隻有在MV_CC_OpenDevice之後,MV_CC_Startgrab接口調用前才能設定水印資訊
nRet = MV_CC_SetBoolValue(handle, "ChunkModeActive", 1);//開啟水印模式
if (MV_OK != nRet)
{
printf("Error: ChunkModeActive fail! nRet [0x%x]\n", nRet);
}
nRet = MV_CC_SetEnumValue(handle, "ChunkSelector", 6); //選擇水印資訊:觸發計數
if (MV_OK != nRet)
{
printf("Error: ChunkSelector fail! nRet [0x%x]\n", nRet);;
}
nRet = MV_CC_SetBoolValue(handle, "ChunkEnable", 1);//使能水印
if (MV_OK != nRet)
{
printf("Error: ChunkEnable fail! nRet [0x%x]\n", nRet);
}
5) String 參數擷取與設定—使用者名稱
//擷取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型參數-自定義使用者名稱 //隻有在MV_CC_OpenDevice之後,MV_CC_Startgrab
//接口調用前才能設定使用者ID
nRet = MV_CC_SetStringValue(handle, "DeviceUserID", "HikrobotCamera");
if (MV_OK != nRet)
{ printf("Error: SetStringValue fail [%x]\n", nRet); }
6) Boolean 參數設定—觸發計數水印資訊擷取
MVS 檢視參數類型及節點名稱
調用對應函數接口
//開啟水印資訊需要按照步驟,才能一步步進行操作
//隻有在MV_CC_OpenDevice之後,MV_CC_Startgrab接口調用前才能設定水印資訊
nRet = MV_CC_SetBoolValue(handle, "ChunkModeActive", 1);//開啟水印模式
if (MV_OK != nRet)
{
printf("Error: ChunkModeActive fail! nRet [0x%x]\n", nRet);
}
nRet = MV_CC_SetEnumValue(handle, "ChunkSelector", 6); //選擇水印資訊:觸發計數
if (MV_OK != nRet)
{
printf("Error: ChunkSelector fail! nRet [0x%x]\n", nRet);;
}
nRet = MV_CC_SetBoolValue(handle, "ChunkEnable", 1);//使能水印
if (MV_OK != nRet)
{
printf("Error: ChunkEnable fail! nRet [0x%x]\n", nRet);
}
值得看的技術文章:
機器視覺康耐視智能相機Insight-手眼标定詳細步驟
海康機器視覺工業相機用戶端MVS-介紹與使用,相機狀态
值得看的趣文:
機器視覺工程師們,我是一個沒見過世面的人
機器視覺工程師,如何快速找到女朋友攻略