devops:python:opencv
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| devops:python:opencv [2024/10/10 06:32] – created srohr_admin | devops:python:opencv [2024/10/10 06:47] (current) – srohr_admin | ||
|---|---|---|---|
| Line 2: | Line 2: | ||
| < | < | ||
| # 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 = cv2.imread(" | ||
| - | | + | |
| - | # importing image on which we are going to | + | # importing image on which we are going to |
| # apply watermark | # apply watermark | ||
| img = cv2.imread(" | img = cv2.imread(" | ||
| + | </ | ||
| + | |||
| + | < | ||
| # 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 | ||
| + | </ | ||
| + | < | ||
| # 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/ | center_y = int(h_img/ | ||
| center_x = int(w_img/ | center_x = int(w_img/ | ||
| - | | + | |
| # calculating from top, bottom, right and left | # calculating from top, bottom, right and left | ||
| top_y = center_y - int(h_logo/ | top_y = center_y - int(h_logo/ | ||
| + | left_x = center_x - int(w_logo/ | ||
| 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> |
| + | < | ||
| # adding watermark to the image | # adding watermark to the image | ||
| destination = img[top_y: | destination = img[top_y: | ||
| - | result = cv2.addWeighted(destination, | + | result = cv2.addWeighted(destination, |
| + | </ | ||
| + | < | ||
| + | # displaying and saving image | ||
| + | img[top_y: | ||
| + | cv2.imwrite(" | ||
| + | cv2.imshow(" | ||
| + | cv2.waitKey(0) | ||
| + | cv2.destroyAllWindows() | ||
| + | </ | ||
| + | |||
| + | |||
| + | < | ||
| + | # watermarking image using OpenCV | ||
| + | |||
| + | # importing cv2 | ||
| + | import cv2 | ||
| + | |||
| + | # loading images | ||
| + | # importing logo that we are going to use | ||
| + | logo = cv2.imread(" | ||
| + | |||
| + | # importing image on which we are going to | ||
| + | # apply watermark | ||
| + | img = cv2.imread(" | ||
| + | |||
| + | # 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/ | ||
| + | center_x = int(w_img/ | ||
| + | |||
| + | # calculating from top, bottom, right and left | ||
| + | top_y = center_y - int(h_logo/ | ||
| + | left_x = center_x - int(w_logo/ | ||
| + | bottom_y = top_y + h_logo | ||
| + | right_x = left_x + w_logo | ||
| + | |||
| + | # adding watermark to the image | ||
| + | destination = img[top_y: | ||
| + | result = cv2.addWeighted(destination, | ||
| + | |||
| + | # displaying and saving image | ||
| + | img[top_y: | ||
| + | cv2.imwrite(" | ||
| + | cv2.imshow(" | ||
| + | cv2.waitKey(0) | ||
| + | cv2.destroyAllWindows() | ||
| </ | </ | ||
devops/python/opencv.1728538331.txt.gz · Last modified: 2024/10/10 06:32 by srohr_admin
