我已经使用skimage的slic将图像分割成超像素。现在,我想在超像素上使用抓取。我该怎么做?
from skimage.segmentation import slic
from skimage.util import img_as_float
from skimage import io
import matplotlib.pyplot as plt
import argparse
import cv2
import numpy as np
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required = True, help = "Path to the image")
args = vars(ap.parse_args())
image = img_as_float(io.imread(args["image"]))
for numSegments in (100, 500):
segments = slic(image, n_segments = numSegments, sigma = 5)
bgdModel = np.zeros((1,65),np.float64)
fgdModel = np.zeros((1,65),np.float64)
cv2.grabCut(segments, bgdModel, fgdModel, 5)
plt.imshow(segments)