我最近开始在mexopencv工作,我是新手。但是,我为ORB和SURF建立了关键点和图像特征的数据库,并将其与受过训练的匹配器一起保存在.mat文件中。
Matcher使用:
如果我在同一个脚本中训练数据并尝试从数据库中找到图像,它可以正常工作。但是,当我尝试通过加载关键点数据和匹配器在另一个脚本中从数据库中查找图像时,它会失败。
制作数据库的代码是:
%% OPTIONS
SURF_Threshold = 40000;
%% SETUP
SURF = cv.SURF('HessianThreshold', SURF_Threshold);
ORB = cv.ORB;
opts = {'KDTree', 'Trees',5}; %Dictionary required for FLANN
matcherFLANN = cv.DescriptorMatcher('FlannBasedMatcher', 'Index',opts);
matcherBF = cv.DescriptorMatcher('BruteForce-Hamming');
foldername = uigetdir;
oldFolder = cd(foldername);
files = [dir('*.jpg');dir('*.png')]; %Look for jpg files in the directory.
N = size(files,1); %numel the files
%Create empty training sets
trainDataORB = struct('name', cell(N,1), 'pts',cell(N,1), 'feat',cell(N,1));
trainDataSURF = struct('name', cell(N,1), 'pts',cell(N,1), 'feat',cell(N,1));
%% TRAINING
for i=1:N
% read image
img = imread((files(i).name));
%Extracting keypoints and descriptors (features) for both
[trainDataSURF(i).pts, trainDataSURF(i).feat] = SURF.detectAndCompute(img);
[trainDataORB(i).pts, trainDataORB(i).feat] = SURF.detectAndCompute(img);
trainDataSURF(i).name = files(i).name;
trainDataORB(i).name = files(i).name;
% add to training set to match against for each of descriptor
matcherFLANN.add(trainDataSURF(i).feat);
matcherBF.add(trainDataORB(i).feat);
end
% build index
matcherFLANN.train();
matcherBF.train();
%% SAVING DATA
%Navigate back to old folder
cd(oldFolder);
save('training_data.mat', 'matcherFLANN', 'matcherBF', 'trainDataSURF','trainDataORB');
然后在另一个脚本(带有已清除的工作空间)中加载匹配器对象:
load('training_data.mat');
返回错误:
使用DescriptorMatcher_找不到对象时出错id = 109
cv.DescriptorMatcher / match中的错误(第461行) matches = DescriptorMatcher_(this.id,'match',queryDescriptors,varargin {:});
detection_Test出错(第27行) matches = matcherFLANN.match(feat);
欢迎任何帮助。