-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtranslation.py
More file actions
44 lines (36 loc) · 1.05 KB
/
translation.py
File metadata and controls
44 lines (36 loc) · 1.05 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
import numpy as np
import argparse
import imutils
import cv2
ap = argparse.ArgumentParser()
ap.add_argument('-i', '--image', required=True,
help='Path to image')
args = vars(ap.parse_args())
image = cv2.imread(args['image'])
cv2.imshow('Original', image)
cv2.waitKey(0)
M = np.float32([[1, 0, -50], [0, 1, -90]])
shifted = cv2.warpAffine(image, M, (image.shape[1], image.shape[0]))
cv2.imshow('Shifted up and left', shifted)
cv2.waitKey(0)
M = np.float32([[1, 0, 25], [0, 1, 50]])
shifted = cv2.warpAffine(image, M, (image.shape[1], image.shape[0]))
cv2.imshow('Shifted down and right', shifted)
cv2.waitKey(0)
'''
imutils.py
#does image translation
import numpy as np
import cv2
def translate(image, x, y):
M = np.float32([[1, 0, x],[0, 1, y]])
shifted = cv2.warpAffine(image, M, (image.shape[1].
image.shape[0]))
return shifted
'''
shifted = imutils.translate(image, 0, 100)
cv2.imshow('Shifted down', shifted)
cv2.waitKey(0)
shifted = imutils.translate(image, -50, -100)
cv2.imshow('Shifted up and left', shifted)
cv2.waitKey(0)