User Tools

Site Tools


devops:python:opencv

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
devops:python:opencv [2024/10/10 06:32] – created srohr_admindevops:python:opencv [2024/10/10 06:47] (current) srohr_admin
Line 2: Line 2:
 <code> <code>
 # watermarking image using OpenCV  # watermarking image using OpenCV 
-  +
 # importing cv2  # importing cv2 
 import cv2  import cv2 
-  + 
 +# loading images 
 # importing logo that we are going to use  # importing logo that we are going to use 
 logo = cv2.imread("logo.jpg" logo = cv2.imread("logo.jpg"
-   + 
-# importing image on which we are going to  +# importing image on which we are going to 
 # apply watermark  # apply watermark 
 img = cv2.imread("dark.png" img = cv2.imread("dark.png"
 +</code>
  
 +
 +<code>
 # calculating dimensions  # calculating dimensions 
 # height and width of the logo  # height and width of the logo 
Line 19: Line 23:
 # height and width of the image  # height and width of the image 
 h_img, w_img, _ = img.shape  h_img, w_img, _ = img.shape 
 +</code>
  
  
 +<code>
 # calculating coordinates of center  # calculating coordinates of center 
-# calculating center, where we are going   +# calculating center, where we are going to  
-to place our watermark +# place our watermark 
 center_y = int(h_img/2)  center_y = int(h_img/2) 
 center_x = int(w_img/2)  center_x = int(w_img/2) 
-  +
 # calculating from top, bottom, right and left  # calculating from top, bottom, right and left 
 top_y = center_y - int(h_logo/2)  top_y = center_y - int(h_logo/2) 
 +left_x = center_x - int(w_logo/2) 
 bottom_y = top_y + h_logo  bottom_y = top_y + h_logo 
 right_x = left_x + w_logo  right_x = left_x + w_logo 
-left_x = center_x - int(w_logo/2) +</code>
  
  
 +<code>
 # adding watermark to the image  # adding watermark to the image 
 destination = img[top_y:bottom_y, left_x:right_x]  destination = img[top_y:bottom_y, left_x:right_x] 
-result = cv2.addWeighted(destination,1, logo, 0.5, 0) +result = cv2.addWeighted(destination, 1, logo, 0.5, 0)  
 +</code>
  
  
 +<code>
 +# displaying and saving image 
 +img[top_y:bottom_y, left_x:right_x] = result 
 +cv2.imwrite("watermarked.jpg", img) 
 +cv2.imshow("Watermarked Image", img) 
 +cv2.waitKey(0) 
 +cv2.destroyAllWindows()
 +</code>
 +
 +
 +<code>
 +# watermarking image using OpenCV 
 +
 +# importing cv2 
 +import cv2 
 +
 +# loading images 
 +# importing logo that we are going to use 
 +logo = cv2.imread("logo.jpg"
 +
 +# importing image on which we are going to 
 +# apply watermark 
 +img = cv2.imread("dark.png"
 +
 +# 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) 
 +cv2.waitKey(0) 
 +cv2.destroyAllWindows() 
 </code> </code>
devops/python/opencv.1728538331.txt.gz · Last modified: 2024/10/10 06:32 by srohr_admin

Except where otherwise noted, content on this wiki is licensed under the following license: CC0 1.0 Universal
CC0 1.0 Universal Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki