Python 官方文档:入门教程 => 点击学习
import numpy as np import cv2 from matplotlib import pyplot as plt img = cv2.imread('b.jpg') mask = np.zeros(img.sh
import numpy as np
import cv2
from matplotlib import pyplot as plt
img = cv2.imread('b.jpg')
mask = np.zeros(img.shape[:2], np.uint8)
bgdModel = np.zeros((1, 65), np.float64)
fgdModel = np.zeros((1, 65), np.float64)
rect = (20, 20, 413, 591)
cv2.grabCut(img, mask, rect, bgdModel, fgdModel, 10, cv2.GC_INIT_WITH_RECT)
mask2 = np.where((mask == 2) | (mask == 0), 0, 1).astype('uint8')
img = img * mask2[:, :, np.newaxis]
img += 255 * (1 - cv2.cvtColor(mask2, cv2.COLOR_GRAY2BGR))
# plt.imshow(img)
# plt.show()
img = np.array(img)
mean = np.mean(img)
img = img - mean
img = img * 0.9 + mean * 0.9
img /= 255
plt.imshow(img)
plt.show()
--结束END--
本文标题: python实现抠图
本文链接: https://lsjlt.com/news/184920.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0