91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

資源簡介

程序用python編寫,使用GUI庫wxpython 需要預先安好各種庫,運行速度取決于cpu。。。(逃

資源截圖

代碼片段和文件信息

import?numpy?as?np
import?cv2
from?matplotlib?import?pyplot?as?plt
from?grabcut?import?GrabCut

def?minx(x1x2y1y2):
if?x1 return?x1y1
else:
return?x2y2

def?checkout(xp):
if?x>p:
return?p
if?x<0:
return?0
return?x

def?algo_grabcut(filenameforeground=[]background=[]pos1x=1pos1y=1pos2x=511pos2y=511times=5?algo=True):
img?=?cv2.imread(filename)
mask?=?np.zeros(img.shape[:2]np.uint8)
height?=?img.shape[:2][0]
width?=?img.shape[:2][1]
pos1x?=?checkout(pos1xwidth-1)
pos1y?=?checkout(pos1yheight-1)
pos2x?=?checkout(pos2xwidth-1)
pos2y?=?checkout(pos2yheight-1)
mask[min(pos1ypos2y):max(pos1ypos2y)+1min(pos1xpos2x):max(pos1xpos2x)+1]=3
for?y1x1y2x2?in?foreground:
x1?=?checkout(x1height-1)
y1?=?checkout(y1width-1)
x2?=?checkout(x2height-1)
y2?=?checkout(y2width-1)
if?x1==x2:
mask[x1min(y1y2):max(y1y2)+1]?=?1
else:
k?=?(y1-y2)/(x1-x2)
xy?=?minx(x1x2y1y2)
while?True:
mask[xy]?=?1
x?=?x+1
y?=?checkout(int(round(y+k))width-1)
if?x>max(x1x2):
break
for?y1x1y2x2?in?background:
x1?=?checkout(x1height-1)
y1?=?checkout(y1width-1)
x2?=?checkout(x2height-1)
y2?=?checkout(y2width-1)
if?x1==x2:
mask[x1min(y1y2):max(y1y2)+1]?=?0
else:
k?=?(y1-y2)/(x1-x2)
xy?=?minx(x1x2y1y2)
while?True:
mask[xy]?=?0
x?=?x+1
y?=?checkout(int(round(y+k))height-1)
if?x>max(x1x2):
break
if?algo:
rect=(0000)
bgdModel?=?np.zeros((165)np.float64)
fgdModel?=?np.zeros((165)np.float64)
cv2.grabCut(imgmaskrectbgdModelfgdModeltimescv2.GC_INIT_WITH_MASK)
mask2?=?np.where((mask==2)|(mask==0)01).astype(‘uint8‘)
im?=?img*mask2[::np.newaxis]
im?+=?255*(1-cv2.cvtColor(mask2?cv2.COLOR_GRAY2BGR))
cv2.imwrite(‘out.png‘im)
else:
mask1?=?np.zeros(img.shape[:2]np.uint8)
mask1[mask==1]?=?3
mask1[mask==2]?=?1
mask1[mask==3]?=?2
GrabCut(filename?mask1?1)
return?True

評論

共有 條評論