当前位置: 首页 > news >正文

json缩放 json 缩放

目录

Labelme JSON

json缩放


Labelme JSON

{"version": "5.3.1","flags": {},"imageData": null,"imageHeight": 1080,"imageWidth": 1920,"imagePath": "first_frame.jpg","shapes": [{"label": "1","points": [[870,337],[1213,704]],"group_id": 0,"description": "","shape_type": "rectangle","flags": {}}]
}

json缩放

import json
import copy
import osimport cv2
import numpy as npdef save_rescaled_json(annotation: dict, output_path: str, scale: float):# 深拷贝原始标注,避免修改原对象new_anno = copy.deepcopy(annotation)# 更新图片宽高if "imageHeight" in new_anno:new_anno["imageHeight"] = int(round(new_anno["imageHeight"] * scale))if "imageWidth" in new_anno:new_anno["imageWidth"] = int(round(new_anno["imageWidth"] * scale))# 遍历 shapes 并缩放每个点for shape in new_anno.get("shapes", []):if "points" in shape:pts = np.array(shape["points"], dtype=np.float32)pts *= scaleshape["points"] = pts.tolist()# 保存文件os.makedirs(os.path.dirname(output_path), exist_ok=True)with open(output_path, "w", encoding="utf-8") as f:json.dump(new_anno, f, ensure_ascii=False, indent=2)print(f"✅ 已保存缩放后的标注:{output_path}")if __name__ == '__main__':img_path=r"D:\data\tmp\data_similar\sample\box_frame.jpg"splits=os.path.splitext(img_path)save_path=splits[0]+"_scale.jpg"json_path=splits[0]+".json"json_path_new=splits[0]+"_scale.json"# 1. 读取原始标注with open(json_path, "r", encoding="utf-8") as f:anno = json.load(f)scale=0.5anno['imagePath']=save_path# 2. 缩放并保存save_rescaled_json(anno, json_path_new, scale=scale)img=cv2.imread(img_path)h,w=img.shape[:2]new_w = int(w * scale)new_h = int(h * scale)img_new = cv2.resize(img, (new_w, new_h), interpolation=cv2.INTER_LINEAR)cv2.imwrite(save_path, img_new)

http://www.dtcms.com/a/541031.html

相关文章:

  • maxkb部署,版本升级步骤与注意事项(超详细图文)
  • 测试开发话题02---概念篇
  • 网站建设推广优化排名全国工商核名查询系统官网
  • ASP Content Linking
  • 【研究生随笔】Pytorch中的卷积神经网络(1)
  • Android运行项目报错集合
  • 为什么电脑会蓝屏?怎么快速解决电脑蓝屏问题
  • js建设网站html5网站开发价格
  • ESP32学习笔记(基于IDF):OneNET物模型数据交互(控制小灯)
  • JavaScript逆向与爬虫实战——基础篇(css反爬之动态字体实现原理及绕过)
  • 浏览器在请求 js/css 静态文件时,服务器返回了 500 内部错误 500 Internal Server Error
  • CSS 实现酷炫的不规则圆角与斜角边框效果(四种方法详解)
  • 在线网站地图生成器自建购物网站多少钱
  • 网站开发的整个流程一家只做卫生巾的网站
  • xv6-riscv开发调试环境搭建(vscode+ubuntu)
  • 架构兜底五大手段:构建韧性系统的全面防御体系
  • 阿里巴巴有几个网站是做外贸的wordpress 禅意主题
  • 在 `PaddleOCR` 中配置自定义模型(如自己训练的检测/识别模型)
  • 云谷系统网站开发网站备案要收费吗
  • 前端页面初始化加载速度优化方案
  • 【数据库】金仓数据库构建集团化医院全栈信创“全链路解决方案”
  • MATLAB基于自适应动态特征加权的K-means算法
  • 我的Dify OCR 识别发票准确率测试工具
  • 免费域名申请网站大全封面型网站首页怎么做
  • 专业的网站建设化妆品备案
  • 详解使用CodeBuddy解决高难度项目问题
  • Days.js实时更新时间格式文案在切换全局语言之后的方案
  • 网站icp备案时间网站营销网站营销推广
  • 广州官方宣布网络公司网站优化网站建设
  • 【黑马点评|2 Redis缓存 面试题】