# 0418.py : OpenCV-Python Tutorials 참조
import cv2
import numpy as np

src1 = cv2.imread('./data/lena.jpg')
src2 = cv2.imread('./data/opencv_logo.png')
cv2.imshow('src2', src2)

#1
rows, cols, channels = src2.shape
roi = src1[0:rows, 0:cols]

#2
gray = cv2.cvtColor(src2, cv2.COLOR_BGR2GRAY)
ret, mask = cv2.threshold(gray, 160, 255, cv2.THRESH_BINARY)
mask_inv = cv2.bitwise_not(mask)
cv2.imshow('mask', mask)
cv2.imshow('mask_inv', mask_inv)

#3
src1_bg = cv2.bitwise_and(roi, roi, mask = mask)
cv2.imshow('src1_bg', src1_bg)

#4
src2_bg = cv2.bitwise_and(src2, src2, mask = mask_inv)
cv2.imshow('src2_bg', src2_bg)

#5
##dst = cv2.add(src1_bg, src2_bg)
dst = cv2.bitwise_or(src1_bg, src2_bg)
cv2.imshow('dst', dst)

#6
src1[0:rows, 0:cols] = dst

cv2.imshow('result', src1)
cv2.waitKey()
cv2.destroyAllWindows()
# 0418.py : OpenCV-Python Tutorials 참조
import cv2
import numpy as np

src1 = cv2.imread('./data/lena.jpg')
src2 = cv2.imread('./data/opencv_logo.png')
cv2.imshow('src2', src2)

#1
rows, cols, channels = src2.shape
roi = src1[0:rows, 0:cols]

#2
gray = cv2.cvtColor(src2, cv2.COLOR_BGR2GRAY)
ret, mask = cv2.threshold(gray, 160, 255, cv2.THRESH_BINARY)
mask_inv = cv2.bitwise_not(mask)
cv2.imshow('mask', mask)
cv2.imshow('mask_inv', mask_inv)

#3
src1_bg = cv2.bitwise_and(roi, roi, mask = mask)
cv2.imshow('src1_bg', src1_bg)

#4
src2_bg = cv2.bitwise_and(src2, src2, mask = mask_inv)
cv2.imshow('src2_bg', src2_bg)

#5
##dst = cv2.add(src1_bg, src2_bg)
dst = cv2.bitwise_or(src1_bg, src2_bg)
cv2.imshow('dst', dst)

#6
src1[0:rows, 0:cols] = dst

cv2.imshow('result', src1)
cv2.waitKey()
cv2.destroyAllWindows()
# 0418.py : OpenCV-Python Tutorials 참조 #1 #2 #3 #4 #5 ##dst = cv2.add(src1_bg, src2_bg) #6