tMatcher1 を使用したサブピクセ​ル単位でのテンプレー​トマッチング

4 views (last 30 days)
Keiichiro Yashima
Keiichiro Yashima on 11 Dec 2020
こんにちは。
私は現在テンプレートマッチングを使用して、2枚の画像で三次元計測を行なっています。
使用しているテンプレートマッチングの関数は
tMatcher1 = vision.TemplateMatcher('Metric','Sum of absolute differences');
location = tMatcher1(OriImage2,Template);
なのですが、サブピクセル単位でマッチングする方法が分からずに困っております。
そもそもこの関数では整数値でマッチングを行い、整数値の結果しか出力することしかできないのでしょうか。
以下に、サンプルコードを添付いたします。
よろしくお願い致します。
OriImage1 = rgb2gray(imread('〜'));
OriImage2 = rgb2gray(imread('〜'));
figure;
imagesc(OriImage1);
axis image
hold on
%画像の一点を指定
[x,y] = ginput(1);
plot(x,y, 'ro', 'MarkerSize',5);
Template = OriImage1(y-10:y+10,x-10:x+10) ;
tMatcher1 = vision.TemplateMatcher('Metric','Sum of absolute differences');
location = tMatcher1(OriImage2,Template);
lx = location(:,1);
ly = location(:,2);
OriImage25151 = OriImage2(ly-100:ly+100,lx-100:lx+100);
img.temp=zeros(7:7);
for n1 = -11:9
for m1 = -11:9
j1=n1+12;
h1=m1+12;
img(j1,h1).temp = OriImage1(y+n1-2:y+n1+4,x+m1-2:x+m1+4);
end
end
% img2.locat=zeros(1:2);
% for n2 = -11:9
% for m2 = -11:9
% j2=n2+12;
% h2=m2+12;
% img2(j2,h2).locat = tMatcher1(OriImage25151,img(j2,h2).temp);
% end
% end
matchedPoints25151 = [];
for n2 = -11:9
for m2 = -11:9
j2=n2+12;
h2=m2+12;
xylocation = tMatcher1(OriImage25151,img(j2,h2).temp);
matchedPoints25151 = cat(1,matchedPoints25151,xylocation);
end
end
xmathced2 = matchedPoints25151(:,1)+(lx-100);
ymathced2 = matchedPoints25151(:,2)+(ly-100);
matchedPoints2before = [xmathced2 ymathced2];
matchedPoints2 = cast(matchedPoints2before,'double');
%mathedPoints1
[x1, y1] = meshgrid(x-10:x+10,y-10:y+10);
matchedPoints1 = ([x1(:) y1(:)]);
showMatchedFeatures(OriImage1,OriImage2,matchedPoints1,matchedPoints2);

Answers (0)

Categories

Find more on 単一カメラとステレオ カメラのキャリブレーション in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!