devops:python:opencv
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| devops:python:opencv [2024/10/10 06:45] – srohr_admin | devops:python:opencv [2024/10/10 06:47] (current) – srohr_admin | ||
|---|---|---|---|
| Line 54: | Line 54: | ||
| cv2.imshow(" | cv2.imshow(" | ||
| cv2.waitKey(0) | cv2.waitKey(0) | ||
| - | cv2.destroyAllWindows() | + | 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.1728539148.txt.gz · Last modified: 2024/10/10 06:45 by srohr_admin
