python - 如何可视化选择性搜索的分割图像?
问题描述
如何可视化应用于图像的选择性搜索算法的分割图像输出?
import cv2
image = cv2.imread("x.jpg")
ss = cv2.ximgproc.segmentation.createSelectiveSearchSegmentation()
ss.setBaseImage(image)
ss.switchToSelectiveSearchQuality()
rects = ss.process()
也就是得到右边的图像
解决方案
我认为您可以使用以下内容。我试过了 - 它工作正常
import cv2, random
image = cv2.imread("x.jpg")
ss = cv2.ximgproc.segmentation.createSelectiveSearchSegmentation()
ss.setBaseImage(image)
ss.switchToSelectiveSearchQuality()
rects = ss.process()
for i in range(0, len(rects), 100):
# clone the original image so we can draw on it
output = image.copy()
# loop over the current subset of region proposals
for (x, y, w, h) in rects[i:i + 100]:
# draw the region proposal bounding box on the image
color = [random.randint(0, 255) for j in range(0, 3)]
cv2.rectangle(output, (x, y), (x + w, y + h), color, 2)
cv2.imshow("Output", output)
key = cv2.waitKey(0) & 0xFF
# if the `q` key was pressed, break from the loop
if key == ord("q"):
break
为什么是100?我选择了 100 的块大小。
原图:
推荐阅读
- javascript - 如何将重叠矩形的轮廓转换为顶点?
- c++ - 将 SDL_Cursor 与 unique_ptr 一起使用:不允许错误不完整类型
- html - 通过“发布”发布包含图像文件相对路径的报告
- asp.net-core - 从 Angular 5 注销 MVC 应用程序
- java - 多模块java app项目结构
- mercurial - 仅查看来自特定分支的提交
- java - Java InputStreamReader 尝试读取整个流?
- php - 小错误,但我看不到在哪里 - Symfony 外键
- excel - 将多个表格从 Excel 插入 Word VBA
- php - 通过流访问大对象 (LONGBLOB)