User Tools

Site Tools


devops:python:opencv

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
devops:python:opencv [2024/10/10 06:45] srohr_admindevops:python:opencv [2024/10/10 06:47] (current) srohr_admin
Line 54: Line 54:
 cv2.imshow("Watermarked Image", img)  cv2.imshow("Watermarked Image", img) 
 cv2.waitKey(0)  cv2.waitKey(0) 
-cv2.destroyAllWindows() +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.1728539148.txt.gz · Last modified: 2024/10/10 06:45 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