您好,登录后才能下订单哦!
这篇文章主要介绍“Halcon怎么读取json文件”,在日常操作中,相信很多人在Halcon怎么读取json文件问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”Halcon怎么读取json文件”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
①定义
get_dict_tuple( DictHandle, Key , Tuple)
DictHandle:字典句柄
key:键
tuple:根据Key在句柄下取内容,存放到tuple中
②功能:从字典中检索与键关联的元组
①定义
get_dict_param( DictHandle, GenParamName, Key ,GenParamValue)
DictHandle:字典句柄
GenParamName:根据参数在字典中查询相关信息。当填写’keys’时,默认取所有元素
key:键。可以不填内容,直接写 []
GenParamValue:读取的内容存放
②功能:查询字典参数或有关字典的信息。
有些原理我也不是特别清楚,但通过实践几次之后,略有所感。所有,实践是检验真理的唯一标准,多动手。
************以下是我json文件内容*************** * {"path":"C:\\Users\\Administrator\\Desktop\\算子开发任务书\\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文件,将内容放入字典中 read_dict('data.json',[],[],DictJson) *取字典中所有关键字 get_dict_param(DictJson,'keys',[],ALLKeys) *读取outputs下的内容 get_dict_tuple(DictJson,'outputs',outputsDict) *取字典中所有关键字 *这一步其实是对outputs内容的读取,但读取的内容可能是地址信息 get_dict_param(outputsDict,'keys',[],outputsDictAllKeys) *根据‘地址'信息将内容读入到元组中 get_dict_tuple(outputsDict,outputsDictAllKeys,outputsObjectDict) *读取元组数据 get_dict_param(outputsObjectDict,'keys',[],outputsObjectDictALLKeys) *元组中数据数量统计(其中元组中有小元组,而数量是指小元组的数量) num:=|outputsObjectDictALLKeys| *遍历 for keysIndex:=0 to num-1 by 1 try get_dict_tuple(outputsObjectDict,outputsObjectDictALLKeys[keysIndex],objectDict) get_dict_param(objectDict,'keys',[],objectDictAllKeys) *标注类型 矩形框还是多边形 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) *创建一个矩形 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]] *创建多边形 gen_region_polygon(labelRegion,bufY,bufX) fill_up(labelRegion,labelRegion) endif *读取 name 内容,存放到objectName中 get_dict_tuple(objectDict,objectDictAllKeys[0],objectName) catch (Exception) endtry endfor
到此,关于“Halcon怎么读取json文件”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。