-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmosaic.py
More file actions
67 lines (63 loc) · 1.59 KB
/
mosaic.py
File metadata and controls
67 lines (63 loc) · 1.59 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
"""
Composed image from multiple small images
usage:
./mosaic.py <pattern.csv> <output filename>
CSV:
<filename>,<x>,<y>,<degAngle>
"""
import sys
import cv2
import numpy as np
import csv
import math
DESIRED_SIZE = 1200,800
SCALE = 0.5
def mosaic( csvFile ):
result = None
reader = csv.reader( open(csvFile) )
for row in reader:
filename = row[0]
x, y, degAngle = [int(t) for t in row[1:]]
img = cv2.imread( filename, cv2.CV_LOAD_IMAGE_COLOR )
while True:
a = math.radians(int(degAngle))
M = np.float32( [[SCALE*math.cos(a), SCALE*math.sin(a), x],
[SCALE*-math.sin(a), SCALE*math.cos(a), y],
[0,0,1]])
img2 = cv2.warpPerspective(img,M,DESIRED_SIZE)
tmp = result
if tmp != None:
tmp = cv2.add(result,img2)
else:
tmp = img2
cv2.imshow('result', tmp)
key = cv2.waitKey()
if key == 2424832: # left
x -= 1
elif key == 2555904: # right
x += 1
elif key == 2490368: # up
y -= 1
elif key == 2621440: # down
y += 1
# elif key =
elif key == 113: # q turn clockwise
degAngle += 1
elif key == 97: # a turn anticlockwise
degAngle -= 1
elif key == 13:
break
elif key == 27: # ESC
return None
else:
print key
print "%s,%d,%d,%d" % (filename,x,y,degAngle)
result = tmp
return result
if __name__ == "__main__":
if len(sys.argv) < 3:
print __doc__
sys.exit(1)
img = mosaic( sys.argv[1] )
if img != None:
cv2.imwrite( sys.argv[2], img )