-
Notifications
You must be signed in to change notification settings - Fork 0
/
00_02_transformations.py
50 lines (32 loc) · 1.07 KB
/
00_02_transformations.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
from configparser import Interpolation
from fnmatch import translate
import cv2 as cv
import numpy as np
img = cv.imread("img/car_and_road.jpg")
cv.imshow("Original image", img)
# Transfpormation
def translate(img, x, y):
transMat = np.float32([[1, 0, x],[0,1,y]])
dimenstions = (img.shape[1], img.shape[0])
return cv.warpAffine(img, transMat, dimenstions)
translated = translate(img, 100, 200)
cv.imshow('Translated', translated)
# Rotation
def rotate(img, angle, rotPoint=None):
(height, width) = img.shape[:2]
if(rotPoint is None):
rotPoint = (width//2, height//2)
rotMat = cv.getRotationMatrix2D(rotPoint, angle, 1.0)
dimensions = (width, height)
return cv.warpAffine(img, rotMat, dimensions)
rotated = rotate(img, 1)
for _ in range(360):
rotated = rotate(rotated, 1)
cv.imshow('Rotated', rotated)
# Resizing
resized = cv.resize(img, (500, 500), interpolation=cv.INTER_CUBIC)
cv.imshow('Resized', resized)
# Flipping
flip = cv.flip(img, 0)
cv.imshow('Flipped', flip)
cv.waitKey(0)