import cv2 as cv
import sys
if __name__ == '__main__':
img = cv.imread('tu.jpg')
part = img[300:400,250:350]
mask = cv.resize(part, (300, 300), fx=0, fy=0, interpolation=cv.INTER_LINEAR)
if img is None is None:
print('Failed to read picture')
sys.exit()
img[110:410,570:870]=mask
cv.rectangle(img,(250,300),(350,400),(0,255,0),1)
cv.rectangle(img,(570,110),(870,410),(0,255,0),1)
img = cv.line(img,(350,300),(570,110),(0,255,0))
img = cv.line(img,(350,400),(570,410),(0,255,0))
cv.imshow('img',img)
cv.waitKey(0)
cv.destroyAllWindows()
原图:
结果: