grabcut代码(python代码)

import numpy as np
import cv2
from matplotlib import pyplot as plt

img=cv2.imread(‘C:\Users\86198\Desktop\1.jpeg’)
mask=np.zeros(img.shape[:2],np.uint8)

bgdModel=np.zeros((1,65),np.float64)
fgdModel=np.zeros((1,65),np.float64)

roi=cv2.selectROI(windowName=“roi”,img=img,showCrosshair=True,fromCenter=False)

rect=roi
cv2.grabCut(img,mask,rect,bgdModel,fgdModel,5,cv2.GC_INIT_WITH_RECT)

mask2=np.where((mask2)|(mask0),0,1).astype(‘uint8’)
img=img*mask2[:,:,np.newaxis]

plt.imshow(img),plt.colorbar(),plt.show()

grabcut代码

结果:
grabcut代码

相关文章:

  • 2021-11-14
  • 2021-08-11
  • 2021-11-27
  • 2022-12-23
  • 2022-12-23
  • 2021-06-15
  • 2022-01-19
猜你喜欢
  • 2021-07-29
  • 2021-10-19
  • 2021-04-29
  • 2022-12-23
  • 2021-04-11
  • 2019-03-20
  • 2021-11-07
相关资源
相似解决方案