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


一、目标检测 VS 目标识别

目标识别(objec recognition)是指明一幅输入图像中包含那类目标。其输入为一幅图像,输出是该图像中的目标属于哪个类别(class probability)。而目标检测(object detection)除了要告诉输入图像中包含了哪类目前外,还要框出该目标的具体位置(bounding boxes)。

在目标检测时,为了定位到目标的具体位置,通常会把图像分成许多子块(sub-regions / patches),然后把子块作为输入,送到目标识别的模型中。分子块的最直接方法叫滑动窗口法(sliding window approach)。滑动窗口的方法就是按照子块的大小在整幅图像上穷举所有子图像块。这种方法产生的数据量想想都头大。和滑动窗口法相对的是另外一类基于区域(region proposal)的方法。selective search就是其中之一!

二、selective search算法流程

step0:生成区域集R,具体参见论文《Efficient Graph-Based Image Segmentation》

step1:计算区域集R里每个相邻区域的相似度S={s1,s2,…}
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色彩空间)。

其中,是直方图中第个bin的值。

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

举例:

  1. #include "opencv2/ximgproc/segmentation.hpp"
  2. #include "opencv2/highgui.hpp"
  3. #include "opencv2/core.hpp"
  4. #include "opencv2/imgproc.hpp"
  5. #include <iostream>
  6. #include <ctime>
  7. using namespace cv;
  8. using namespace cv::ximgproc::segmentation;
  9. static void help() {
  10. std::cout << std::endl <<
  11. "Usage:" << std::endl <<
  12. "./ssearch input_image (f|q)" << std::endl <<
  13. "f=fast, q=quality" << std::endl <<
  14. "Use l to display less rects, m to display more rects, q to quit" << std::endl;
  15. }
  16. int main(int argc, char** argv) {
  17. // If image path and f/q is not passed as command
  18. // line arguments, quit and display help message
  19. if (argc < 3) {
  20. help();
  21. return -1;
  22. }
  23. // speed-up using multithreads
  24. // void cv::setUseOptimized(bool onoff), Enables or disables the optimized code.
  25. setUseOptimized(true);
  26. setNumThreads(4);
  27. // read image
  28. Mat im = imread(argv[1]);
  29. // resize image
  30. int newHeight = 200;
  31. int newWidth = im.cols*newHeight/im.rows;
  32. resize(im, im, Size(newWidth, newHeight));
  33. // create Selective Search Segmentation Object using default parameters
  34. Ptr<SelectiveSearchSegmentation> ss = createSelectiveSearchSegmentation();
  35. // set input image on which we will run segmentation
  36. ss->setBaseImage(im);
  37. // Switch to fast but low recall Selective Search method
  38. if (argv[2][0] == 'f') {
  39. ss->switchToSelectiveSearchFast();
  40. }
  41. // Switch to high recall but slow Selective Search method
  42. else if (argv[2][0] == 'q') {
  43. ss->switchToSelectiveSearchQuality();
  44. }
  45. // if argument is neither f nor q print help message
  46. else {
  47. help();
  48. return -2;
  49. }
  50. // run selective search segmentation on input image
  51. std::vector<Rect> rects;
  52. ss->process(rects);
  53. std::cout << "Total Number of Region Proposals: " << rects.size() << std::endl;
  54. // number of region proposals to show
  55. int numShowRects = 100;
  56. // increment to increase/decrease total number of reason proposals to be shown
  57. int increment = 50;
  58. while(1) {
  59. // create a copy of original image
  60. Mat imOut = im.clone();
  61. // itereate over all the region proposals
  62. for(int i = 0; i < rects.size(); i++) {
  63. if (i < numShowRects) {
  64. rectangle(imOut, rects[i], Scalar(0, 255, 0));
  65. }
  66. else {
  67. break;
  68. }
  69. }
  70. // show output
  71. imshow("Output", imOut);
  72. // record key press
  73. int k = waitKey();
  74. // m is pressed
  75. if (k == 109) {
  76. // increase total number of rectangles to show by increment
  77. numShowRects += increment;
  78. }
  79. // l is pressed
  80. else if (k == 108 && numShowRects > increment) {
  81. // decrease total number of rectangles to show by increment
  82. numShowRects -= increment;
  83. }
  84. // q is pressed
  85. else if (k == 113) {
  86. break;
  87. }
  88. }
  89. return 0;
  90. }

上边代码git地址:https://code.csdn.net/guoyunfei20/selective_search_opencv_demo.git(运行需要安装OpenCV3.0以上 + contrib)

