先上代码:
import cv2,os
import numpy as np
imgpath='C:/Users/10234/Desktop/007.jpg'
s_img = cv2.imread(imgpath)
print(s_img.shape)
img_big=np.zeros((512,512,3), np.uint8)
#img_big.fill(0) 填充黑色0,白色255
#rbg=(84,101,97)
rows,cols,channels = s_img.shape
#opencv 对应的是bgr
img_big[:, :, 0] = 97
img_big[:, :, 1] = 101
img_big[:, :, 2] = 84
x_offset=50
y_offset=60
img_big[y_offset:y_offset+s_img.shape[0], x_offset:x_offset+s_img.shape[1]] = s_img
cv2.imwrite('C:/Users/10234/Desktop/008.jpg', img_big)
效果图: