Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #使用 opencv 库读取 1.png
- import cv2
- sunset=cv2.imread("sunset.jpeg")
- #x 轴、y 轴同时翻转后保存为 1_1.png
- xy=cv2.flip(sunset,-1)
- cv2.imwrite('1_1.png', xy)
- #对其右下角一个形状为(400,400,3)的区域绕 x 轴,y 轴同时反转
- height, width = sunset.shape[:2]
- start_x = width - 400
- start_y = height - 400
- end_x = width
- end_y = height
- if start_x < 0 or start_y < 0:
- print("Error: Image size is smaller than 400x400")
- exit()
- region = sunset[start_y:end_y, start_x:end_x]
- flipped_region = cv2.flip(region, -1)
- cv2.imshow('Flipped Region', flipped_region)
- cv2.waitKey(0)
- cv2.imwrite('1_2.png', flipped_region)
- cv2.destroyAllWindows()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement