matlab中定义sift,请问sift函数的用法

本书例程3.3-6中有调用sift函数,我想应该是MATLAB函数内部提供的函数吧?但是却运行出错,报错如下

>> mosaicTest

'siftWin32' 不是内部或外部命令,也不是可运行的程序

或批处理文件。

Error using sift (line 53)

Invalid keypoint file beginning.

Error in siftMatch (line 18)

[des1, loc1] = sift(img1);

Error in imMosaic (line 12)

[matchLoc1 matchLoc2] = siftMatch(img1, img2);

Error in mosaicTest (line 9)

img0 = imMosaic(img2,img1,1);

原出错程序打开如下:

function [descriptors, locs] = sift(img)

% If you have the Image Processing Toolbox, you can uncomment the following

%   lines to allow input of color images, which will be converted to grayscale.

%if isrgb(img)

img = rgb2gray(img);

%end

[rows, cols] = size(img);

% Convert into PGM imagefile, readable by "keypoints" executable

f = fopen('tmp.pgm', 'w');

if f == -1

error('Could not create file tmp.pgm.');

end

fprintf(f, 'P5\n%d\n%d\n255\n', cols, rows);

fwrite(f, img', 'uint8');

fclose(f);

% Call keypoints executable

if isunix

command = '!./sift ';

else

command = '!siftWin32 ';

end

command = [command ' tmp.key'];

eval(command);

% Open tmp.key and check its header

g = fopen('tmp.key', 'r');

if g == -1

error('Could not open file tmp.key.');

end

[header, count] = fscanf(g, '%d %d', [1 2]);

if count ~= 2

error('Invalid keypoint file beginning.');

end

num = header(1);

len = header(2);

if len ~= 128

error('Keypoint descriptor length invalid (should be 128).');

end

% Creates the two output matrices (use known size for efficiency)

locs = double(zeros(num, 4));

descriptors = double(zeros(num, 128));

% Parse tmp.key

for i = 1:num

[vector, count] = fscanf(g, '%f %f %f %f', [1 4]); %row col scale ori

if count ~= 4

error('Invalid keypoint file format');

end

locs(i, :) = vector(1, :);

[descrip, count] = fscanf(g, '%d', [1 len]);

if (count ~= 128)

error('Invalid keypoint file value.');

end

% Normalize each input vector to unit length

descrip = descrip / sqrt(sum(descrip.^2));

descriptors(i, :) = descrip(1, :);

end

fclose(g);

delete('tmp.pgm');

其中出错的语句是:

if count ~= 2

error('Invalid keypoint file beginning.');

end

请教一下。这个程序我是在本版块下的作者的例程来运行的,彻底没改变过啊!为什么会出错?难道我用R2013a版本的原因?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值