選擇性搜尋(selective search)

2021-08-11 22:49:13 字數 3547 閱讀 7352

該文翻譯整理自:selective search for object detection(c++ / python)

一、目標檢測 vs 目標識別

目標識別(objec recognition)是指明一幅輸入影象中包含那類目標。其輸入為一幅影象,輸出是該影象中的目標屬於哪個類別(class probability)。而目標檢測(object detection)除了要告訴輸入影象中包含了哪類目前外,還要框出該目標的具體位置(bounding boxes)。

二、selective search演算法流程

step0:生成區域集r,具體參見**《efficient graph-based image segmentation》

step1:計算區域集r裡每個相鄰區域的相似度s=

step2:找出相似度最高的兩個區域,將其合併為新集,新增進r

step3:從s中移除所有與step2中有關的子集

step4:計算新集與所有子集的相似度

step5:跳至step2,直至s為空

三、相似度計算

**考慮了顏色、紋理、尺寸和空間交疊這4個引數。

3.1、顏色相似度(color similarity)

將色彩空間轉為hsv,每個通道下以bins=25計算直方圖,這樣每個區域的顏色直方圖有25*3=75個區間。 對直方圖除以區域尺寸做歸一化後使用下式計算相似度:

3.2、紋理相似度(texture similarity)

**採用方差為1的高斯分布在8個方向做梯度統計,然後將統計結果(尺寸與區域大小一致)以bins=10計算直方圖。直方圖區間數為8*3*10=240(使用rgb色彩空間)。

其中,3.3、尺寸相似度(size similarity)

保證合併操作的尺度較為均勻,避免乙個大區域陸續「吃掉」其他小區域。

例:設有區域a-b-c-d-e-f-g-h。較好的合併方式是:ab-cd-ef-gh -> abcd-efgh -> abcdefgh。 不好的合併方法是:ab-c-d-e-f-g-h ->abcd-e-f-g-h ->abcdef-gh -> abcdefgh。

3.4、交疊相似度(shape compatibility measure)

3.5、最終的相似度

四、opencv 3.3 實現了selective search

在opencv的contrib模組中實現了selective search演算法。類定義為:

cv::ximgproc::segmentation::selectivesearchsegmentation
舉例:

#include "opencv2/ximgproc/segmentation.hpp"

#include "opencv2/highgui.hpp"

#include "opencv2/core.hpp"

#include "opencv2/imgproc.hpp"

#include #include using namespace cv;

using namespace cv::ximgproc::segmentation;

static void help()

int main(int argc, char** argv)

// speed-up using multithreads

// void cv::setuseoptimized(bool onoff), enables or disables the optimized code.

setuseoptimized(true);

setnumthreads(4);

// read image

mat im = imread(argv[1]);

// resize image

int newheight = 200;

int newwidth = im.cols*newheight/im.rows;

resize(im, im, size(newwidth, newheight));

// create selective search segmentation object using default parameters

ptrss = createselectivesearchsegmentation();

// set input image on which we will run segmentation

ss->setbaseimage(im);

// switch to fast but low recall selective search method

if (argv[2][0] == 'f')

// switch to high recall but slow selective search method

else if (argv[2][0] == 'q')

// if argument is neither f nor q print help message

else

// run selective search segmentation on input image

std::vectorrects;

ss->process(rects);

std::cout << "total number of region proposals: " << rects.size() << std::endl;

// number of region proposals to show

int numshowrects = 100;

// increment to increase/decrease total number of reason proposals to be shown

int increment = 50;

while(1)

else

}// show output

imshow("output", imout);

// record key press

int k = waitkey();

// m is pressed

if (k == 109)

// l is pressed

else if (k == 108 && numshowrects > increment)

// q is pressed

else if (k == 113)

}return 0;

}

Selective Search 選擇性搜尋

今天看r cnn的 演算法的第一步是提取2000個region proposal,然後根據提取的目標影象進行crop warp處理後,再用alexnet vgg 提取特徵,得到固定維度的輸出 4096 經過svm分類識別,再用bounding box regressing精確候選框位置。而生成候選區...

mysql選擇性 Mysql索引的選擇性

對於索引的使用,mysql並不一直都是用採用正確的決定的。參考乙個簡單的表 create table r2 id int 11 default null,id1 int 11 default null,cname varchar 32 default null,key id1 id1 engine ...

索引 選擇性

索引的選擇性是指索引列中不同值的數目與表中記錄數的比。如果乙個表中有2000條記 錄,表索引列有1980個不同的值,那麼這個索引的選擇性就是1980 2000 0.99。乙個索引的選擇性越接近於1,這個索引的效率就越高。如果是使用基於cost的最優化,優化器不應該使用選擇性不好的索引。如果是使用基於...