isat将标签转化为labelme格式后,labelme打不开的解决方案
亲测解决路径如下:
1、首先将图像和转化后的labelme格式的标签放在统一文件夹里(也就是混合放,比如放在e盘的test文件夹下)
2、运行如下代码,来填充 "imageData":字段
import os
import json
import base64# JSON 和图片所在的文件夹
folder = r"E:\test"# 遍历文件夹
for file in os.listdir(folder):if file.endswith(".json"):json_path = os.path.join(folder, file)# 打开 JSONwith open(json_path, "r", encoding="utf-8") as f:data = json.load(f)# 获取 imagePathimg_name = data.get("imagePath")if not img_name:print(f"⚠️ JSON 中没有 imagePath: {file}")continue# 图片完整路径img_path = os.path.join(folder, img_name)# 检查图片是否存在if not os.path.exists(img_path):print(f"❌ 图片不存在: {img_path}")continue# 读取图片并转为 Base64with open(img_path, "rb") as img_f:img_bytes = img_f.read()img_b64 = base64.b64encode(img_bytes).decode("utf-8")# 填充到 JSONdata["imageData"] = img_b64# 保存回 JSON 文件with open(json_path, "w", encoding="utf-8") as f:json.dump(data, f, ensure_ascii=False, indent=4)print(f"✅ 填充完成: {file}")print("所有 JSON 文件处理完成!")
3、使用labelme打开test文件夹,即可正常显示标注内容