您好,登錄后才能下訂單哦!
這篇文章主要介紹“Halcon怎么讀取json文件”,在日常操作中,相信很多人在Halcon怎么讀取json文件問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對(duì)大家解答”Halcon怎么讀取json文件”的疑惑有所幫助!接下來,請(qǐng)跟著小編一起來學(xué)習(xí)吧!
①定義
get_dict_tuple( DictHandle, Key , Tuple)
DictHandle:字典句柄
key:鍵
tuple:根據(jù)Key在句柄下取內(nèi)容,存放到tuple中
②功能:從字典中檢索與鍵關(guān)聯(lián)的元組
①定義
get_dict_param( DictHandle, GenParamName, Key ,GenParamValue)
DictHandle:字典句柄
GenParamName:根據(jù)參數(shù)在字典中查詢相關(guān)信息。當(dāng)填寫’keys’時(shí),默認(rèn)取所有元素
key:鍵??梢圆惶顑?nèi)容,直接寫 []
GenParamValue:讀取的內(nèi)容存放
②功能:查詢字典參數(shù)或有關(guān)字典的信息。
有些原理我也不是特別清楚,但通過實(shí)踐幾次之后,略有所感。所有,實(shí)踐是檢驗(yàn)真理的唯一標(biāo)準(zhǔn),多動(dòng)手。
************以下是我json文件內(nèi)容*************** * {"path":"C:\\Users\\Administrator\\Desktop\\算子開發(fā)任務(wù)書\\000001.png", * "outputs":{"object":[{"name":"sharp","polygon":{"x1":2613,"y1":418,"x2":2686,"y2":1218,"x3":2722,"y3":2054,"x4":2759,"y4":2372,"x5":2795,"y5":2445,"x6":2759,"y6":3136,"x7":2777,"y7":3136,"x8":2831,"y8":2881,"x9":2904,"y9":4263,"x10":3013,"y10":4263,"x11":3013,"y11":3900,"x12":3086,"y12":3881,"x13":3140,"y13":4263,"x14":3268,"y14":4263,"x15":3086,"y15":2972,"x16":3131,"y16":2900,"x17":3177,"y17":3100,"x18":3231,"y18":3109,"x19":3050,"y19":2154,"x20":3122,"y20":2172,"x21":3013,"y21":1072,"x22":2977,"y22":336,"x23":2868,"y23":309,"x24":2904,"y24":590,"x25":2777,"y25":572,"x26":2722,"y26":372}}]}, * "time_labeled":1582335060421, * "labeled":true, * "size":{"width":3798,"height":8748,"depth":3}} *讀取json文件,將內(nèi)容放入字典中 read_dict('data.json',[],[],DictJson) *取字典中所有關(guān)鍵字 get_dict_param(DictJson,'keys',[],ALLKeys) *讀取outputs下的內(nèi)容 get_dict_tuple(DictJson,'outputs',outputsDict) *取字典中所有關(guān)鍵字 *這一步其實(shí)是對(duì)outputs內(nèi)容的讀取,但讀取的內(nèi)容可能是地址信息 get_dict_param(outputsDict,'keys',[],outputsDictAllKeys) *根據(jù)‘地址'信息將內(nèi)容讀入到元組中 get_dict_tuple(outputsDict,outputsDictAllKeys,outputsObjectDict) *讀取元組數(shù)據(jù) get_dict_param(outputsObjectDict,'keys',[],outputsObjectDictALLKeys) *元組中數(shù)據(jù)數(shù)量統(tǒng)計(jì)(其中元組中有小元組,而數(shù)量是指小元組的數(shù)量) num:=|outputsObjectDictALLKeys| *遍歷 for keysIndex:=0 to num-1 by 1 try get_dict_tuple(outputsObjectDict,outputsObjectDictALLKeys[keysIndex],objectDict) get_dict_param(objectDict,'keys',[],objectDictAllKeys) *標(biāo)注類型 矩形框還是多邊形 objectShape:=objectDictAllKeys[1] get_dict_tuple (objectDict, objectDictAllKeys[1], objectLabelPosition) get_dict_param(objectLabelPosition,'keys',[],objectLabelPositionDictAllKeys) *矩形框 if(objectShape='bndbox') get_dict_tuple(objectLabelPosition,objectLabelPositionDictAllKeys[0],xMin) get_dict_tuple (objectLabelPosition, objectLabelPositionDictAllKeys[1], yMin) get_dict_tuple (objectLabelPosition, objectLabelPositionDictAllKeys[2], xMax) get_dict_tuple (objectLabelPosition, objectLabelPositionDictAllKeys[3], yMax) *創(chuàng)建一個(gè)矩形 gen_rectangle1(labelRegion,yMin,xMin,yMax,xMax) endif *多邊形 if(objectShape='polygon') bufX:=[] bufY:=[] for keysIndex0:=0 to |objectLabelPositionDictAllKeys|/2-1 by 1 xAddr:=keysIndex0*2 yAddr:=xAddr+1 get_dict_tuple (objectLabelPosition, objectLabelPositionDictAllKeys[xAddr], positionX) bufX:=[bufX,positionX] get_dict_tuple (objectLabelPosition, objectLabelPositionDictAllKeys[yAddr], positionY) bufY:=[bufY,positionY] endfor bufX:=[bufX,bufX[0]] bufY:=[bufY,bufY[0]] *創(chuàng)建多邊形 gen_region_polygon(labelRegion,bufY,bufX) fill_up(labelRegion,labelRegion) endif *讀取 name 內(nèi)容,存放到objectName中 get_dict_tuple(objectDict,objectDictAllKeys[0],objectName) catch (Exception) endtry endfor
到此,關(guān)于“Halcon怎么讀取json文件”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注億速云網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)砀鄬?shí)用的文章!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。