gpt4 book ai didi

python - 不能在不改变颜色的情况下覆盖面膜?

转载 作者:行者123 更新时间:2023-12-02 17:56:26 25 4
gpt4 key购买 nike

从下面的图像中,我使用以下代码在蒙版下面创建了:

 hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
mask = cv2.inRange(hsv, lower_color, upper_color)
res = cv2.bitwise_and(img,img, mask= mask)
图片:

面具:

我想覆盖看起来像这样的资源:

我使用下面的代码来覆盖它。
bgra = cv2.addWeighted(bgra, 1, res, 1, 0)
循环改变原始图像的颜色
for i in tqdm((range(rang)), ascii=True, desc = 'Loops'):
hmod += speed
alpha = img[:, :, 3]

bgr = img[:, :, 0:3]

hsv = cv2.cvtColor(bgr, cv2.COLOR_BGR2HSV)

h, s, v = cv2.split(hsv)

hnew = np.mod(h + hmod, 180).astype(np.uint8)

hsv_new = cv2.merge([hnew, s, v])

bgr_new = cv2.cvtColor(hsv_new, cv2.COLOR_HSV2BGR)

bgra = cv2.cvtColor(bgr_new, cv2.COLOR_BGR2BGRA)
bgra[:, :, 3] = alpha
if maskPresent[-1]:
bgra = cv2.addWeighted(bgra, 1, res, 1, 0)
if i == 0:
chromas = bgra
else:
try:
chromas = cv2.vconcat([bgra, chromas])
except MemoryError:
raise MemoryError('Out of memory(Try using an image with a lesser resolution or use a higher speed)')
但这即使在res变量保持不变的情况下,也可以在连接图像时更改蒙版的颜色。有谁知道解决方法?

最佳答案

chromares = cv2.bitwise_and(bgra, bgra, mask= mask)
bgra -= chromares
bgra += originalres #what was res```

关于python - 不能在不改变颜色的情况下覆盖面膜?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64625295/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com