擅长:python、mysql、java
<p>这里canvas是白色区域,img是您的输入图像。你知道吗</p>
<pre><code>canvas = np.zeros((512,512,3))
canvas.fill(255)
img = cv2.imread("xx.png",cv2.IMREAD_COLOR)
canvas[canvas.shape[0]//2-img.shape[0]//2:canvas.shape[0]//2+img.shape[0]//2,
canvas.shape[1]//2-img.shape[1]//2:canvas.shape[1]//2+img.shape[1]//2] = img
</code></pre>
<p>这是一个简单的代码,假设源代码和画布都是正方形和RGB图像。你知道吗</p>
<p>标志cv2.IMREAD\u颜色很重要,因为画布是3个通道。
如果要使用灰度,请在画布中使用1个通道,如果要使用png(包括alpha通道),请相应地使用4个通道。你知道吗</p>