How to add a text in the captured image

Question:

I have created a app which capture the image and convert into pencil sketch.

I need to add a watermark inside the capture image I find for the documentation I didn’t get the exact one let me know how to add a water mark inside the image or any idea would be appreciated.

import base64
import streamlit as st 
import numpy as np
from PIL import Image  
import cv2 

def dodgeV2(x, y):
    return cv2.divide(x, 255 - y, scale=256)

def pencilsketch(inp_img):
img_gray = cv2.cvtColor(inp_img, cv2.COLOR_BGR2GRAY)
img_invert = cv2.bitwise_not(img_gray)
img_smoothing = cv2.GaussianBlur(img_invert, (21, 21),sigmaX=0, sigmaY=0)
final_img = dodgeV2(img_gray, img_smoothing)
logo_img = cv2.imread("Watertext.jpg")
logo_gray = cv2.cvtColor(logo_img, cv2.COLOR_BGR2GRAY)
logo_height, logo_width = logo_gray.shape[:2]
#y_offset = x_offset = 0 # paste to the top left of image
x_offset = final_img.shape[1] - logo_width
y_offset = 0
final_img[x_offset:x_offset+logo_height, y_offset:y_offset+logo_width] = logo_gray
return(final_img)

Water Mark

Asked By: Fariya

||

Answers:

using OpenCV you can add a watermark on your photos and video also, you need to import the library and use it.

**import cv2
img = cv2.imread('diego-jimenez-A-NVHPka9Rk-unsplash.JPG')
watermark = cv2.imread("Watermark.JPG")**

for more references go to this blog post

Answered By: Devang Amrutiya

Make use of cv2.addWeighted() which is used to blend images.
This is an example:

output_img = cv2.addWeighted(input_img, 1, watermark, 0.5, 0)
Answered By: Akshata Relekar

Modify your pencilsketch function like

def pencilsketch(inp_img):
    img_gray = cv2.cvtColor(inp_img, cv2.COLOR_BGR2GRAY)
    img_invert = cv2.bitwise_not(img_gray)
    img_smoothing = cv2.GaussianBlur(img_invert, (21, 21),sigmaX=0, sigmaY=0)
    final_img = dodgeV2(img_gray, img_smoothing)
    logo_img = cv2.imread("path/to/logo/image.jpg")
    logo_gray = cv2.cvtColor(logo_img, cv2.COLOR_BGR2GRAY)
    logo_height, logo_width = logo_gray.shape[:2]
    x_offset = y_offset = 0 # paste to the top left of image
    final_img[y_offset:y_offset+logo_height, x_offset:x_offset+logo_width] = logo_gray
    return(final_img)

If you want to paste in top right, change line

    x_offset = y_offset = 0 # paste to the top left of image

to

    x_offset = final_img.shape[1] - logo_width
    y_offset = 0

If you want to paste in bottom right, change line

    x_offset = y_offset = 0 # paste to the top left of image

to

    x_offset = final_img.shape[1] - logo_width
    y_offset = final_img.shape[0] - logo_height
Answered By: AnhPC03
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.