i have two images, i need to use numpy and opencv to overlay foreground on top of background using numpy masks.
import numpy as np
import cv2
import matplotlib.pyplot as plt
background = cv2.imread("background.jpg")
foreground = cv2.imread("foreground.png")
foreground = cv2.cvtColor(foreground ,cv2.COLOR_BGR2GRAY)
background = cv2.cvtColor(background ,cv2.COLOR_BGR2GRAY)
arr = []
for i in range(foreground.shape[1]): #parse forground pixels
temp_row = []
for j in range(foreground.shape[0]):
if((foreground [i][j] == 0)):#if pixel transperant draw background
temp_row.append(background[i][j])
else: # draw forground
temp_row.append(foreground[i][j])
arr.append(temp_row)
res_im = np.array(arr)
plt.figure()
plt.imshow(res_im, cmap='gray', vmin=0, vmax=255)
plt.show()
i used this solution but was told i needed to use masks.. help?


