English 中文(简体)
如何直观选择性搜索的分部分形象?
原标题:How to visualize the segmented image of Selective Search?

How can I visualize the segmented image output of the Selective Search algorithm applied on an image?

import cv2

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

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

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

That is, to get the image on the right

“在此处的影像描述”/</a

最佳回答

I am not sure but I think the image you require can possibly not be obtained. Reason being: Open this file first containing the source code

第726-734条 变数的“工资”是私人的,在828行的“ToSelectiveSearchality()”转换方法中,用于计算的不同图像被储存在私人变量“images”中(见下面的添加功能)。

此外,“images”变量中储存的图像需要处理第901行的分部分。 这里所说的方法是我无法追溯到的“分类”类过程。

因此,你所需要的图像不可能存放在任何地方,也不可能储存在无法进入的私人变量中。

EDIT: Found "GraphSegmentation" class and method "processImage" declaration in this file at lines 46 and 52.

问题回答

I think you can use the following. I tried it - it s working

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

Why 100? I chose a chunk size of 100.

Original Image:

enter image description here

After processing: enter image description here

You have a bit a confusion.

The image you are trying to create is generated by graph segmentation:

  gs = cv2.ximgproc.segmentation.createGraphSegmentation()

  # Set the sigma, k, and min_size parameters
  gs.setSigma(sigma)
  gs.setK(k)
  gs.setMinSize(min_size)

  # Process the image
  segments = gs.processImage(img)

  # Get the minimum and maximum values in the segments image
  # min, max,_, _ = cv2.minMaxLoc(segments)

  # # Get the number of segments
  # nb_segs = int(max + 1)

  # Create an output image
  output = np.zeros_like(img)
  for segment_id in np.unique(segments):
      output[segments == segment_id] = color_mapping(segment_id)

  # Save the output image
  cv2.imwrite(output_image, output)

  print("Image written to " + output_image)

graph segmentation works as described here: https://www.youtube.com/watch?v=2IVAznQwdS4&ab_channel=FirstPrinciplesofComputerVision

while selective search described here https://learnopencv.com/selective-search-for-object-detection-cpp-python/ is used for bounding box suggestion - i.e. it will produce many suggestion, so that some of the suggestion contains objects

NOTE:

  1. Selective search uses graph segmentation as it s first step
  2. Selective search is used as suggesting mechanizm for RCNN to avoid scanning the entire img, as explained here https://towardsdatascience.com/understanding-regions-with-cnn-features-r-cnn-ec69c15f8ea7
  3. The RCNN uses the suggestion to predict objects class, if there is no object in the suggestion, the suggestion is discarded, therefore Selective search require an extra step to discard bad suggestion in order to be usefull




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签