Python 将图像复制到特定位置的另一个图像
我试图将图像的某个区域复制到同一图像的另一个位置。我试着用StackOverflow上的代码。我将给出我尝试过的代码片段:Python 将图像复制到特定位置的另一个图像,python,image-processing,opencv3.0,Python,Image Processing,Opencv3.0,我试图将图像的某个区域复制到同一图像的另一个位置。我试着用StackOverflow上的代码。我将给出我尝试过的代码片段: roi = frame[ry1:ry2, rx1:rx2] roi.shape frame = frame.copy() frame[:roi.shape[0], :roi.shape[1]] = roi 您可以使用此示例: import cv2 def roi(frame, x1, y1, w, h, x2, y2): # x1
roi = frame[ry1:ry2, rx1:rx2]
roi.shape
frame = frame.copy()
frame[:roi.shape[0], :roi.shape[1]] = roi
您可以使用此示例:
import cv2
def roi(frame, x1, y1, w, h, x2, y2):
# x1, y1: from
# w, h: size
# x2, y2: to
roi = frame[y1:y1+h, x1:x1+w]
frame = frame.copy()
frame[y2:y2+h, x2:x2+w] = roi
return frame
image = cv2.imread('test.png')
image = roi(image, 100, 120, 90, 150, 320, 310)
cv2.imshow("Image", image)
cv2.waitKey(0)
cv2.destroyAllWindows()
你可以使用掩蔽