资源简介
程序用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
相关资源
- wxPython使用教程
- wxpython 教程
- wxPython3.0-win32-3.0.2.0-py2732位系统安装包
- wxPython2.8-win64-unicode-2.8.12.1-py27.exe
- wxPython-docs-4.0.3.tar.gz:wxPython官方文档
- wxPython3.0-win32-3.0.2.0-py27
- 图像分割python实现代码
- wxPython2.8-win64-unicode-2.8.12.1-py27
- numpy-1.18.1-cp38-cp38-win_amd64.zip
- wxpython in action中英文合集(两份)
- wxPython4.0 api && doc
- python3 + wxpython 实现RSA加密聊天室
- wxPython几本好书
- Python-CENet用于2D医学图像分割的上下文
- 练手项目1(wxpython连连看)
- python3+wxpython图书馆管理系统
- wxPython写的拼图小游戏
- 基于区域的图像分割python源代码
- python版本的GrabCut前景分割和分水岭分
- 多目标区域的图像分割算法
-
wxPython实现fr
ame界面的跳转 - Graph Cut图像分割算法——Python+Opencv实
- python实现类似QQ群聊
- wxpython使用matplotlib的简单教程
- 基于wxPython和PySerial实现的串口助手
- KMeans++算法实现图像分割
- python 数独游戏源码
- Python WxPython开源扫雷游戏PyMine新版1
- wxPython写的类似qq截图的小程序
- wxPython2.8-win32-unicode-2.8.12.1-py27 for py
评论
共有 条评论