-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflipping-1.4.4.py
67 lines (55 loc) · 1.7 KB
/
flipping-1.4.4.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
# import the necessary packages
import argparse
import cv2
# construct the argument parser and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True, help="Path to the image")
args = vars(ap.parse_args())
# # load the image and show it
# image = cv2.imread(args["image"])
# cv2.imshow("Original", image)
#
# # flip the image horizontally
# flipped = cv2.flip(image, 1)
# cv2.imshow("Flipped Horizontally", flipped)
#
# X=235
# Y=259
# (b, g, r) = flipped[X,Y]
# print("Pixel at ({X},{Y}) - Red: {r}, Green: {g}, Blue: {b}".format(X=X,Y=Y,r=r, g=g, b=b))
#
#
# # flip the image vertically
# flipped = cv2.flip(image, 0)
# cv2.imshow("Flipped Vertically", flipped)
#
# # flip the image along both axes
# flipped = cv2.flip(image, -1)
# cv2.imshow("Flipped Horizontally & Vertically", flipped)
# cv2.waitKey(0)
###### Quiz
q2Image = cv2.imread(args["image"])
# flip horzintally
flipped1 = cv2.flip(q2Image, 1)
cv2.imshow("Flipped Horizontally", flipped1)
cv2.waitKey()
#rotate 45
# where is cnetre
(h, w) = flipped1.shape[:2]
print("Shape height={} width={}".format(h, w))
(centreX, centreY) = (w//2, h//2)
print("Centre = ({0},{1})".format(centreX, centreY))
# rotate our image by 45 degrees
M = cv2.getRotationMatrix2D((centreX, centreY), 45, 1.0)
quizRotated = cv2.warpAffine(flipped1, M, (w, h))
cv2.imshow("Flipped Horizontally rotated 45 degrees", quizRotated)
cv2.waitKey()
#flip vert
flipped3 = cv2.flip(quizRotated, 0)
cv2.imshow("Flipped Horizontally rotated 45 degrees then flipped vertically", flipped3)
cv2.waitKey()
X=189
Y=441
(b, g, r) = flipped3[X,Y]
print("Pixel at ({X},{Y}) - Red: {r}, Green: {g}, Blue: {b}".format(X=X,Y=Y,r=r, g=g, b=b))
cv2.destroyAllWindows()