Advertisement
Guest User

Untitled

a guest
Nov 21st, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. def rotateImage(self):
  2. ForwardMap = np.zeros((self.width,self.height),dtype="uint8")
  3. BackwardMap = np.zeros((self.width,self.height),dtype="uint8")
  4.  
  5. for i in range(self.width):
  6. for j in range(self.height):
  7. # forward mapping
  8. for_x = (i - self.x) * math.cos(self.angle*(math.pi/180)) - (j - self.y) * math.sin(self.angle*(math.pi/180)) + self.x
  9. for_y = (i - self.x) * math.sin(self.angle*(math.pi/180)) + (j - self.y) * math.cos(self.angle*(math.pi/180)) + self.x
  10. for_x = int(for_x)
  11. for_y = int(for_y)
  12. # backward mapping
  13. back_x = (i - self.x) * math.cos(self.angle*(math.pi/180)) + (j - self.y) * math.sin(self.angle*(math.pi/180)) + self.x
  14. back_y = -(i - self.x) * math.sin(self.angle*(math.pi/180)) + (j - self.y) * math.cos(self.angle*(math.pi/180)) + self.x
  15. back_x = int(back_x)
  16. back_y = int(back_y)
  17. if for_x in range(self.width) and for_y in range(self.height):
  18. ForwardMap[i, j] = self.img[for_x, for_y]
  19. else:
  20. pass
  21. if back_x in range(self.width) and back_y in range(self.height):
  22. BackwardMap[i, j] = self.img[back_x, back_y]
  23. else:
  24. pass
  25. cv2.imshow('Forward Mapping', ForwardMap)
  26. cv2.imshow('Backward Mapping', BackwardMap)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement