https://blog.csdn.net/fanzonghao/article/details/82946058
RCNN模型中使用了SS(Selective Search)进行区域推荐,SS作为一种区域推荐算法作为检测框,它是一种基于图像层次纹理、大小、形状进行分割与合并的算法 。
SS算法进行区域推荐ROI生成会执行如下步骤
对每个分割区域计算外接矩形框,作为区域推荐窗口
对每组相邻的分割区域根据相似性进行合并
不断重复1~2
下面利用前10个roi作为演示。
cv2.setUseOptimized(True)
cv2.setNumThreads(4)
# read image
im = cv2.imread("./data/1.png")
print(im.shape)
# resize image
newHeight = 200
newWidth = int(im.shape[1] * 200 / im.shape[0])
im = cv2.resize(im, (newWidth, newHeight))
cv2.imshow("input", im)
# 创建算法+设置输入图像
ss = cv2.ximgproc.segmentation.createSelectiveSearchSegmentation()
ss.setBaseImage(im)
# 使用SS快速版本
ss.switchToSelectiveSearchFast()
# 执行SS
rects = ss.process()
print('Total Number of Region Proposals: {}'.format(len(rects)))
# 推荐100个ROI
numShowRects = 10
imOut = im.copy()
# 显示前100个区域外接矩形框
for i, rect in enumerate(rects):
if i < numShowRects:
x, y, w, h = rect
cv2.rectangle(imOut, (x, y), (x + w, y + h), (0, 255, 0), 1, cv2.LINE_AA)
else:
break
# show output
cv2.imshow("SS", imOut)
cv2.waitKey(0)
cv2.destroyAllWindows()