-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisualizer.py
More file actions
39 lines (32 loc) · 800 Bytes
/
Copy pathvisualizer.py
File metadata and controls
39 lines (32 loc) · 800 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
35
36
37
38
39
import sys
import cv2
import numpy as np
from PIL import Image
def mask_image(image, coordinates):
mask = np.zeros(image.shape[:2]).flatten()
for x in coordinates:
try:
mask[x - 1] = 255
except:
print len(mask), x
return mask.reshape(image.shape[:2])
def load_points(filename):
f = open(filename, 'r')
points = []
for row in f:
x,y = row.rstrip('\n').split(' ')
x,y = int(x), int(y)
points.append((x,y))
return points
def load_object_points(filename):
f = open(filename, 'r')
points = []
for row in f:
x = int(row.rstrip('\n'))
points.append(x)
return points
if __name__ == "__main__":
image = cv2.imread(sys.argv[1])
points = load_object_points(sys.argv[2])
mask = mask_image(image, points)
cv2.imwrite('images/segmented_' + sys.argv[1].split('/')[1], mask)