#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ 一键生成“纯背景”COCO格式json(annotations为空) """ import os import json import glob from PIL import Image from datetime import datetime def generate_empty_coco_json(image_folder, output_json_path, start_image_id=500000): """ 将文件夹内所有图片写成COCO格式(无标注) :param image_folder: 纯背景图片目录 :param output_json_path: 输出json路径 :param start_image_id: 起始image_id,避免冲突 """ exts = ["*.jpg", "*.jpeg", "*.png", "*.bmp", "*.tif", "*.tiff"] image_files = [] for ext in exts: image_files.extend(glob.glob(os.path.join(image_folder, ext))) image_files.extend(glob.glob(os.path.join(image_folder, ext.upper()))) image_files = sorted(list(set(image_files))) if not image_files: print(f"× 在{image_folder}下未找到图片,请检查路径。") return print(f"√ 找到{len(image_files)}张背景图片,开始处理...") coco_output = { "info": { "description": "Empty Background Images for Negative Mining", "url": "", "version": "1.0", "year": datetime.now().year, "contributor": "User", "date_created": datetime.now().strftime("%Y-%m-%d %H:%M:%S") }, "licenses": [], "images": [], "annotations": [], # 关键:空列表 "categories": [] # 可留空,合并时以主文件为准 } for idx, img_path in enumerate(image_files): try: with Image.open(img_path) as img: width, height = img.size file_name = os.path.basename(img_path) image_info = { "id": start_image_id + idx, "file_name": file_name, "width": width, "height": height, "date_captured": datetime.now().strftime("%Y-%m-%d %H:%M:%S") } coco_output["images"].append(image_info) if (idx + 1) % 100 == 0: print(f"√ 已处理{idx + 1}张图片...") except Exception as e: print(f"× 无法读取图片{img_path}:{e}") os.makedirs(os.path.dirname(output_json_path), exist_ok=True) with open(output_json_path, 'w', encoding='utf-8') as f: json.dump(coco_output, f, indent=4, ensure_ascii=False) print(f"成功生成JSON文件:{output_json_path}") print(f"共包含{len(coco_output['images'])}张图片,0个标注。") if __name__ == "__main__": # ===== 按需改这两行 ===== IMAGE_DIR = r"C:\Users\11726\Desktop\pla\ao-90" # 纯背景图文件夹 OUTPUT_JSON = r"C:\Users\11726\Desktop\pla/empty_samples.json" START_ID = 500000 # 起始image_id # ======================= generate_empty_coco_json(IMAGE_DIR, OUTPUT_JSON, START_ID)空白数据生成coco
张小明
前端开发工程师
TF-A上电后从`bl1_entrypoint`执行的原因
TF-A上电后从bl1_entrypoint执行的原因涉及硬件启动机制和软件设计的结合。让我详细解释: 1. 硬件层面的原因 ARM架构的启动流程 上电/复位 → CPU从固定地址开始执行 → 执行第一条指令对于大多数ARM处理器: 复位向量地址固定:CPU复位后&…
ImageToSTL终极指南:从平面图片到立体实体的完整转换教程
ImageToSTL终极指南:从平面图片到立体实体的完整转换教程 【免费下载链接】ImageToSTL This tool allows you to easily convert any image into a 3D print-ready STL model. The surface of the model will display the image when illuminated from the left sid…
为什么90%的企业用不好库存预警?Agent建模中的5个致命盲区曝光
第一章:供应链 Agent 的库存预警在现代供应链系统中,自动化库存管理是保障运营效率的核心环节。通过引入智能 Agent 技术,企业能够实现对库存水平的实时监控与动态预警,从而有效避免缺货或积压问题。Agent 的核心职责 供应链 Agen…
Web扩展跨平台开发终极指南:架构决策与设计模式深度解析
Web扩展跨平台开发终极指南:架构决策与设计模式深度解析 【免费下载链接】PT-Plugin-Plus PT 助手 Plus,为 Microsoft Edge、Google Chrome、Firefox 浏览器插件(Web Extensions),主要用于辅助下载 PT 站的种子。 项…
【专家级实战分享】:打造下一代农业灌溉Agent的7个关键技术点
第一章:农业种植Agent灌溉策略的核心价值在现代农业智能化转型中,基于Agent的灌溉策略正成为提升水资源利用效率与作物产量的关键技术。通过部署具备感知、决策与执行能力的智能Agent,系统能够实时采集土壤湿度、气象数据及作物生长状态&…