|
|
import os
|
|
|
import zipfile
|
|
|
import re
|
|
|
|
|
|
|
|
|
def extract_and_rename(zip_path, output_folder):
|
|
|
if not os.path.exists(output_folder):
|
|
|
os.makedirs(output_folder)
|
|
|
|
|
|
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
|
|
|
for file in zip_ref.namelist():
|
|
|
match = re.search(r'images/with_ground_truth/(.+)/(HighQualityRender\d{4}\.png)', file)
|
|
|
if match:
|
|
|
scene_lights_movements = match.group(1).replace('/', '_').replace(' ', '_')
|
|
|
png_filename = match.group(2)
|
|
|
new_filename = f"{scene_lights_movements}_{png_filename[-8:]}"
|
|
|
|
|
|
|
|
|
extracted_path = os.path.join(output_folder, new_filename)
|
|
|
with zip_ref.open(file) as src, open(extracted_path, 'wb') as dst:
|
|
|
dst.write(src.read())
|
|
|
|
|
|
|
|
|
txt_filename = os.path.splitext(new_filename)[0] + ".txt"
|
|
|
txt_path = os.path.join(output_folder, txt_filename)
|
|
|
keywords = scene_lights_movements.replace("_", ",")
|
|
|
with open(txt_path, 'w') as txt_file:
|
|
|
txt_file.write(f"realistic fur, {keywords}")
|
|
|
|
|
|
print(f"Extracted: {new_filename}, Created: {txt_filename}")
|
|
|
|
|
|
|
|
|
|
|
|
zip_file_path = "synthetic_fur_images.zip"
|
|
|
output_directory = "synthetic_fur_groundtruth"
|
|
|
extract_and_rename(zip_file_path, output_directory) |