擅长:python、mysql、java
<p>我想你正在寻找的答案是<code>alpha blending</code>。
如果您有描述中给出的两个图像(大小相同)(我们称它们为<code>img</code>和<code>annotation</code>),您可以执行以下操作:</p>
<pre><code>alpha = 0.5
# How much you want img to be opaque, alpha = 1 leads to your result being img,
# alpha = 0 to result==annotation
# with alpha = 0.5, you will get a blending with each image have the same
# importance
result = cv2.addWeighted(img, alpha, annotation, 1-alpha, 0)
</code></pre>
<p>您可以找到有关函数<a href="https://note.nkmk.me/en/python-opencv-numpy-alpha-blend-mask/" rel="nofollow noreferrer">here</a>的一些解释</p>
<p>现在,如果您的图像大小不同,则需要在混合它们之前调整它们的大小(我会调整较小图像的大小,以获得与较大图像相同的大小),因此它应该如下所示:</p>
<pre><code>width = img.shape[1]
height = img.shape[0]
dim = (width, height)
annotation = cv2.resize(annotation, dim)
</code></pre>