second
This commit is contained in:
35
EM18恢复原状.py
Normal file
35
EM18恢复原状.py
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
import os
|
||||||
|
import re
|
||||||
|
import shutil
|
||||||
|
|
||||||
|
# ====== 配置 ======
|
||||||
|
input_dir = r"E:\数据标注\REJ\EM 18 REJ" # 原始 XML 文件夹路径
|
||||||
|
output_dir = r"E:\数据标注\REJ\EM18REJ修改" # 修改后 XML 文件输出路径
|
||||||
|
offset = 1450 # 要裁掉的像素值
|
||||||
|
|
||||||
|
# 创建输出文件夹(如果不存在)
|
||||||
|
os.makedirs(output_dir, exist_ok=True)
|
||||||
|
|
||||||
|
def process_xml(file_path, output_path, offset):
|
||||||
|
with open(file_path, 'r', encoding='utf-8') as f:
|
||||||
|
content = f.read()
|
||||||
|
|
||||||
|
if "<height>1350</height>" in content:
|
||||||
|
new_width = 2800 - offset
|
||||||
|
new_content = content.replace("<height>1350</height>", f"<height>2800</height>")
|
||||||
|
|
||||||
|
with open(output_path, 'w', encoding='utf-8') as f:
|
||||||
|
f.write(new_content)
|
||||||
|
|
||||||
|
print(f"✅ 修改并保存: {os.path.basename(file_path)} → 宽度 {new_width}")
|
||||||
|
else:
|
||||||
|
# 直接复制未修改的文件
|
||||||
|
shutil.copy(file_path, output_path)
|
||||||
|
print(f"↪ 保持原样: {os.path.basename(file_path)}")
|
||||||
|
|
||||||
|
|
||||||
|
for filename in os.listdir(input_dir):
|
||||||
|
if filename.lower().endswith(".xml"):
|
||||||
|
input_path = os.path.join(input_dir, filename)
|
||||||
|
output_path = os.path.join(output_dir, filename)
|
||||||
|
process_xml(input_path, output_path, offset)
|
||||||
35
裁剪EM18XML.py
Normal file
35
裁剪EM18XML.py
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
import os
|
||||||
|
import re
|
||||||
|
import shutil
|
||||||
|
|
||||||
|
# ====== 配置 ======
|
||||||
|
input_dir = r"E:\Train\EM 18 REJ" # 原始 XML 文件夹路径
|
||||||
|
output_dir = r"E:\Train\EM18Output" # 修改后 XML 文件输出路径
|
||||||
|
offset = 1450 # 要裁掉的像素值
|
||||||
|
|
||||||
|
# 创建输出文件夹(如果不存在)
|
||||||
|
os.makedirs(output_dir, exist_ok=True)
|
||||||
|
|
||||||
|
def process_xml(file_path, output_path, offset):
|
||||||
|
with open(file_path, 'r', encoding='utf-8') as f:
|
||||||
|
content = f.read()
|
||||||
|
|
||||||
|
if "<height>2800</height>" in content:
|
||||||
|
new_width = 2800 - offset
|
||||||
|
new_content = content.replace("<height>2800</height>", f"<height>{new_width}</height>")
|
||||||
|
|
||||||
|
with open(output_path, 'w', encoding='utf-8') as f:
|
||||||
|
f.write(new_content)
|
||||||
|
|
||||||
|
print(f"✅ 修改并保存: {os.path.basename(file_path)} → 宽度 {new_width}")
|
||||||
|
else:
|
||||||
|
# 直接复制未修改的文件
|
||||||
|
shutil.copy(file_path, output_path)
|
||||||
|
print(f"↪ 保持原样: {os.path.basename(file_path)}")
|
||||||
|
|
||||||
|
|
||||||
|
for filename in os.listdir(input_dir):
|
||||||
|
if filename.lower().endswith(".xml"):
|
||||||
|
input_path = os.path.join(input_dir, filename)
|
||||||
|
output_path = os.path.join(output_dir, filename)
|
||||||
|
process_xml(input_path, output_path, offset)
|
||||||
@@ -2,8 +2,8 @@ import os
|
|||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
# === 参数配置 ===
|
# === 参数配置 ===
|
||||||
input_folder = r"D:\PythonProject\AutoAnno\还没clip" # 原图所在文件夹
|
input_folder = r"E:\Train\EM 18 REJ" # 原图所在文件夹
|
||||||
output_folder = r"D:\PythonProject\AutoAnno\test_images" # 裁剪后保存的文件夹
|
output_folder = r"E:\Train\EM18Output" # 裁剪后保存的文件夹
|
||||||
crop_right_pixels = 1450 # 要裁掉的右侧像素数量
|
crop_right_pixels = 1450 # 要裁掉的右侧像素数量
|
||||||
|
|
||||||
# 如果输出文件夹不存在则创建
|
# 如果输出文件夹不存在则创建
|
||||||
|
|||||||
Reference in New Issue
Block a user