Advertisement
wyx0311

电宇智控视觉组2_1

May 31st, 2024
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.69 KB | Source Code | 0 0
  1. #使用 opencv 库读取 1.png
  2. import cv2
  3.  
  4. sunset=cv2.imread("sunset.jpeg")
  5.  
  6. #x 轴、y 轴同时翻转后保存为 1_1.png
  7. xy=cv2.flip(sunset,-1)
  8. cv2.imwrite('1_1.png', xy)
  9.  
  10. #对其右下角一个形状为(400,400,3)的区域绕 x 轴,y 轴同时反转
  11. height, width = sunset.shape[:2]
  12. start_x = width - 400
  13. start_y = height - 400
  14. end_x = width
  15. end_y = height
  16. if start_x < 0 or start_y < 0:
  17.     print("Error: Image size is smaller than 400x400")
  18.     exit()
  19.    
  20. region = sunset[start_y:end_y, start_x:end_x]
  21. flipped_region = cv2.flip(region, -1)
  22. cv2.imshow('Flipped Region', flipped_region)
  23. cv2.waitKey(0)
  24. cv2.imwrite('1_2.png', flipped_region)
  25. cv2.destroyAllWindows()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement