如何可视化选择性搜索的分割图像?

2024-10-03 00:31:15 发布

您现在位置:Python中文网/ 问答频道 /正文

如何可视化应用于图像的选择性搜索算法的分割图像输出

import cv2

image = cv2.imread("x.jpg")

ss = cv2.ximgproc.segmentation.createSelectiveSearchSegmentation()
ss.setBaseImage(image)

ss.switchToSelectiveSearchQuality()
rects = ss.process()

也就是说,要使图像位于右侧

enter image description here


Tags: 图像imageimport可视化cv2ssjpg搜索算法
2条回答

我认为你可以使用以下方法。我试过了,它起作用了

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的块

原始图像:

enter image description here

处理后: enter image description here

我不确定,但我认为你需要的图像可能无法获得。 理由是: Open this file first containing the source code

在第726-734行中,变量“images”是私有的,在第828行的方法switchToSelectiveSearchQuality()中,用于计算的不同图像存储在私有变量“images”中(遵循addImage函数查看)

此外,在第901行,存储在“images”变量中的图像被调用用于处理分割。这里调用的方法是“GraphSegmentation”类的processImage(),我无法向后跟踪

因此,您需要的映像可能根本不存储在任何地方,或者存储在我们无法访问的私有变量中

编辑:在第46行和第52行的this file中找到了“GraphSegmentation”类和方法“processImage”声明

相关问题 更多 >