labelme imageData 格式

由labelme 生成的json格式如下:

其中生成imageData数据是将图像数据整体进行保存的包括数据头,除了jpg和jpeg以jpeg保存外其他格式图片都按png保存,并将保存在内存里的数据通过base64加密处理后输出到json中。

json格式如下:

{
  "version": "3.16.7",
  "flags": {},
  "shapes": [
    {
      "label": "人群",
      "line_color": null,
      "fill_color": null,
      "points": [
        [
          328.14285714285717,
          114.04761904761904
        ],
        [
          318.61904761904765,
          175.95238095238096
        ],
        [
          494.80952380952385,
          314.04761904761904
        ],
        [
          504.33333333333337,
          214.04761904761904
        ]
      ],
      "shape_type": "polygon",
      "flags": {}
    },
    {
      "label": "天空",
      "line_color": null,
      "fill_color": null,
      "points": [
        [
          842.4285714285714,
          114.04761904761904
        ],
        [
          837.6666666666667,
          204.52380952380963
        ],
        [
          1013.8571428571429,
          318.80952380952385
        ],
        [
          999.5714285714287,
          204.52380952380963
        ]
      ],
      "shape_type": "polygon",
      "flags": {}
    }
  ],
  "lineColor": [
    0,
    255,
    0,
    128
  ],
  "fillColor": [
    255,
    0,
    0,
    128
  ],
  "imagePath": "2019_6_25_9_4_29000.bmp",
  "imageData": "iVBORw0KGgoAAAANSUhEUgAABgAAAAIACAAAAABhyvikAAEAAElEQVR4nDT9zY.....................,
  "imageHeight": 512,
  "imageWidth": 1536
} 

 

 

相关保存源码如下:


 

 with io.BytesIO() as f:
            ext = osp.splitext(filename)[1].lower()
            if PY2 and QT4:
                format = 'PNG'
            elif ext in ['.jpg', '.jpeg']:
                format = 'JPEG'
            else:
                format = 'PNG'
            image_pil.save(f, format=format)
            f.seek(0)
            return f.read()

    def load(self, filename):
        keys = [
            'imageData',
            'imagePath',
            'lineColor',
            'fillColor',
            'shapes',  # polygonal annotations
            'flags',   # image level flags
            'imageHeight',
            'imageWidth',
        ]
        try:
            with open(filename, 'rb' if PY2 else 'r') as f:
                data = json.load(f)
            if data['imageData'] is not None:
                imageData = base64.b64decode(data['imageData'])
                if PY2 and QT4:
                    imageData = utils.img_data_to_png_data(imageData)
            else:
                # relative path from label file to relative path from cwd
                imagePath = osp.join(osp.dirname(filename), data['imagePath'])
                imageData = self.load_image_file(imagePath)
            flags = data.get('flags') or {}
            imagePath = data['imagePath']
            self._check_image_height_and_width(
                base64.b64encode(imageData).decode('utf-8'),
                data.get('imageHeight'),
                data.get('imageWidth'),
            )
            lineColor = data['lineColor']
            fillColor = data['fillColor']
            shapes = (
                (
                    s['label'],
                    s['points'],
                    s['line_color'],
                    s['fill_color'],
                    s.get('shape_type', 'polygon'),
                    s.get('flags', {}),
                )
                for s in data['shapes']
            )
        except Exception as e:
            raise LabelFileError(e)

        otherData = {}
        for key, value in data.items():
            if key not in keys:
                otherData[key] = value

        # Only replace data after everything is loaded.
        self.flags = flags
        self.shapes = shapes
        self.imagePath = imagePath
        self.imageData = imageData
        self.lineColor = lineColor
        self.fillColor = fillColor
        self.filename = filename
        self.otherData = otherData

 

  • 6
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 8
    评论
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值