2,代码实现,先加载文件,在将文件路径,坐标保存到文本文件
# -*- coding: utf-8 -*-
import json, os
from PIL import Image
label_path = r"C:\Users\RoseC\Desktop\picture"
save_path = "save_img"
with open("./label.txt", "w+") as f: # 打开文件
for filename in os.listdir(label_path):
# 定义特征点
x1 ,y1 = 0, 0 # 框左上 x: 距左,y:距上
x2, y2 = 0, 0 # 框右下
mark_x1, mark_y1 = 0, 0 # 左上点
mark_x2, mark_y2 = 0, 0 # 右上点
mark_x3, mark_y3 = 0, 0 # 左下点
mark_x4, mark_y4 = 0, 0 # 右下点
if filename.endswith(".json"):
json_path = os.path.join(label_path, filename)
data = json.load(open