-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerateCropOnly.py
100 lines (73 loc) · 2.76 KB
/
generateCropOnly.py
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# The function of this python script is to generate cropped images as output.
# run using: py generateCropOnly.py
import PIL
import os
import os.path
import cv2
from PIL import Image
import sys
import numpy as np
# Assumes images are in 1944x2592 dimensions and in .jpg format
sourceFolder = "./source"
sourceFolderCropped = "xxx"
currentDir="xxx"
def cropTopLeft():
(left, upper, right, lower) = (0, 0, 1024, 1024)
for file in os.listdir(sourceFolder):
f_img = sourceFolder+"/"+file
img = Image.open(f_img)
# Cropping
img = img.crop((left, upper, right, lower))
# You should change 'test' to your preferred folder.
MYDIR = ("sourceFolderCropped")
CHECK_FOLDER = os.path.isdir(MYDIR)
# If folder doesn't exist, then create it.
if not CHECK_FOLDER:
os.makedirs(MYDIR)
print("created folder : ", MYDIR)
# You should change 'test' to your preferred folder.
MYDIR2 = ("Final")
CHECK_FOLDER = os.path.isdir(MYDIR2)
# If folder doesn't exist, then create it.
if not CHECK_FOLDER:
os.makedirs(MYDIR2)
print("created folder : ", MYDIR2)
newDir = os.path.join(os.getcwd(), MYDIR)
global sourceFolderCropped
global currentDir
sourceFolderCropped = newDir
currentDir = os.path.join(os.getcwd(), "Final")
file = "cropTopLeft" + file
destination = os.path.join(os.getcwd(), MYDIR, file)
destination2 = os.path.join(currentDir, file)
#print(destination)
img.save(destination)
img.save(destination2)
def cropBottomLeft():
(left, upper, right, lower) = (0, 1568, 1024, 2592)
for file in os.listdir(sourceFolder):
f_img = sourceFolder+"/"+file
img = Image.open(f_img)
# Cropping
img = img.crop((left, upper, right, lower))
# You should change 'test' to your preferred folder.
MYDIR = ("sourceFolderCropped")
CHECK_FOLDER = os.path.isdir(MYDIR)
# If folder doesn't exist, then create it.
if not CHECK_FOLDER:
os.makedirs(MYDIR)
print("created folder : ", MYDIR)
newDir = os.path.join(os.getcwd(), MYDIR)
global sourceFolderCropped
sourceFolderCropped = newDir
#print(sourceFolderCropped)
file = "cropBottomLeft" + file
destination = os.path.join(os.getcwd(), MYDIR, file)
#print(destination)
destination2 = os.path.join(currentDir, file)
#print(destination)
img.save(destination)
img.save(destination2)
cropTopLeft()
cropBottomLeft()
print("Done!")