SS(selective search) and Graph Based Image Segmentation

用处:避免滑动窗口暴力穷举列出所有区域

SS算法流程

其中分割算法执行结果:

分割算法执行结果:

SS执行结果:

import skimage.data
import selectivesearch
import cv2 as cv

'''
img : ndarray
            image with region label
            region label is stored in the 4th value of each pixel [r,g,b,(region)]
        regions : array of dict
            [
                {
                    'rect': (left, top, width, height),
                    'labels': [...],
                    'size': component_size
                },
                ...
            ]
'''
img = cv.imread('house.jpg')
img_lbl, regions = selectivesearch.selective_search(img, 500, 0.8, 10)

for region in regions:
    x, y, w, h = region['rect']
    rect = cv.rectangle(img, (x, y), (x+w, y+h), (0, 0, 255), 1)


cv.imshow("test", img)
print("number of Boxes %d" % len(regions))
cv.waitKey(0)


猜你喜欢

转载自blog.csdn.net/futangxiang4793/article/details/82631388