forked from sashaDoubov/PreprocessingOfficeImages
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelabel_split_images.py
More file actions
34 lines (26 loc) · 1005 Bytes
/
relabel_split_images.py
File metadata and controls
34 lines (26 loc) · 1005 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import os
from PIL import Image, ImageDraw, ImageOps
import sys
import ntpath
from tqdm import tqdm
from shutil import copyfile
import random
from collections import defaultdict
import glob
"""
This script may be used if it is desired to label the split images individually, ie. split them into 5 regions first,
then label each individually.
To use: python label_split_images.py <images folder path>
"""
image_folder_path = sys.argv[1]
images = [img for img in glob.glob(os.path.join(image_folder_path, "*.jpg"))]
strip_images = [img.split(".")[0] for img in images]
len_imgs = len(strip_images)
for i, img_name in enumerate(strip_images):
file_path = img_name + '.jpg'
img = Image.open(file_path)
img.show()
input_string = raw_input("Enter string for file {} # {}/{} : ".format(os.path.basename(img_name), i, len_imgs))
txt_path = img_name + '.txt'
with open(txt_path,'w+') as txt_file:
txt_file.write(input_string)