diff --git a/matlab/external/methods/opencvDetector.py b/matlab/external/methods/opencvDetector.py new file mode 100755 index 0000000..6c171ba --- /dev/null +++ b/matlab/external/methods/opencvDetector.py @@ -0,0 +1,44 @@ +#!/usr/bin/python +# Usage: python opencvDetector.py +# Ex: python opencvDetector.py SIFT /path/to/repository/benchmark-orientation/data/Viewpoints + +import sys +import os + +if len(sys.argv) < 3: + print 'Error, missing arguments' + print 'Usage: python opencvDetector.py ' + print 'Ex: python opencvDetector.py SIFT /path/to/repository/benchmark-orientation/data/Viewpoints\n' + exit(1) + +program = 'opencvDetector' + +method = sys.argv[1] +pathDataset = sys.argv[2] + +dirImgs = 'test/image_color' +dirOut = 'test/features' + +ext = '.png' +#ext = '.jpg' + + +nameFileOut = '_' + method + '_keypoints-none-txt' + +for dir in os.listdir(pathDataset): + + if os.path.isdir(pathDataset + '/' + dir): + pathImages = pathDataset + '/' + dir + '/' + dirImgs + + for image in os.listdir(pathImages): + if os.path.isfile(pathImages + '/' + image): + pathImg = pathImages + '/' + image + nameImg = image[0:image.find(ext)] + pathFileOut = pathDataset + '/' + dir + '/' + dirOut + '/' + nameImg + nameFileOut + print program + ' ' + method + ' ' + pathImg + ' ' + pathFileOut + '\n' + # raw_input('paused') + status = os.system('./' + program + ' ' + method + ' ' + pathImg + ' ' + pathFileOut) + if status != 0: + print 'Error - status', status + exit(1) + diff --git a/matlab/src/KeypointDetectors/_SIFT/getKeypoints_SIFT.m b/matlab/src/KeypointDetectors/_SIFT/getKeypoints_SIFT.m index 2a33d02..91dfdeb 100755 --- a/matlab/src/KeypointDetectors/_SIFT/getKeypoints_SIFT.m +++ b/matlab/src/KeypointDetectors/_SIFT/getKeypoints_SIFT.m @@ -35,10 +35,30 @@ param_nameKp = p.optionalParametersKpName; out = [img_info.full_feature_prefix '_' methodName '_keypoints-' param_nameKp '-txt']; if ~exist(out, 'file') - + fprintf(['File with features does not exist: "' out '"\n']); + in = img_info.image_name; in = strrep(in, 'image_gray', 'image_color'); - opencvDetector(methodName, in, out); + try + opencvDetector(methodName, in, out); + catch + fprintf('\nCould not run "opencvDetector" directly, trying with system()...\n'); + + VENV = getenv('VIRTUAL_ENV'); + if ~strcmpi(VENV, '') + prefix = ['LD_LIBRARY_PATH=' VENV '/lib/']; + else + prefix = ['LD_LIBRARY_PATH=']; + end + com = ['(cd ../external/src/OpenCVWrapper/;' prefix '; ./opencvDetector ' methodName ' ' in ' ' out ')']; + [status, cmdout] = system(com); + + if status ~= 0 + fprintf('\n'); + error('Error when running "opencvDetector" with system(): \n%sRun "benchmark-orientation/matlab/external/methods/opencvDetector.py" python script to extract features first!\n', cmdout); + end + end + end [keypts, ~, ~] = loadFeatures(out); diff --git a/matlab/src/KeypointOrientations/GHHPooling/getOrientations_GHHPooling.m b/matlab/src/KeypointOrientations/GHHPooling/getOrientations_GHHPooling.m index 161fa61..d1c212d 100755 --- a/matlab/src/KeypointOrientations/GHHPooling/getOrientations_GHHPooling.m +++ b/matlab/src/KeypointOrientations/GHHPooling/getOrientations_GHHPooling.m @@ -104,7 +104,7 @@ % Run the python script to test and get keypoints prefix = ['LD_LIBRARY_PATH=']; end - com = ['(cd ' rootFolder '/../../learn-orientation-release/python-code/;' prefix '; OMP_NUM_THREADS=1 python runSingleTestWithFiles.py ' in_img ... + com = ['(cd ' rootFolder '/../../learn-orientation/python-code/;' prefix '; OMP_NUM_THREADS=1 python runSingleTestWithFiles.py ' in_img ... ' ' in_kp ' ' config_file_full_name ' ' out ')']; [status, result] = system(com); diff --git a/matlab/src/Utils/computeDescriptors.m b/matlab/src/Utils/computeDescriptors.m index f951764..f60f5ee 100755 --- a/matlab/src/Utils/computeDescriptors.m +++ b/matlab/src/Utils/computeDescriptors.m @@ -65,17 +65,24 @@ Allrepeatability = cell(size(combinations,1),1); for idxComb = 1:size(combinations,1) - % Check if somebody else is running - lockfile = ['.lock/' combinations{idxComb,1} '-' ... - strrep(combinations{idxComb,2},'/','-') '-' ... - num2str(combinations{idxComb,3}) '.lock']; - if exist(lockfile,'file') - continue; + if parameters.useMultithread + lockFolder = '.lock'; + if ~exist(lockFolder, 'dir') + mkdir(lockFolder); + end + + % Check if somebody else is running + lockfile = [lockFolder '/' combinations{idxComb,1} '-' ... + strrep(combinations{idxComb,2},'/','-') '-' ... + num2str(combinations{idxComb,3}) '.lock']; + if exist(lockfile,'file') + continue; + end + % Create a lock + lockfid = fopen(lockfile,'w'); + fprintf(lockfid,'Working on it\n'); + fclose(lockfid); end - % Create a lock - lockfid = fopen(lockfile,'w'); - fprintf(lockfid,'Working on it\n'); - fclose(lockfid); res = evaluateDescriptors(combinations{idxComb,1}, ... @@ -206,7 +213,9 @@ num2str(numberOfKeypoints{1})], 'res', '-v7.3'); % Release the lock - delete(lockfile); + if parameters.useMultithread && exist(lockfile,'file') + delete(lockfile); + end end end diff --git a/matlab/src/Utils/evaluateDescriptors.m b/matlab/src/Utils/evaluateDescriptors.m index 3ef2370..53852c4 100755 --- a/matlab/src/Utils/evaluateDescriptors.m +++ b/matlab/src/Utils/evaluateDescriptors.m @@ -59,7 +59,8 @@ p.trainset_name = trainset_name; p.testset_name = testset_name; p.omp_num_threads = '16'; - p.rootTest = [sRoot '/../data/' p.dataset_name '/test']; + % p.rootTest = [sRoot '/../data/' p.dataset_name '/test']; + p.rootTest = [parameters.pathDatasets '/' p.dataset_name '/test']; p.test_img_list_filename = fullfile(p.rootTest,'test_imgs.txt'); setenv('OMP_NUM_THREADS', p.omp_num_threads); diff --git a/matlab/src/run_evaluate.m b/matlab/src/run_evaluate.m index 113cf30..ad5a0c3 100644 --- a/matlab/src/run_evaluate.m +++ b/matlab/src/run_evaluate.m @@ -39,6 +39,21 @@ sRoot = strjoin(tmp,'/'); setup_path + % Allow to run script without multithreads + parameters.useMultithread = false; + + % Variable "parameters.pathDatasets" allow to store datasets out of "benchmark-orientation/data" + % Uncoment line bellow if datasets are stored out of "benchmark-orientation/data" + % parameters.pathDatasets = '/path/to/folder/data'; + + if ~isfield(parameters, 'pathDatasets') + parameters.pathDatasets = [sRoot '/../data/']; + end + + if ~exist(parameters.pathDatasets, 'dir') + error(['Directory "' parameters.pathDatasets '" does not exist. Configure variable "parameters.pathDatasets" first']); + end + % mean scale normalization applied for BRISK and ORB, as they have a % different justification for scale. We make them have about the same % scale value range as SIFT. I am bit unsure where we got this thing, @@ -110,7 +125,8 @@ parameters.parameters_dir_name = 'prelearned'; % Detectors to test - parameters.bypassDisactivateDetector = {'EdgeFociD'}; + % parameters.bypassDisactivateDetector = {'EdgeFociD'}; + parameters.bypassDisactivateDetector = {'SIFT'}; % Descriptors to test parameters.bypassDesactivateDescriptor = {'VGG', 'Daisy'}; @@ -121,7 +137,8 @@ cleanAll = 0; if cleanAll for i = 1:size(parameters.testsets,2) - where = [sRoot '/../data/' parameters.testsets{i} '/test']; + % where = [sRoot '/../data/' parameters.testsets{i} '/test']; + where = [parameters.pathDatasets '/' parameters.testsets{i} '/test']; system(['rm -r ' where '/features']); end end