-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.py
45 lines (39 loc) · 1.31 KB
/
helper.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
import os
acceptedExt = ['jpg', 'jpeg','png','bmp', "tiff",'JPG']
def filter_files(filenames):
acceptedFiles = []
for fname in filenames:
ext = (fname.split('.'))[-1]
if ext in acceptedExt:
acceptedFiles.append(fname)
return acceptedFiles
def getPercentOfImageSize(image, percent):
h, w = image.size
return (int(h * (percent/100)), int(w * (percent/100)))
def deleteFileFromDirectory(dir,images):
for im in images:
os.remove(dir+im)
def generateJsonWithThreshold(imgsWithPercentList, threshold):
finalJSON = {}
for obj in imgsWithPercentList:
im1, im2 , percent = obj
if int(percent) <= threshold:
continue
if im1 in finalJSON:
finalJSON[im1].append([im2,percent])
else:
finalJSON[im1] = []
finalJSON[im1].append([im2,percent])
if im2 in finalJSON:
finalJSON[im2].append([im1,percent])
else:
finalJSON[im2] = []
finalJSON[im2].append([im1,percent])
return finalJSON
def filterByThreshold(imgsWithPercentList, threshold):
filteredList = []
for obj in imgsWithPercentList:
im1, im2 , percent = obj
if int(percent) >= threshold:
filteredList.append((im1, im2, percent))
return filteredList