-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRotation by translation.py
68 lines (51 loc) · 1.41 KB
/
Rotation by translation.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# -*- coding: utf-8 -*-
"""
Created on Sun May 19 12:03:54 2019
@author: AshKing
"""
import numpy as np
from math import sin,cos,radians
import cv2 as cv
img = cv.imread('images/perspective transform/example_01.png',1)
img=cv.cvtColor(img,cv.COLOR_BGR2RGB )
centre=(img.shape[0]//2,img.shape[1]//2) #centre of the image
shape=int((img.shape[0]**2+img.shape[1]**2)**0.5) #create a copy of image but size along diagonals
copy=np.zeros((shape,shape))
def mul(*args):
matrices=iter(args) #store first matrix in matrices
mul=next(matrices) #iterator
for i in matrices:
mul=np.matmul(mul,i)
return mul
def shift(x=0,y=0):
return np.array([[1,0,x],[0,1,y],[0,0,1]])
def rot(theta=0):
theta=radians(theta)
return np.array([[cos(theta),
-sin(theta),0],[sin(theta),cos(theta),0]
,[0,0,1]])
def mat(img):
return np.array([[x,y,1]
for x in range(img.shape[0])
for y in range(img.shape[1])]).transpose() #creates an array of size 3*img.size
image=mat(img)
#def scale(x=1,y=1):
# return np.array([[x,0,0],[0,y,0],[0,0,1]])
x=1
y=0
a=0
b=1
rx,ry=(50,50)
#sx=0.3
#sy=0.3
theta=0
final=mul(shift(rx,ry)
,rot(theta)
,shift(-rx,-ry)
,image)
#shift=mul(shift(rx,ry),image)
#a=[shift[0],shift[1]]
#a=np.array(a,dtype=np.uint8)
cv.imshow("ik",img)
cv.waitKey(0)
cv.destroyAllWindows()