我有两个图像.我想从一个图像中抓取一个区域(多边形,而不是矩形),然后将该区域复制到另一图像上.我该怎么做?这是我到目前为止所拥有的.
import cv2
import numpy as np
#load two images
srcfilename = 'foo.jpg'
src1 = cv2.imread(srcfilename)
srcfilename = 'bar.jpg'
src2 = cv2.imread(srcfilename)
src1_mask = np.zeros(src1.shape[:-1])
#create a polygon for region of interest
poly = np.array([ [150,150], [200,100], [350,150], [350,200], [300,220], [200,200], [190,180] ], np.int32)
cv2.fillPoly(src1_mask, [poly], 255)
此时,我已加载了两个图像,并且对该区域具有了多边形和蒙版.现在,我不知道如何使用此蒙版/多边形将src1的该部分复制到src2.
#I can also create a mask that has the same number of channels (3)
src1_mask = np.zeros(src1.shape)
#create a polygon for region of interest
poly = np.array([ [150,150], [200,100], [350,150], [350,200], [300,220], [200,200], [190,180] ], np.int32)