Created
October 26, 2015 20:56
-
-
Save panmari/bb1831cb62721a47165c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Using opencv for borderless cloning. | |
import cv2 | |
import numpy as np | |
# Read images : src image will be cloned into dst | |
im_filename = "wolf.jpg" | |
im = cv2.imread(im_filename) | |
obj= cv2.flip(cv2.imread("hamster.jpg"), 1) | |
mask = cv2.flip(cv2.imread("hamster_mask.png"), 1) | |
mask = cv2.cvtColor(mask, cv2.COLOR_RGB2GRAY) | |
for resize_factor in np.arange(1.3, 1.8, 0.05): | |
obj_small = cv2.resize(obj, None, fx=resize_factor, fy=resize_factor) | |
# Create an all white mask | |
mask_small = cv2.resize(mask, None, fx=resize_factor, fy=resize_factor) | |
# The location of the center of the src in the dst | |
center = (700, 450) | |
# Seamlessly clone src into dst and put the results in output | |
normal_clone = cv2.seamlessClone(obj_small, im, mask_small, center, cv2.NORMAL_CLONE) | |
mixed_clone = cv2.seamlessClone(obj_small, im, mask_small, center, cv2.MIXED_CLONE) | |
# Write results | |
cv2.imwrite("{0}-normal-clone{1}.jpg".format(im_filename, resize_factor), normal_clone) | |
cv2.imwrite("{0}-mixed-clone{1}.jpg".format(im_filename, resize_factor), mixed_clone) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment