Last active
May 5, 2018 14:14
-
-
Save rabssm/464f00848171514083b07e758f3c5d3b to your computer and use it in GitHub Desktop.
Watermark an image using OpenCV 2 and python.
This file contains 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
import cv2 | |
# Read in the image | |
image_file = 'original.jpg' | |
image = cv2.imread(image_file) | |
overlay = image.copy() | |
output = image.copy() | |
height, width = image.shape[:2] | |
# Stamp the image lower right corner and write it | |
alpha = 0.3 | |
namestamp = "My Name" | |
cv2.putText(overlay, namestamp.format(alpha), (width-400, height-24), cv2.FONT_HERSHEY_PLAIN, 1.5, (255,255,255), thickness=2) | |
cv2.addWeighted(overlay, alpha, output, 1 - alpha, 0, output) | |
cv2.imwrite("stamped.jpg", output) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment