Now the class can perform the resize, crop and rotate operations. In the source codes of ResizeCropRotate.py the class is imported in Line 2, this is a typical way to include another Python file for reference.
1 import cv2
2 import common.ImageProcessing as ip
3
4 if __name__ == "__main__":
5 # Create an ImageProcessing object
6 ip = ip.ImageProcessing("Resize,Crop and Rotate", "../res/flower005.jpg")
7
8 # Show original image
9 ip.show()
10
11 # Resize the original image and show it
12 resized_image = ip.resize(50)
13 ip.show("Resized -- 50%", resized_image)
14
15 # Rotate the resized image and show it
16 rotated_image = ip.rotate(45, resized_image)
17 ip.show("Rotated -- 45 degree", rotated_image)
18
19 # Crop the original image and show it
20 cropped_image = ip.crop((300, 10), (600, 310))
21 ip.show("Cropped", cropped_image)
22
23 cv2.waitKey(0)
24 cv2.destroyAllWindows()
Below are the results, First Figure shows the original image and the second shows the 50% resized image:
Figures below shows the cropped image and the 45-degree rotated image:
Feel free to play with the source codes, for example change an image file, change the degree of rotation, change the percentage of the resizing, and observe how the image is processed.
0 comments:
Post a Comment