How to Add Text Watermark on Images with OpenCV Python

This post will be helpful in learning OpenCV using Python programming. Here I will show how to implement OpenCV functions and apply them in various aspects using some great examples. Then the output will be visualized along with the comparisons.

We will also discuss the basic of image processing and provide the detail explanation related to the OpenCV functions.


First, you need to setup your Python Environment with OpenCV. You can easily do it by following Life2Coding’s tutorial on YouTube: Linking OpenCV with Python 3


The goal is to make you understand how to draw text watermark on images using Python OpenCV.



retval=cv.imread(filename[, flags])

Loads an image from a file.

filename Name of file to be loaded.
flags Flag that can take values of cv::ImreadModes


img=cv.putText(img, text, org, fontFace, fontScale, color[, thickness[, lineType[, bottomLeftOrigin]]])

Draws a text string.

img Image.
text Text string to be drawn.
org Bottom-left corner of the text string in the image.
fontFace Font type, see HersheyFonts.
fontScale Font scale factor that is multiplied by the font-specific base size.
color Text color.
thickness Thickness of the lines used to draw a text.
lineType Line type. See LineTypes
bottomLeftOrigin When true, the image data origin is at the bottom-left corner. Otherwise, it is at the top-left corner.


dst=cv.addWeighted(src1, alpha, src2, beta, gamma[, dst[, dtype]])

Calculates the weighted sum of two arrays.

src1 first input array.
alpha weight of the first array elements.
src2 second input array of the same size and channel number as src1.
beta weight of the second array elements.
gamma scalar added to each sum.
dst output array that has the same size and number of channels as the input arrays.
dtype optional depth of the output array; when both input arrays have the same depth, dtype can be set to -1, which will be equivalent to src1.depth().


None=cv.imshow(winname, mat)

Displays an image in the specified window.

winname Name of the window.
mat Image to be shown.


retval=cv.waitKey([, delay])

Waits for a pressed key.

delay Delay in milliseconds. 0 is the special value that means “forever”.


  • Load a face image using cv2.imread()
  • Load the image using cv2.imread()
  • Create the overlay copy of the image using copy()
  • Draw the watermark text using cv2.putText() on the overlay image
  • Then blend the images using cv2.addWeighted()
  • Display the image using cv2.imshow()
  • Wait for keyboard button press using cv2.waitKey()
  • Exit window and destroy all windows using cv2.destroyAllWindows()

Example Code:

# import the necessary packages
from __future__ import print_function
import numpy as np
import cv2

# load the image
image = cv2.imread("./hanif.jpg")

def addWaterMark(text,opacity,BGRColor):
    overlay = image.copy()
    output = image.copy()

    cv2.putText(overlay, text, (0,int(2*(image.shape[1])/3)), cv2.FONT_HERSHEY_SIMPLEX, 1.0, BGRColor, 2)
    # apply the overlay
    cv2.addWeighted(overlay, opacity, output, 1 - opacity,
                    0, output)
    # show the output image
    cv2.imshow("Output", output)

if __name__ == '__main__':
    #put the text , Opacity, BGR Color


5cd124a82d047 How to Add Text Watermark on Images with OpenCV Python
life2coding_icon [] How to Add Text Watermark on Images with OpenCV Python

One thought on “How to Add Text Watermark on Images with OpenCV Python

  1. ayse

    When i tried run the code, i have this error:
    overlay = image.copy()
    AttributeError: ‘NoneType’ object has no attribute ‘copy’ How can i fix this error?

    Thank you!

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.