-
Notifications
You must be signed in to change notification settings - Fork 0
/
transformations.py
70 lines (45 loc) · 1.71 KB
/
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import cv2 as cv
import numpy as np
img = cv.imread('Photos/park.jpg')
cv.imshow('Park', img)
# #----> Translation
# def translation(image, x, y):
# transMat = np.float32([[1,0,x], [0,1,y]])
# dimension = (image.shape[1], image.shape[0])
# return cv.warpAffine(image, transMat, dimension)
# # x ---> Right
# # y ---> Down
# #-y ---> Up
# #-x ---> Left
# trans = translation(img, 100, -100)
# cv.imshow('Translated', trans)
# #----> Rotation
# def rotation(image, angle, rotationPoint=None):
# (height, width) = image.shape[0], image.shape[1] ## Could be written as (height, width) = image.shape[:2]
# if rotationPoint is None: #we are going to assume that we want to rotate in center
# rotationPoint = (width//2, height//2)
# rotationMatrix = cv.getRotationMatrix2D(rotationPoint, angle, 1.0)
# dimen = (width, height)
# return cv.warpAffine(image, rotationMatrix, dimen)
# rotate = rotation(img, -160) #angle will be in degrees
# cv.imshow("ROtation", rotate)
# again_rotate = rotation(img, 120)
# cv.imshow("Again-Rotated", again_rotate)
# #---> Resizing
# resize = cv.resize(img, (400, 425), interpolation=cv.INTER_AREA)
# cv.imshow("Resized Park", resize)
# #---> Flipping
# ##flip codes:
# # 0 = flipping the image vertically that is over the X axis
# # 1 = flipping the image horizontally or over the Y axis
# # -1 = flipping the image both vertically as well as horizontally
# flipping0 = cv.flip(img, 0)
# flipping1 = cv.flip(img, 1)
# flippingMinus1 = cv.flip(img, -1)
# cv.imshow('Flipping 0', flipping0)
# cv.imshow('Flipping 1', flipping1)
# cv.imshow('Flipping -1', flippingMinus1)
#---> Cropping
cropping = img[200:400, 300:400]
cv.imshow('Cropped', cropping)
cv.waitKey(0)