Harris检测角点C代码(opencv角点检测harris)
admin 发布:2022-12-19 23:12 173
本篇文章给大家谈谈Harris检测角点C代码,以及opencv角点检测harris对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
- 1、图像特征之Harris角点检测
- 2、opencv里的cvCornerHarris函数 怎么用
- 3、关于Harris角点检测以及改进算法的matlab代码问题
- 4、求助Matlab关于Harris角点检测的两个问题
- 5、c语言写harris角点提取难吗
- 6、CV算法:Harris角点(Harris Corner Detector)
图像特征之Harris角点检测
简单说:
和边缘检测一样也有了成熟的算法。
思想是用小窗口在图像上平移,如果窗口内像素:
通过移动前后窗口的自相关函数(对应位置的差平方)大小,可以衡量变化程度。下图中u, v为移动方向,取相互垂直的方向最佳。
窗口的权重可以取均值或者高斯权重,为下图中的w。
将I(x + u, y + v)进行一阶泰勒展开,得到:
因此E(u, v)化为:
E(u, v)变成一个二元二次函数:
此时回顾一下角点处,E(u, v)应满足对u, v变化而剧烈变化,如何用这个二元二次表达式来衡量这种变化程度呢?
利用几何,可知E(u, v)是椭圆形的表达式,因此原点到椭圆形的边缘可表示沿改方向的变化程度。
已知u, v方向垂直,通过坐标变换可以更新E(u, v)为E(x, y),相当于椭圆旋转为于x, y方向垂直,不改变椭圆的形状。
但这样做的原因是,我们可以将矩阵转换为对角矩阵的形式,其中特征值就是旋转后,x和y方向的变化程度的衡量。
设定一个阈值,就可以判断是conner、edge、flat了。
具体步骤:
OpenCV中对应的函数是:
opencv里的cvCornerHarris函数 怎么用
openv中对cvWaitkey函数的定义如下:
int cvWaitKey( int delay=0 )
返回值为int型,函数的参数为int型,当delay小于等于0的时候,如果没有键盘触发,则一直等待,此时的返回值为-1,否则返回值为键盘按下的码字;当delay大于0时,如果没有键盘的的触发,则等待delay的时间,此时的返回值是-1,否则返回值为键盘按下的码字。
测试代码如下:
#includestdio.h
#includecv.h
#includehighgui.h
int main()
{ IplImage *src=cvLoadImage("car.jpg",-1);
cvShowImage("car",src);
int t=cvWaitKey(-1);
printf("cvWaitKey return: %d",t);
return 0;
}
关于Harris角点检测以及改进算法的matlab代码问题
这个谈不上改进,一个横向检测一个纵向检测,此外还有斜着的。但是哪个好是针对图片库而言的。碰巧你检测的那几张更适合x方向而已。建议:用公共图片库挨个做实验,再说明哪个比较好。
求助Matlab关于Harris角点检测的两个问题
%MatLab角点检测程序harris。
ori_im2=rgb2gray(imread('2.bmp'));
%ori_im2=imresize(ori_im2',0.50,'bicubic'); %加上这句图就变成竖着的了
fx = [5 0 -5;8 0 -8;5 0 -5]; % % la gaucienne,ver axe x
Ix = filter2(fx,ori_im2); % la convolution vers axe x
fy = [5 8 5;0 0 0;-5 -8 -5]; % la gaucienne,ver axe y
Iy = filter2(fy,ori_im2); % la convolution vers axe y
Ix2 = Ix.^2;
Iy2 = Iy.^2;
Ixy = Ix.*Iy;
clear Ix;
clear Iy;
h= fspecial('gaussian',[3 3],2); % générer une fonction gaussienne,sigma=2
Ix2 = filter2(h,Ix2);
Iy2 = filter2(h,Iy2);
Ixy = filter2(h,Ixy);
height = size(ori_im2,1);
width = size(ori_im2,2);
result = zeros(height,width); % enregistrer la position du coin
R = zeros(height,width);
K=0.04;
Rmax = 0; % chercher la valeur maximale de R
for i = 1:height
for j = 1:width
M = [Ix2(i,j) Ixy(i,j);Ixy(i,j) Iy2(i,j)];
R(i,j) = det(M)-K*(trace(M))^2; % % calcule R
if R(i,j) Rmax
Rmax = R(i,j);
end;
end;
end;
cnt = 0;
for i = 2:height-1
for j = 2:width-1
% réduire des valuers minimales ,la taille de fenetre 3*3
if R(i,j) 0.01*Rmax R(i,j) R(i-1,j-1) R(i,j) R(i-1,j) R(i,j) R(i-1,j+1) R(i,j) R(i,j-1) R(i,j) R(i,j+1) R(i,j) R(i+1,j-1) R(i,j) R(i+1,j) R(i,j) R(i+1,j+1)
result(i,j) = 1;
cnt = cnt+1;
end;
end;
end;
[posr2, posc2] = find(result == 1);
cnt % compter des coins
figure
imshow(ori_im2);
hold on;
plot(posc2,posr2,'w*');
harris优化的角点检测
%%%Prewitt Operator Corner Detection.m
%%%时间优化--相邻像素用取差的方法
%%
clear;
Image = imread('15.bmp'); % 读取图像
Image = im2uint8(rgb2gray(Image));
dx = [-1 0 1;-1 0 1;-1 0 1]; %dx:横向Prewitt差分模版
Ix2 = filter2(dx,Image).^2;
Iy2 = filter2(dx',Image).^2;
Ixy = filter2(dx,Image).*filter2(dx',Image);
%生成 9*9高斯窗口。窗口越大,探测到的角点越少。
h= fspecial('gaussian',9,2);
A = filter2(h,Ix2); % 用高斯窗口差分Ix2得到A
B = filter2(h,Iy2);
C = filter2(h,Ixy);
nrow = size(Image,1);
ncol = size(Image,2);
Corner = zeros(nrow,ncol); %矩阵Corner用来保存候选角点位置,初值全零,值为1的点是角点
%真正的角点在137和138行由(row_ave,column_ave)得到
%参数t:点(i,j)八邻域的“相似度”参数,只有中心点与邻域其他八个点的像素值之差在
%(-t,+t)之间,才确认它们为相似点,相似点不在候选角点之列
t=20;
%我并没有全部检测图像每个点,而是除去了边界上boundary个像素,
%因为我们感兴趣的角点并不出现在边界上
boundary=8;
for i=boundary:nrow-boundary+1
for j=boundary:ncol-boundary+1
nlike=0; %相似点个数
if Image(i-1,j-1)Image(i,j)-t Image(i-1,j-1)Image(i,j)+t
nlike=nlike+1;
end
if Image(i-1,j)Image(i,j)-t Image(i-1,j)Image(i,j)+t
nlike=nlike+1;
end
if Image(i-1,j+1)Image(i,j)-t Image(i-1,j+1)Image(i,j)+t
nlike=nlike+1;
end
if Image(i,j-1)Image(i,j)-t Image(i,j-1)Image(i,j)+t
nlike=nlike+1;
end
if Image(i,j+1)Image(i,j)-t Image(i,j+1)Image(i,j)+t
nlike=nlike+1;
end
if Image(i+1,j-1)Image(i,j)-t Image(i+1,j-1)Image(i,j)+t
nlike=nlike+1;
end
if Image(i+1,j)Image(i,j)-t Image(i+1,j)Image(i,j)+t
nlike=nlike+1;
end
if Image(i+1,j+1)Image(i,j)-t Image(i+1,j+1)Image(i,j)+t
nlike=nlike+1;
end
if nlike=2 nlike=6
Corner(i,j)=1;%如果周围有0,1,7,8个相似与中心的(i,j)
%那(i,j)就不是角点,所以,直接忽略
end;
end;
end;
CRF = zeros(nrow,ncol); % CRF用来保存角点响应函数值,初值全零
CRFmax = 0; % 图像中角点响应函数的最大值,作阈值之用
t=0.05;
% 计算CRF
%工程上常用CRF(i,j) =det(M)/trace(M)计算CRF,那么此时应该将下面第105行的
%比例系数t设置大一些,t=0.1对采集的这几幅图像来说是一个比较合理的经验值
for i = boundary:nrow-boundary+1
for j = boundary:ncol-boundary+1
if Corner(i,j)==1 %只关注候选点
M = [A(i,j) C(i,j);
C(i,j) B(i,j)];
CRF(i,j) = det(M)-t*(trace(M))^2;
if CRF(i,j) CRFmax
CRFmax = CRF(i,j);
end;
end
end;
end;
%CRFmax
count = 0; % 用来记录角点的个数
t=0.01;
% 下面通过一个3*3的窗口来判断当前位置是否为角点
for i = boundary:nrow-boundary+1
for j = boundary:ncol-boundary+1
if Corner(i,j)==1 %只关注候选点的八邻域
if CRF(i,j) t*CRFmax CRF(i,j) CRF(i-1,j-1) ......
CRF(i,j) CRF(i-1,j) CRF(i,j) CRF(i-1,j+1) ......
CRF(i,j) CRF(i,j-1) CRF(i,j) CRF(i,j+1) ......
CRF(i,j) CRF(i+1,j-1) CRF(i,j) CRF(i+1,j)......
CRF(i,j) CRF(i+1,j+1)
count=count+1;%这个是角点,count加1
else % 如果当前位置(i,j)不是角点,则在Corner(i,j)中删除对该候选角点的记录
Corner(i,j) = 0;
end;
end;
end;
end;
% disp('角点个数');
% disp(count)
figure,imshow(Image); % display Intensity Image
hold on;
% toc(t1)
for i=boundary:nrow-boundary+1
for j=boundary:ncol-boundary+1
column_ave=0;
row_ave=0;
k=0;
if Corner(i,j)==1
for x=i-3:i+3 %7*7邻域
for y=j-3:j+3
if Corner(x,y)==1
% 用算数平均数作为角点坐标,如果改用几何平均数求点的平均坐标,对角点的提取意义不大
row_ave=row_ave+x;
column_ave=column_ave+y;
k=k+1;
end
end
end
end
if k0 %周围不止一个角点
plot( column_ave/k,row_ave/k ,'g.');
end
end;
end;
%end
c语言写harris角点提取难吗
针对
Har
ris
角点检
测算法对
T
型和斜
T
型
角点存在定
位不准确
以及运算速
度慢的问题
,
提出
了一种改
进算法。
改进算法计算目标像素点的
8
邻域范围内与之灰度相似的点的
数目
,
然后对目标
像素点周
围其他像素
点按同
样方法
处
理
,
并对得到的计算数据进行比较
,
分析出局部范围内的像素
点的灰度值
分布。根据比
较结果
,
从中遴
选出部
分像素
点
作为下一步角点检测的计算对象
,
并计算其角
点响应函数值
,
如
果角点响应
函数值大
于设定的阈
值
,
该
点则会
被确定
为
最终的角点。实验结果表明
:
改进算法的角点检测时间
仅为原
算法的
14.
3%
,
并实现
了对
T
、
斜
T
型角
点准确
定位
,
提
高了
H
arr
is
角点检测算法的检测效率和精度。
关
键
词
:
机器视觉
;
图像处理
;
角点检测
;
H
arr
is
算法
;
角点响应函数
中图分类号
:
T
P391.
4
文献标识码
:
A
An
improved
algorithm
for
Harris
corner
detection
WANG
Wei
1,
2
,
TANG
Yi
ping
1
,
REN
Juan
li
3
,
SH
I
Bing
chuan
1
,
LI
Pei
lin
2
,
H
AN
H
ua
ting
2
(
1
.
State
K
ey
L
abor
atory
f
or
Manuf
acturing
Sy
stem
Eng
ineer
ing
,
X
i
an
J
iaotong
University
,
X
i
an
710049
,
China;
2
.
L
aunch
E
ngineer
ing
Dep
ar
tm
ent,
M
issile
I
nstitute
of
Air
Force
E
ngineering
Univer
sity
,
Sany
uan
713800
,
China;
3
.
S
chool
of
A
rt
and
Media
,
X
i
an
T
echnological
Univer
sity
,
X
i
an
710032
,
China)
Abstract:
An
impr
oved
algo
rithm
for
H
arris
cor
ner
detectio
n
is
proposed
by
considering
the
lim
itatio
ns
of
inaccurate
localization
to
tw
o
kinds
of
corners
(
T
and
diag
onal
T
)
and
lo
w
efficiency
in
H
ar
ris
algo
r
ithm.
T
he
im
pro
ved
alg
orithm
is
used
to
calculate
the
number
o
f
points
that
the
g
ray
level
is
similar
to
that
of
the
target
pixel
w
ithin
8
neighborhoods
of
the
tar
get
pixel,
and
then
to
tr
eat
the
other
points
in
the
sam
e
manner.
Som
e
of
the
pixels
are
selected
as
the
calculating
objects
for
the
nex
t
step
of
cor
ner
detection
by
analy
zing
distr
ibution
of
the
pixels
in
lo
cal
area
and
com
paring
the
calculated
data,
and
the
v
alues
for
their
corner
response
functions
are
calculated.
if
the
value
is
larg
er
than
threshold,
it
w
ill
be
co
nsidered
as
the
final
corner.
T
he
experimental
results
show
that
the
com
putation
tim
e
of
impr
oved
algorithm
is
o
nly
14.
3%
that
of
the
or
ig
inal
H
arris
alg
orithm,
and
it
can
realize
the
accur
ate
localization
to
T
and
diag
onal
T
corners,
w
hich
m
eans
that
im
pro
ved
algo
rithm
acquires
better
eff
CV算法:Harris角点(Harris Corner Detector)
Harris Corner Detector
斯坦福CS131-1718作业3
cornell-CS4670-5670-2016spring lec10_features2_web-Harris(这个比较详细)
需要找出一些显著特征点进行匹配
从图中扣出一块,然后要进行匹配,有些任意有些不容易,因此我们要找出一些特征的特征,也就是我们这节要说的“角”(Corner)
视角变化也仍然可以很好的辨识+跟周围点在任何方向变化都很大——好的特征
加窗,窗在任何方向上随意移动变化都很大的就是角。
算法结果:
Harris检测角点C代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于opencv角点检测harris、Harris检测角点C代码的信息别忘了在本站进行查找喔。
版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;
- 上一篇:html时间代码的简单介绍
- 下一篇:买毕设代码靠谱吗(买的程序毕设能过吗)
相关推荐
- 05-17网站检测,网站检测工具有哪些
- 05-09网页代码,网页代码快捷键
- 05-06单页网站的代码(完整的网页代码)[20240506更新]
- 05-06个人主页图片代码(个人主页图片代码怎么弄)[20240506更新]
- 05-06提取微信名片代码(微信名片信息提取)[20240506更新]
- 05-06php后台权限管理代码(php管理员权限)[20240506更新]
- 05-06付费观看代码php(付费观看代码)[20240506更新]
- 05-06在线html执行代码(html怎么运行)[20240506更新]
- 05-06源代码管理资源管理器(资源管理器运行代码)[20240506更新]
- 05-06代码源软件库(程序代码库)[20240506更新]
取消回复欢迎 你 发表评论:
- 标签列表
- 最近发表
- 友情链接