1.客戶端軟件MVS的安裝
1.1安裝包的下載和解壓
去 官網(wǎng) 下載兩個軟件安裝,分別是客戶端和開發(fā)環(huán)境。(這里我們下載V2.1.1(Linux)和Runtime組件包(Linux)):
工業(yè)相機文檔/安裝包中的不同安裝版本安裝包里有各個系統(tǒng)及arm開發(fā)板使用的安裝包,選擇相應(yīng)的安裝包進行安裝(這里我們選擇最后一個):
?右鍵提取,進入提取后的文件夾,右鍵打開終端。
1.2安裝步驟
Step1:切換root權(quán)限
rm@rm:~/下載/MVS-2.1.1_x86_64_20211224$ sudo su
Step2:運行安裝腳本
rm@rm:~/下載/MVS-2.1.1_x86_64_20211224$ ./setup.sh
安裝完成后,/opt路徑下會生成MVS文件夾,包含以下內(nèi)容:
1.3 MVS客戶端的運行
?進入bin目錄,運行MVS,即可打開客戶端?
連接??倒I(yè)相機之后,通過其官方提供的MVS客戶端,我們可以設(shè)置相關(guān)相機參數(shù),來調(diào)整圖像,達到我們想要的效果,但是如此眾多的相機參數(shù),我們該如何集成進入我們程序呢,接下來就是我們的SDK二次開發(fā)。
2.參數(shù)的設(shè)置
2.1 SDK 用戶指南的閱讀
-
在 opt/MVS/doc 目錄下,我們可以找到 工業(yè)相機Linux SDK用戶指南V3.2.0(C).html ,經(jīng)查詢SDK文檔,可以發(fā)現(xiàn),他們提供了一套通用接口,來對相機進行參數(shù)獲取與設(shè)置。
-
通用接口把相機參數(shù),分成六大類,除command參數(shù)外,每一類提供Set/Get接口來設(shè)置與獲取相關(guān)節(jié)點
如整形數(shù)據(jù)的獲取與設(shè)置
?
-
相機所有開放的屬性值都可參考 相機參數(shù)節(jié)點表 進行查詢,此節(jié)點表對每個節(jié)點的名稱、數(shù)據(jù)類型、數(shù)值范圍定義、訪問模式和節(jié)點描述進行了詳細(xì)說明。對著表可以對參數(shù)進行詳細(xì)的設(shè)置。
2.2 MVS 客戶端的聯(lián)合使用
通過查表,我們可以知道key值該填什么,key值的屬性是什么,但是,這樣子太慢了。為確定我想調(diào)的參數(shù)在xml表的位置,還需要在MVS客戶端中進行定位。那么有沒有更為簡單快速的方法? 通過觀察MVS客戶端,有一個更簡單的方法能夠知道相機參數(shù)的屬性,類型等,可以快速方便的對參數(shù)進行操作
-
在MVS中找到自己想要的參數(shù),鼠標(biāo)選中它,在MVS右下角,參數(shù)描述中,能看看該參數(shù)的節(jié)點名、類型、取值范圍、步進等信息
其節(jié)點名為上圖可知,圖像寬度“Height”,類型是“int”,取值范圍是32~2480,步進是2;根據(jù)類型,我們就可以選用 MV_CC_GetIntValue/MV_CC_SetIntValue來對該屬性進行操作;
2.3 六類參數(shù)的獲取和設(shè)置(例)
-
獲取/設(shè)置 Bool 類型節(jié)點值
? ? ? ?// 獲取bool型變量 ? ? ? ?// get IBoolean variable ? ? ? ?bool bGetBoolValue = false; ? ? ? ?nRet = MV_CC_GetBoolValue(handle, "ReverseX", &bGetBoolValue); ? ? ? ?if (MV_OK == nRet) ? ? ? { ? ? ? ? ? ?if (0 != bGetBoolValue) ? ? ? ? ? { ? ? ? ? ? ? ? ?printf("ReverseX current is true\n\n"); ? ? ? ? ? } ? ? ? ? ? ?else ? ? ? ? ? { ? ? ? ? ? ? ? ?printf("ReverseX current is false\n\n"); ? ? ? ? ? } ? ? ? } ? ? ? ?// 設(shè)置bool型變量 ? ? ? ?// set IBoolean variable ? ? ? ?int nSetBoolValue; ? ? ? ?bool bSetBoolValue; ? ? ? ?printf("please input the ReverseX to set(bool): "); ? ? ? ?scanf("%d", &nSetBoolValue); ? ? ? ?if (0 != nSetBoolValue) ? ? ? { ? ? ? ? ? ?bSetBoolValue = true; ? ? ? } ? ? ? ?else ? ? ? { ? ? ? ? ? ?bSetBoolValue = false; ? ? ? } ? ? ? ?nRet = MV_CC_SetBoolValue(handle, "ReverseX", bSetBoolValue); ? ? ? ?if (MV_OK == nRet) ? ? ? { ? ? ? ? ? ?printf("Set ReverseX OK!\n\n"); ? ? ? } ? ? ? ?else ? ? ? { ? ? ? ? ? ?printf("Set ReverseX Failed! nRet = [%x]\n\n", nRet); ? ? ? }
-
獲取/設(shè)置 Enum 類型節(jié)點值
? ? ? ?// 獲取enum型變量 ? ? ? ?// get IEnumeration variable ? ? ? ?MVCC_ENUMVALUE stTriggerMode = {0}; ? ? ? ?nRet = MV_CC_GetEnumValue(handle, "TriggerMode", &stTriggerMode); ? ? ? ?if (MV_OK == nRet) ? ? ? { ? ? ? ? ? ?printf("TriggerMode current value:%d\n", stTriggerMode.nCurValue); ? ? ? ? ? ?printf("supported TriggerMode number:%d\n", stTriggerMode.nSupportedNum); ? ? ? ? ? ?for (unsigned int i = 0; i < stTriggerMode.nSupportedNum; ++i) ? ? ? ? ? { ? ? ? ? ? ? ? ?printf("supported TriggerMode [%d]:%d\n", i, stTriggerMode.nSupportValue[i]); ? ? ? ? ? } ? ? ? ? ? ?printf("\n"); ? ? ? } ? ? ? ?else ? ? ? { ? ? ? ? ? ?printf("get TriggerMode failed! nRet [%x]\n\n", nRet); ? ? ? } ? ? ? ?// 設(shè)置enum型變量 ? ? ? ?// set IEnumeration variable ? ? ? ?unsigned int nTriggerMode = 0; ? ? ? ?printf("please input the TriggerMode to set:"); ? ? ? ?scanf("%d", &nTriggerMode); ? ? ? ?nRet = MV_CC_SetEnumValue(handle, "TriggerMode", nTriggerMode); ? ? ? ?if (MV_OK == nRet) ? ? ? { ? ? ? ? ? ?printf("set TriggerMode OK!\n\n"); ? ? ? } ? ? ? ?else ? ? ? { ? ? ? ? ? ?printf("set TriggerMode failed! nRet [%x]\n\n", nRet); ? ? ? }
-
獲取/設(shè)置 Float 類型節(jié)點值
? ? ? ?// 獲取float型變量 ? ? ? ?// get IFloat variable ? ? ? ?MVCC_FLOATVALUE stExposureTime = {0}; ? ? ? ?nRet = MV_CC_GetFloatValue(handle, "ExposureTime", &stExposureTime); ? ? ? ?if (MV_OK == nRet) ? ? ? { ? ? ? ? ? ?printf("exposure time current value:%f\n", stExposureTime.fCurValue); ? ? ? ? ? ?printf("exposure time max value:%f\n", stExposureTime.fMax); ? ? ? ? ? ?printf("exposure time min value:%f\n\n", stExposureTime.fMin); ? ? ? } ? ? ? ?else ? ? ? { ? ? ? ? ? ?printf("get exposure time failed! nRet [%x]\n\n", nRet); ? ? ? } ? ? ? ?// 設(shè)置float型變量 ? ? ? ?// set IFloat variable ? ? ? ?float fExposureTime = 0.0f; ? ? ? ?printf("please input the exposure time to set: "); ? ? ? ?scanf("%f", &fExposureTime); ? ? ? ?nRet = MV_CC_SetFloatValue(handle, "ExposureTime", fExposureTime); ? ? ? ?if (MV_OK == nRet) ? ? ? { ? ? ? ? ? ?printf("set exposure time OK!\n\n"); ? ? ? } ? ? ? ?else ? ? ? { ? ? ? ? ? ?printf("set exposure time failed! nRet [%x]\n\n", nRet); ? ? ? }
-
獲取/設(shè)置 Int 類型節(jié)點值
? ? ? ?// 獲取int型變量 ? ? ? ?// get IInteger variable ? ? ? ?MVCC_INTVALUE stHeight = {0}; ? ? ? ?nRet = MV_CC_GetIntValue(handle, "Height", &stHeight); ? ? ? ?if (MV_OK == nRet) ? ? ? { ? ? ? ? ? ?printf("height current value:%d\n", stHeight.nCurValue); ? ? ? ? ? ?printf("height max value:%d\n", stHeight.nMax); ? ? ? ? ? ?printf("height min value:%d\n", stHeight.nMin); ? ? ? ? ? ?printf("height increment value:%d\n\n", stHeight.nInc); ? ? ? } ? ? ? ?else ? ? ? { ? ? ? ? ? ?printf("get height failed! nRet [%x]\n\n", nRet); ? ? ? } ? ? ? ?// 設(shè)置int型變量 ? ? ? ?// set IInteger variable ? ? ? ?unsigned int nHeightValue = 0; ? ? ? ?printf("please input the height to set:"); ? ? ? ?scanf("%d", &nHeightValue); ? ? ? ?// 寬高設(shè)置時需考慮步進(2),即設(shè)置寬高需2的倍數(shù) ? ? ? ?// Step (16) should be considered when setting width and height, that is the width and height should be a multiple of 2 ? ? ? ?nRet = MV_CC_SetIntValue(handle, "Height", nHeightValue); ? ? ? ? ? ?if (MV_OK == nRet) ? ? ? { ? ? ? ? ? ?printf("set height OK!\n\n"); ? ? ? } ? ? ? ?else ? ? ? { ? ? ? ? ? ?printf("set height failed! nRet [%x]\n\n", nRet); ? ? ? }
-
獲取/設(shè)置 String 類型節(jié)點值
? ? ? ?// 獲取string型變量 ? ? ? ?// get IString variable ? ? ? ?MVCC_STRINGVALUE stStringValue = {0}; ? ? ? ?nRet = MV_CC_GetStringValue(handle, "DeviceUserID", &stStringValue); ? ? ? ?if (MV_OK == nRet) ? ? ? { ? ? ? ? ? ?printf("Get DeviceUserID [%s]\n\n", stStringValue.chCurValue); ? ? ? } ? ? ? ?else ? ? ? { ? ? ? ? ? ?printf("Get DeviceUserID Failed! nRet = [%x]\n\n", nRet); ? ? ? } ? ? ? ?// 設(shè)置string型變量 ? ? ? ?// set IString variable ? ? ? ?unsigned char strValue[256]; ? ? ? ?printf("please input the DeviceUserID to set(string):"); ? ? ? ?scanf("%s", strValue); ? ? ? ?nRet = MV_CC_SetStringValue(handle, "DeviceUserID", (char*)strValue); ? ? ? ?if (MV_OK == nRet) ? ? ? { ? ? ? ? ? ?printf("Set DeviceUserID OK!\n\n"); ? ? ? } ? ? ? ?else ? ? ? { ? ? ? ? ? ?printf("Set DeviceUserID Failed! nRet = [%x]\n\n", nRet); ? ? ? }
-
設(shè)置 Command 類型節(jié)點值
? ? ? ?nRet = MV_CC_SetCommandValue(pUser, "TriggerSoftware"); ? ? ? ?if(MV_OK != nRet) ? ? ? { ? ? ? ? ? ?printf("failed in TriggerSoftware[%x]\n", nRet); ? ? ? } ? ? ? ?nRet = MV_CC_GetOneFrameTimeout(pUser, pData, nDataSize, &stImageInfo, 1000); ? ? ? ?if (nRet == MV_OK) ? ? ? { ? ? ? ? ? ?printf("GetOneFrame, Width[%d], Height[%d], nFrameNum[%d]\n", ? ? ? ? ? ? ? ?stImageInfo.nWidth, stImageInfo.nHeight, stImageInfo.nFrameNum); ? ? ? } ? ? ? ?else ? ? ? { ? ? ? ? ? ?printf("Get One Frame failed![%x]\n", nRet); ? ? ? }
3.開發(fā)過程中遇到的問題
3.1 SDK 文檔中參數(shù)的節(jié)點名、類型、取值范圍、步進等信息與MVS 客戶端中不同
在參數(shù)設(shè)置過程中會發(fā)現(xiàn)SDK 文檔中參數(shù)的節(jié)點名、類型、取值范圍、步進等信息與MVS 客戶端中不同,比如幀率的類型,寬度和高度的步進,或者缺少水平合并和垂直合并等,在這里我們以MVS客戶端 中的數(shù)據(jù)為準(zhǔn)。這里就更體現(xiàn)了 2.2MVS客戶端聯(lián)合使用的必要性。
3.2 錯誤碼的解讀
-
所有工業(yè)相機SDK接口都會返回相應(yīng)的值。如果函數(shù)正常完成而沒有檢測到任何錯誤,則返回值為MV_OK,否則返回錯誤碼 。文章來源:http://www.zghlxwxcb.cn/news/detail-491077.html
-
SDK 文檔中已經(jīng)有對于錯誤碼的必要介紹,更詳細(xì)請訪問鏈接??倒I(yè)相機SDK錯誤碼常見場景解析文章來源地址http://www.zghlxwxcb.cn/news/detail-491077.html
到了這里,關(guān)于Linux下??低暪I(yè)相機的SDK二次開發(fā)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!