-
Notifications
You must be signed in to change notification settings - Fork 1
/
P2_salancy_map.py
51 lines (35 loc) · 1.19 KB
/
P2_salancy_map.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
from twitter_src.crop_api import ImageSaliencyModel
from pathlib import Path
from PIL import Image, ImageDraw
from dspipe import Pipe
import pandas as pd
bin_path = "twitter_src/candidate_crops"
model_path = "twitter_src/fastgaze.vxm"
model = ImageSaliencyModel(
crop_binary_path=bin_path,
crop_model_path=model_path,
)
def compute(f0, f1):
print(f0)
f_img = Path(f0)
img = Image.open(f_img)
w, h = img.size
output = model.get_output(f_img)
print(output["salient_point"])
dx = 5
for pt in output["all_salient_points"]:
x, y, z = pt
draw = ImageDraw.Draw(img)
z *= dx
draw.ellipse((x - z, y - z, x + z, y + z), fill="blue", outline="blue")
x, y = output["salient_point"][0]
z = 10
draw.ellipse((x - z, y - z, x + z, y + z), fill="red", outline="black", width=2)
df = pd.DataFrame(output["all_salient_points"])
f2 = str(f1).replace(".jpg", ".csv")
df.to_csv(f2, index=False)
# draw.rectangle(crop, fill=None, outline='white', width=10)
# draw.rectangle(crop, fill=None, outline='black', width=2)
img.save(f1)
P = Pipe("data/raw_photos/", "data/saliancy_map/", output_suffix=".jpg")
P(compute, -1)