forked from quentinl-c/citizensourcing
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateSelectTask.py
More file actions
70 lines (56 loc) · 1.78 KB
/
createSelectTask.py
File metadata and controls
70 lines (56 loc) · 1.78 KB
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
from __future__ import print_function
import os, sys
from PIL import Image
import time
import glob
__author__ = 'charoy'
githubpath="https://raw.githubusercontent.com/charoy/citizensourcing/master/corpus/select/"
def merge(imgs,newimg):
band_size = 30
images = map(Image.open,imgs)
print(images)
mh = min(i.size[1] for i in images)
print(mh)
w = 0
out_images = []
for img in images:
if img.size[1] > mh:
rat = float(img.size[0]) / float(img.size[1])
out = img.resize((int(mh * rat), mh))
else:
out = img
w += out.size[0]
out_images.append(out)
w += (len(images) -1) * band_size
result = Image.new("RGBA", (w, mh),"white")
x = 0
for i in out_images:
result.paste(i, (x, 0))
x += i.size[0] + band_size
result.save(newimg)
import itertools
def findsubsets(S,m):
return set(itertools.combinations(S, m))
def createtasks(path,taskfile):
imgpath=path+"/*_*.jpg"
images=glob.glob(imgpath)
result=findsubsets(images,2)
dirname=os.path.split(path)[1]
print(dirname)
count=0;
for s in result:
merge(s,path+"/result"+str(count)+".jpg")
taskfile.write("2,"+githubpath+dirname+"/result"+str(count)+".jpg\n")
count+=1
def createcsv(path,taskfile):
tasklist=glob.glob(path+"/*")
print(tasklist)
count=1;
for i in tasklist:
createtasks(i,taskfile)
if __name__ == "__main__":
images=glob.glob("C:/Users/charoy/PyCharmProject/mycitizensourcing/corpus/select/1/*_n.jpg")
taskfile=open("C:/Users/charoy/PyCharmProject/mycitizensourcing/corpus/select/task.csv","w")
taskfile.write("len,img\n")
createcsv("C:/Users/charoy/PyCharmProject/mycitizensourcing/corpus/select",taskfile)
taskfile.close()