Ai
1 Star 0 Fork 1

Leo/Learning-OpenCV-4-Computer-Vision-with-Python-Third-Edition

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
grabcut.py 717 Bytes
一键复制 编辑 原始数据 按行查看 历史
Joe Howse 提交于 2019-12-09 00:43 +08:00 . Renaming chapter folders
import numpy as np
import cv2
from matplotlib import pyplot as plt
original = cv2.imread('../images/statue_small.jpg')
img = original.copy()
mask = np.zeros(img.shape[:2], np.uint8)
bgdModel = np.zeros((1, 65), np.float64)
fgdModel = np.zeros((1, 65), np.float64)
rect = (100, 1, 421, 378)
cv2.grabCut(img, mask, rect, bgdModel, fgdModel, 5, cv2.GC_INIT_WITH_RECT)
mask2 = np.where((mask==2) | (mask==0), 0, 1).astype('uint8')
img = img*mask2[:,:,np.newaxis]
plt.subplot(121)
plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
plt.title("grabcut")
plt.xticks([])
plt.yticks([])
plt.subplot(122)
plt.imshow(cv2.cvtColor(original, cv2.COLOR_BGR2RGB))
plt.title("original")
plt.xticks([])
plt.yticks([])
plt.show()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/akwkevin/Learning-OpenCV-4-Computer-Vision-with-Python-Third-Edition.git
git@gitee.com:akwkevin/Learning-OpenCV-4-Computer-Vision-with-Python-Third-Edition.git
akwkevin
Learning-OpenCV-4-Computer-Vision-with-Python-Third-Edition
Learning-OpenCV-4-Computer-Vision-with-Python-Third-Edition
master

搜索帮助