我尝试创建一个simulink块,在此示例后使用冲浪点进行模板匹配:http://www.mathworks.it/it/help/vision/gs/object-detection-and-tracking.html块接收输入场景视频信号(作为'clutteredDesk')和常量模板图像(作为'stapleRemover'框图像) . 我使用Matlab功能块(嵌入式MATLAB功能块)来做到这一点,我写道:

function out = fcn(in, template)


coder.extrinsic('detectSURFFeatures');
coder.extrinsic('indx2mtempl');
coder.extrinsic('extractFeatures');
coder.extrinsic('matchFeatures');
coder.extrinsic('estimateGeometricTransform');
coder.extrinsic('transformPointsForward'); 



scenePoints = detectSURFFeatures(in); %punti caratteristici dello scenario
templPoints = detectSURFFeatures(template);



[boxFeatures, templPoints] = extractFeatures(template, templPoints);
[sceneFeatures, scenePoints] = extractFeatures(in, scenePoints);





boxPairs = matchFeatures(boxFeatures, sceneFeatures);

s = coder.nullcopy(zeros(1,2));
s = size(boxPairs);


[matchTempl,matchScene] = indx2mtempl(templPoints,scenePoints, boxPairs);
if s(1) < 3

    out = single(zeros(1,8));
else


tform = estimateGeometricTransform(matchTempl, matchScene, 'affine');


boxPolygon = [1, 1;...                           % top-left
        size(template, 2), 1;...                 % top-right
        size(template, 2), size(template, 1);... % bottom-right
        1, size(template, 1);...                 % bottom-left
        1, 1];                   % top-left again to close the polygon

newBoxPolygon = coder.nullcopy(single(zeros(5,2)));
newBoxPolygon = transformPointsForward(tform, boxPolygon);

out = coder.nullcopy(single(zeros(1,8)));



out = ([newBoxPolygon(1,1) newBoxPolygon(1,2)...
    newBoxPolygon(2,1) newBoxPolygon(2,2) ...
    newBoxPolygon(3,1) newBoxPolygon(3,2) ...
    newBoxPolygon(4,1) newBoxPolygon(4,2)]);


end

其中indx2mtempl是一个为几何变换估计提取匹配点位置的函数:

function [matchlocTempl,matchlocScene]  = indx2mtempl(SUpoints1,SUpoints2,pairs)


loc1 = SUpoints1.Location;
loc2 = SUpoints2.Location;
matchlocTempl = loc1(pairs(:,1),:);
matchlocScene = loc2(pairs(:,2),:);

我会检查匹配点的数量,按大小检查行数(boxPairs) . 如你所知,如果数学点小于3则不会估计几何变换 . 我尝试使用视频'cat_video.bin'(使用'读取二进制文件'块)和cat_target.png作为模板图像,但它没有检测到cat_target . 我认为它只检查一次匹配点的数量 .