1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
import cv2 import numpy as np
dog = cv2.imread('./dog.jpeg')
logo = np.zeros((200, 200, 3), np.uint8) mask = np.zeros((200, 200), np.uint8)
logo[20:120, 20:120] = [0, 0, 255] logo[80:180, 80:180] = [0, 255, 0]
mask[20:120, 20:120] = 255 mask[80:180, 80:180] = 255
m = cv2.bitwise_not(mask)
roi = dog[0:200, 0:200]
tmp = cv2.bitwise_and(roi, roi, mask = m)
dst = cv2.add(tmp, logo)
dog[0:200,0:200] = dst
cv2.imshow('dog', dog) cv2.imshow('dst', dst) cv2.imshow('tmp', tmp) cv2.imshow('m', m) cv2.imshow('mask', mask) cv2.imshow('logo', logo) cv2.waitKey(0)
|