cv_prj2
Computer Vision Project 2 – Harris Corner Detector
- 姓名: 王兴路
- 学号: 3140102282
- 指导老师: 宋明黎
- 2016-12-16 19:30:22 星期五
Content:
ReadMe
Run Demo
Develop Platform
FileList
Functionality
Implementation
Pipeline
Second Moment Matrix M
Adapative Non Maxima Suppression
Experiments
Implemetation
Demo & Experiments
Median or Guassian
k
aperture_size
Reference
ReadMe
Run Demo
This program implements Harris Corner Detector via Adaptive Nonmaxia Suppression.
- Click
Demo.batto see Demo, the middle resule will be generated in current directory. - Run it though
cmd/bashfollowing usage below: - Usage 1:
prj2.exe inputImgName k=(0.04) aperture_size(=3)guassian=(true)Ada_NMS=(true) R_thre_left=(5000) nms_left=(500) c_robust=(0.9)
- Usage 2:
prj2.exe inputImgName k=(0.04) aperture_size(=3)guassian=(true)Ada_NMS=(false) left=(500)
inputImgNameis required. All other params are alternetive, the default is showed in Usage 1. For example, the following has been tested.
prj2.exe roof.jpgprj2.exe roof.jpg 0.04 5
Develop Platform
- OS system: Win10
- VS 2013 + OpenCV 2.4.12
FileList
.├── 3140102282_WangXinglu_Prj2.pdf├── Demo│ ├── *.jpg (sample input img)│ ├── Demo.bat (click to run)│ ├── *.dll (dependence)│ ├── prj2.exe│ └── SampleOut└── Src├── prj2│ ├── harris.cpp│ ├── harris.h│ ├── main.cpp│ └── prj2.vcxproj├── prj2.sdf├── prj2.sln└── prj2.v12.suo
Functionality
- 求解 R response: $R = |M|-k*Tr(M)$
- 输出中间结果 $ \lambda_{max}$, $\lambda{min}$
- 输出JET Pseudo Img可视化, 对R图进行$Rectify$+$log$操作,符合人类视觉的感受范围。
- NMS部分实现
Adapative NMS和一般的NMS两种算法。 - 命令行解析参数,方便调参。包括
k,aperture_size, 是否采用guassian核, 是否采用Ada_NMS, 以及对应的NMS参数。并且都有默认参数。
Implementation
Pipeline
st=>start: Startread=>operation: Parse Argccal=>operation: calculateR responese map& middle resultnms=>operation: nmsvis=>operation: visualze and imwriteee=>endst->read->cal->nms->vis->ee
Second Moment Matrix M
课件上的公式没有将标量和矩阵分清
$$M = \sum\limits_{x,y} {\left\{ {G(x,y)\left[ {\begin{array}{*{20}{c}}
{{I_x}^2}&{{I_x}{I_y}}\\
{{I_x}{I_y}}&{{I_y}^2}
\end{array}} \right]} \right\}} $$
上面式子中$M$事实上是标量,正确的标量形式写法应当是:
$$M(i,j) = \sum\limits_{x,y} {\left\{ {G(x,y)\left[ {\begin{array}{*{20}{c}}
{{I_x}^2(i + x,j + y)}&{{I_x}{I_y}(i + x,j + y)}\\
{{I_x}{I_y}(i + x,j + y)}&{{I_y}^2(i + x,j + y)}
\end{array}} \right]} \right\}} $$
使用$Correlation$算符$\otimes$,以矩阵形式简写如下:
$$M_{N \times N \times 2 \times 2} = f\left( {\left[ {\begin{array}{*{20}{c}}
{{M_{11}}}&{{M_{12}}}\\
{{M_{21}}}&{{M_{22}}}
\end{array}} \right]} \right) = f\left( {\left[ {\begin{array}{*{20}{c}}
{G \otimes \left( {{I_x}^2} \right)}&{G \otimes \left( {{I_x}{I_y}} \right)}\\
{G \otimes \left( {{I_x}{I_y}} \right)}&{G \otimes \left( {{I_y}^2} \right)}
\end{array}} \right]} \right)$$
其中$f$是Reshape函数,实现维度变换。因为高维矩阵$M$在每一个像素点上都是一个$2 \times 2$的二阶动量矩阵。计算得$M_{ij}$后,需要将对应位置的值拼接起来形成二阶动量矩阵。
$$f:\left( {\begin{array}{*{20}{c}}
{{R_{N \times N}}}&{{R_{N \times N}}}\\
{{R_{N \times N}}}&{{R_{N \times N}}}
\end{array}} \right) \to {R_{N \times N \times 2 \times 2}}$$
Adapative Non Maxima Suppression
我们找到的Harris Corner点数量较多,且容易出现聚簇情况,需要对Harris Corner点的数量和位置分布进行处理,这就用到了Adaptive Non-Maximal Suppression。
该算法在这篇文章中提出[Multi-Image Matching using Multi-Scale Oriented Patches, Brown et al., CVPR 2005]
使用ANMS需要完成两个任务:
- 从图像中抽取指定数量的interest points
- 使interest points均匀分布在图像中。
算法原理如下:
设共有$N$个特征点,
- $\mathbf{x}_i$代表特征点$i$的坐标
- $v_i$代表特征点$i$的R response值。
对于特征$i$,定义抑制半径
$$
r_i = \min_{j \in I_i} \| \mathbf{x}_i - \mathbf{x}_j \|_2
$$
其中$I_i$是满足如下公式的所有特征点的集合
$$
I_i = \{ j \in \{1,\dots, n\} \mid v_i < c_\textrm{robust} v_j \}.
$$
对于每个点计算$r_i$,降序排序,取Top $NMS_left$ 个点,即为所求的需要保留的特征点。
从直观上解释,先不看$c_\textrm{robust}$, 如果一个不厉害的点很近的地方就有一个很厉害的点,那么这个点就应该排名靠后。所以按照距离排序。
[========]
Experiments
可以看到:
- Ada_NMS在自然场景照片中获得了很好的效,这张图没有一个点会重复。
- Ada_NMS在规则格子图上效果相比NMS稍稍好一些。但是25个点不能恰好分布到25个格点。如果具体计算会发现,这是因为Ada_NMS只能够给临近的$4 \times 4$划出两个等级$1$和$\sqrt{2}$。
| \ | global | local |
|---|---|---|
| NMS | ||
| Ada_NMS | ||
| NMS | ||
| Ada_NMS |
Implemetation
vector<Point_float_pair> Point_R;// minMaxLoc(R, &R_min, &R_max);for (int row = 0; row < R.rows; row++){for (int col = 0; col < R.cols; col++){float R_tmp = R.at<float>(row, col);if (R_tmp < 0 || R_tmp <1000)continue;Point_R.push_back(make_pair(Point(row, col), R_tmp));}}R_thre_left = min(R_thre_left, (int)Point_R.size());partial_sort(Point_R.begin(), Point_R.begin()+R_thre_left,Point_R.end(), Point_float_sort());Point_R.resize(R_thre_left);vector<Point_float_pair> Point_dist;for (int i = 0; i < Point_R.size(); ++i){float dist = m_infty;Point now_point = Point_R.at(i).first;for (int j = 0; j < Point_R.size(); ++j){Point counter_point = Point_R.at(j).first;if (i != j && Point_R.at(i).second <c_robust * Point_R.at(j).second){ //0.01==>all 1 ; 10 ==> all inffloat dist_tmp = norm(now_point - counter_point);if (dist_tmp < dist)dist = dist_tmp;}}Point_dist.push_back(make_pair(now_point, dist));}nms_left = min(nms_left, (int)Point_dist.size());partial_sort(Point_dist.begin(), Point_dist.begin() + nms_left, Point_dist.end(), Point_float_sort());Point_dist.resize(nms_left);Mat R_nms(R.size(), CV_32F, Scalar::all(0));for (int i = 0; i <Point_dist.size(); ++i){Point now_point = Point_dist.at(i).first;int row = now_point.x;int col = now_point.y;R_nms.at<float>(row, col) = 1;circle(img_harris, Point(col, row), 4, Scalar(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255)));}
Demo & Experiments
其中$R_{psu}$的具体操作是:
- 将所有负响应置为R图中除去负数的最小值
- $log$操作
- 使用pseudo map 展示
可以看到$R_{psu}$中深蓝色的,即为原本为负数的平坦区域
| $\lambda_{max}$ | $\lambda_{min}$ | $R_{psu}$ |
|---|---|---|
| $R$ | $R_{NMS}$ | $img_{harris}$ |
| $\lambda_{max}$ | $\lambda_{min}$ | $R_{psu}$ |
| $R$ | $R_{NMS}$ | $img_{harris}$ |
Median or Guassian
从测试图片看没有明显差别(Gassian略好):
| Median | Guassian |
|---|---|
k
k增大,检测到的点数变少,效果变差。(不稳定,最符合Corner特性的点没有被保留)
| 0.04 | 0.20 | 0.24 | 0.28 |
|---|---|---|---|
aperture_size
k增大,检测到的点数变少,效果变好。(稳定,响应大的点保留,最符合Corner特性的点保留)
| 3 | 9 |
|---|---|
Reference
https://stackedit.io/editor#fn:footnote
https://www.zybuluo.com/AntLog/note/63228
https://www.learnopencv.com/applycolormap-for-pseudocoloring-in-opencv-c-python/
http://stackoverflow.com/questions/23680073/finding-local-maxima-in-an-image
http://docs.opencv.org/2.4/modules/core/doc/operations_on_arrays.html#min
cv_prj2的更多相关文章
随机推荐
- memcached tomcat maven 学习记录
2016.12.11 maven 快速搭建项目,只要有pom.xml文件配置好依赖 可以把项目切割(具体切割出来的块怎么用?) nginx 负载均衡 文件服务器 主要配置nginx.conf 文件 ...
- Zepto API 学习
1. after, before, append, prepend 的区别 A.after(B) ==== B.insertAfter(A) // B 放在 A 的后面 A.before(B) == ...
- PLSQL登录数据库 报ORA -12154的诡异问题
https://q.cnblogs.com/q/89420/ 现象: 1.机器上先后安装了oracle两个版本的client.在装第一个client后,plsql可以顺利连接数据库a并登录. 2.安装 ...
- Servlet学习五——流的分发
在上一节中有提到,流的传输,可以考虑Stream,但如果需要同时分发流和其它信息,,就需要再考虑其它方式了. 在coding中,服务端查询结果都是以gson进行传输,当需要传输一个语音并且同时需要传输 ...
- 用于模式匹配的String方法
String支持四种使用正则表达式的方法. 1.search()返回第一个与之匹配的子串的起始位置,找不到返回-1.search()参数是一个正则表达式,如果参数不是正则表达式,则会先通过RegExp ...
- Cannot find or open the PDB file问题的解决
'testcv.exe' (Win32): Loaded 'D:\Documents\Visual Studio 2013\Projects\testcv\x64\Debug\testcv.exe'. ...
- Js文件中文乱码
aspx页面引用的js文件中如果包括中文,中文显示乱码或者引起脚本错误.提示是'未结束的字符串' 原因:aspx页面的默认编码是utf-8,而js文件的默认编码是gb2312,两者之间不一致引起了中文 ...
- openssl和Java的keytool证书相关的命令总结
Java的keytool keytool -genkey -alias myserver -keyalg RSA -keysize -keystore oauth-server.keystore -v ...
- php 快速排序
快速排序是以其中一个数为比较标准,其他比较的数分块处理,应用递归按相同想法处理数据 比如:4 3 6 2 1 7 8 以4为比较对象 排序为 3 2 1 6 7 8 左边为 3 2 1 右边 为 6 ...
- XSS的原理分析与解剖(转)
(转)http://netsecurity.51cto.com/art/201408/448305_all.htm 0×01 前言: <xss攻击手法>一开始在互联网上资料并不多(都是现成 ...