refs # Масштабирование изображения до определённой высоты.
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
import cv2
|
import cv2
|
||||||
|
from PIL import Image
|
||||||
|
|
||||||
def rename_files(directory_path: str):
|
def rename_files(directory_path: str):
|
||||||
extensions = set()
|
extensions = set()
|
||||||
@@ -37,8 +38,29 @@ def check_symbols(dir_path: str):
|
|||||||
if any([char not in dict_chars for char in label]):
|
if any([char not in dict_chars for char in label]):
|
||||||
print(filename)
|
print(filename)
|
||||||
|
|
||||||
|
def max_height(dir_path: str):
|
||||||
|
max_height = 0
|
||||||
|
max_filename = ''
|
||||||
|
for filename in os.listdir(dir_path):
|
||||||
|
im = Image.open(os.path.join(dir_path, filename))
|
||||||
|
if im.height > max_height:
|
||||||
|
max_height = im.height
|
||||||
|
max_filename = filename
|
||||||
|
|
||||||
|
print(max_filename, max_height)
|
||||||
|
|
||||||
|
def resize_to_height(dir_path: str, target_height=48):
|
||||||
|
for filename in os.listdir(dir_path):
|
||||||
|
with Image.open(os.path.join(dir_path, filename)) as img:
|
||||||
|
width_percent = target_height / float(img.height)
|
||||||
|
new_width = int(float(img.width) * width_percent)
|
||||||
|
resized_img = img.resize((new_width, target_height), Image.LANZOS)
|
||||||
|
resized_img.save(os.path.join(dir_path, filename))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# rename_files("train_data/images/")
|
# rename_files("train_data/images/")
|
||||||
# check_images("train_data/images/")
|
# check_images("train_data/images/")
|
||||||
# check_labels("train_data/images/")
|
# check_labels("train_data/images/")
|
||||||
check_symbols("train_data/")
|
# check_symbols("train_data/")
|
||||||
|
# max_height("train_data/images")
|
||||||
|
|||||||
Reference in New Issue
Block a user