Python tutorial creating voice assistant using python

April 06, 2022

In this article i will explain you how you can detect face in webcam

Step 1: Install necessary python library which gonna help in reading images

  • OpenCv: This is open source image recogntion library in python
pip3 install opencv-python

Step 2: Once the needed library installed copy paste the following code

# watermarking image using OpenCV

# importing cv2
import cv2

def waterMarkImage(originalimg, watermarkimg):

    # loading images
    # importing logo that we are going to use
    logo = cv2.imread(watermarkimg)

    # importing image on which we are going to
    # apply watermark
    img = cv2.imread(originalimg)

    # calculating dimensions
    # height and width of the logo
    h_logo, w_logo, _ = logo.shape

    # height and width of the image
    h_img, w_img, _ = img.shape

    # calculating coordinates of center
    # calculating center, where we are going to
    # place our watermark
    center_y = int(h_img/2)
    center_x = int(w_img/2)

    # calculating from top, bottom, right and left
    top_y = center_y - int(h_logo/2)
    left_x = center_x - int(w_logo/2)
    bottom_y = top_y + h_logo
    right_x = left_x + w_logo

    # adding watermark to the image
    destination = img[top_y:bottom_y, left_x:right_x]
    result = cv2.addWeighted(destination, 1, logo, 0.5, 0)

    # displaying and saving image
    img[top_y:bottom_y, left_x:right_x] = result
    cv2.imwrite("watermarked.jpg", img)
    cv2.imshow("Watermarked Image", img)

if __name__ == '__main__':

    waterMarkImage("man.jpg", "bs.png")