选择性搜索(selective search)+opencv实现相关推荐

  1. 目标检测之选择性搜索-Selective Search

    在基于深度学习的目标检测算法的综述 那一节中我们提到基于区域提名的目标检测中广泛使用的选择性搜索算法.并且该算法后来被应用到了R-CNN,SPP-Net,Fast R-CNN中.因此我认为还是有研究的 ...

  2. 第三十三节,目标检测之选择性搜索-Selective Search

    https://www.cnblogs.com/zyly/p/9259392.html 添加链接描述 转载此人 目录 一 选择性搜索的具体算法(区域合并算法) 二 保持多样性的策略 1.颜色空间变换 ...

  3. 选择性搜索算法(Selective Search)超详解(通俗易懂版)

    Selective Search(选择性搜索)基于Graph-Based图像分割,是RCNN和Fast RCNN的区域推荐算法. SS算法由IJCV 2012的论文<Selective Sear ...

  4. 【转载】选择性搜索算法介绍——Selective Search

    RCNN中提出了SS算法用于初步产生2k左右的候选框,最开始觉得这个算法很普通,和滑动窗口这类的笨方法一样.然而现在发现并不是这样,这个方法很精巧,其中包含的图像相似度计算似乎还能用到其他地方.这一切 ...

  5. 目标识别的选择性搜索

    目标识别的选择性搜索 Selective Search for Object Recognition 论文地址: https://ivi.fnwi.uva.nl/isis/publications/b ...

  6. 目标检测之Selective Search原理简述(转)

    目标检测物体的候选框是如何产生的? 如今深度学习火热的今天,RCNN/SPP-Net/Fast-RCNN等文章都会谈及bounding boxes(候选边界框)的生成与筛选策略.那么候选框是如何产生, ...

  7. Selective Search(选择性搜索)算法学习

    Selective Search(选择性搜索)算法 在目标检测中,这个算法,可以启发式地搜索出可能包含物体的区域,而不用随机盲目地找很多个方框. 最简单的目标检测 我们的思路是先搞出一些小的方框(不一 ...

  8. 选择性搜索(selective search)

    该文翻译整理自:selective search for object detection(c++ / python) 一.目标检测 VS 目标识别 目标识别(objec recognition)是指 ...

  9. 论文笔记 《Selective Search for Object Recognition》

    论文笔记 <Selective Search for Object Recognition> 项目网址:http://koen.me/research/selectivesearch/ 一 ...

最新文章

  1. iOS 6上的Safari是否缓存$ .ajax结果?
  2. POJ-2391 Ombrophobic Bovines 网络流-拆点构图
  3. 微信月活跃用户数6.97亿 全球十大消息应用第四
  4. Android把自己应用加入到系统文件分享中
  5. 求方差时为什么要除以N—1,而不是除以N!【通俗理解-非数学专业】
  6. 佛山市南海技师学校计算机类,佛山南海信息技术学校2021年有哪些专业
  7. 160 - 18 Brad Soblesky.1
  8. python里面的数学
  9. GNOME界面简单使用
  10. 「新手向」koa2从起步到填坑
  11. VBNET常用字符串常量
  12. 如日中天的Uber到底是用什么开发语言做到的?
  13. rtklib-RINEX文件读取-rinex.c解析(二)
  14. Excel如何通过年份上的时间差操作求得员工工龄
  15. 和平精英灵敏度分享码服务器没有响应,和平精英主播灵敏度
  16. QQ能上网,网页不行总解决办法
  17. VRTK_Example解释
  18. 远程桌面链接怎么用(win10电脑远程桌面连接工具怎么使用)
  19. python读取json文件,大批量写入mongo
  20. java 设计模式 路由器_Java设计模式——工厂模式

热门文章

  1. node.js-session问题
  2. php sqlite存入文件夹,PHP_小文件php+SQLite存储方案,我们草根站长购买的虚拟主机 - phpStudy...
  3. [转]HSPICE软件的应用及常见问题解决
  4. td设置自动隐藏,hover事件触发全部显示,table列表不用担心信息太长导致界面不美观
  5. javascript学习之闭包
  6. 总结一下最近面试经常被问到的问题(2019年4月)
  7. NLP知识包--语义分析-语义角色标注
  8. spring live上有个入门的整合SSH的例子
  9. ssm框架重定向_精选 SSM 框架面试题整理
  10. SQL那些事儿(十一)--ODBC,OLE-DB,ADO.NET区别