normal_versus_mixed_clone.py 860 B

12345678910111213141516171819202122232425262728
  1. #!/usr/bin/python
  2. '''
  3. OpenCV seamlessCloning : Normal vs Mixed
  4. Copyright 2015 by Satya Mallick <spmallick@gmail.com>
  5. '''
  6. import cv2
  7. import numpy as np
  8. # Read images : src image will be cloned into dst
  9. im = cv2.imread("images/wood-texture.jpg")
  10. obj= cv2.imread("images/iloveyouticket.jpg")
  11. # Create an all white mask
  12. mask = 255 * np.ones(obj.shape, obj.dtype)
  13. # The location of the center of the src in the dst
  14. width, height, channels = im.shape
  15. center = (int(height/2), int(width/2))
  16. # Seamlessly clone src into dst and put the results in output
  17. normal_clone = cv2.seamlessClone(obj, im, mask, center, cv2.NORMAL_CLONE)
  18. mixed_clone = cv2.seamlessClone(obj, im, mask, center, cv2.MIXED_CLONE)
  19. # Write results
  20. cv2.imwrite("images/opencv-normal-clone-example.jpg", normal_clone)
  21. cv2.imwrite("images/opencv-mixed-clone-example.jpg", mixed_clone)