我正在学习 OpenCV 并尝试将小图像粘贴到大图像上。但是,它显示了一个错误,因为两个图像应该具有相同的大小。我还尝试遵循提供的建议(如何使用 Pillow 将图像粘贴到更大的图像上?)和(如何使用 Python 中的 PIL 将图像合成到另一个图像上?)
import cv2 as cv
from scipy import ndimage
img1 = cv.imread('Please put your file name')
top_left_x = min([x1,x2,x3,x4])
top_left_y = min([y1,y2,y3,y4])
bot_right_x = max([x1,x2,x3,x4])
bot_right_y = max([y1,y2,y3,y4])
y_right =bot_right_y + 1
x_right =bot_right_x + 1
cropped = img[top_left_y: y_right, top_left_x: x_right]
rotate = ndimage.rotate(cropped, ang)
Run Code Online (Sandbox Code Playgroud)
最终输出图像应位于中心。