当前位置: 首页 > 后端技术 > Python

关键点标注【json转mat】

时间:2023-03-25 23:26:00 Python

它在json中的样子:{"version":"4.5.7","flags":{},"shapes":[{"label":"wood","points":[[739.3162393162394,482.0512820512821]],"group_id":null,"shape_type":"point","flags":{}},{"label":"wood","points":[[758.1196581196582,458.11965811965814]],"group_id":null,"shape_type":"point","flags":{}},],"imagePath":"..\\img\\141.jpg","imageData":"......base64编码的theimage,Verylong.......","imageHeight":1080,"imageWidth":1920}重要的信息是里面点的坐标,其他的不用。提取方法如下:importjsonimportnumpyasnpimportscipy.ioassioimportscipy.ioassioimportmatplotlib.pyplotaspltimportshutilimportospath='D:/test/wood/yi'files=os.listdir(path)forname在文件中:ifname.endswith('.json'):print(name)fp=open(os.path.join(path,name),'r')json_data=json.load(fp)points_data=json_data['shapes']points=[]forpointinpoints_data:points.append(point['points'][0])sio.savemat(os.path.join('./mat',name.replace('.json','.mat')),{'annPoints':points,'num':len(points)})