├── .gitignore ├── AffRANSAC.py ├── CMakeLists.txt ├── GeoEsti-train-model.py ├── IPOLcaller ├── ddl.txt ├── locate_caller.py ├── requirements.txt └── run.sh ├── LICENSE ├── README.md ├── acc-test ├── adam.1.png ├── adam.2.png ├── adam.csv ├── adam.txt ├── arc.1.png ├── arc.2.png ├── arc.csv ├── arc.txt ├── coca.1.png ├── coca.2.png ├── coca.csv ├── coca.txt ├── graf.1.png ├── graf.2.png ├── graf.csv ├── graf.txt ├── notredame.1.png ├── notredame.2.png ├── notredame.csv └── notredame.txt ├── acc_test_library.py ├── cmake ├── AddCompilerFlag.cmake ├── CheckCCompilerFlag.cmake ├── CheckCXXCompilerFlag.cmake ├── CheckMicCCompilerFlag.cmake ├── CheckMicCXXCompilerFlag.cmake └── OptimizeForArchitecture.cmake ├── cpp_libs ├── ACmatch.cpp ├── ACmatch.h ├── libMatch │ ├── CMakeLists.txt │ ├── match.cpp │ └── match.h ├── libNumerics │ ├── CMakeLists.txt │ ├── ccmath_svd.cpp │ ├── ccmath_svd_test.cpp │ ├── computeH.cpp │ ├── cubicRoots.h │ ├── cubicRoots_test.cpp │ ├── homography.cpp │ ├── homography.h │ ├── matrix.cpp │ ├── matrix.h │ ├── numerics.cpp │ ├── numerics.h │ ├── rodrigues.cpp │ ├── rodrigues.h │ └── vector.cpp ├── libOrsa │ ├── CMakeLists.txt │ ├── conditioning.cpp │ ├── conditioning.hpp │ ├── fundamental_model.cpp │ ├── fundamental_model.hpp │ ├── fundamental_model_test.cpp │ ├── fundamental_orsa_test.cpp │ ├── homography_model.cpp │ ├── homography_model.hpp │ ├── homography_model_test.cpp │ ├── homography_orsa_test.cpp │ ├── match.hpp │ ├── orsa_fundamental.cpp │ ├── orsa_fundamental.hpp │ ├── orsa_homography.cpp │ ├── orsa_homography.hpp │ ├── orsa_model.cpp │ └── orsa_model.hpp ├── libUSAC │ ├── config │ │ ├── ConfigFileReader.cpp │ │ ├── ConfigFileReader.h │ │ ├── ConfigParams.cpp │ │ ├── ConfigParams.h │ │ ├── ConfigParamsFundmatrix.cpp │ │ ├── ConfigParamsFundmatrix.h │ │ ├── ConfigParamsHomog.cpp │ │ └── ConfigParamsHomog.h │ ├── estimators │ │ ├── FundmatrixEstimator.h │ │ ├── HomogEstimator.h │ │ ├── TemplateEstimator.h │ │ └── USAC.h │ ├── fundamental.cfg │ ├── homography.cfg │ └── utils │ │ ├── FundmatrixFunctions.cpp │ │ ├── FundmatrixFunctions.h │ │ ├── HomographyFunctions.cpp │ │ ├── HomographyFunctions.h │ │ ├── MathFunctions.cpp │ │ └── MathFunctions.h └── vl │ ├── aib.c │ ├── aib.h │ ├── array.c │ ├── array.h │ ├── covdet.c │ ├── covdet.h │ ├── dsift.c │ ├── dsift.h │ ├── fisher.c │ ├── fisher.h │ ├── float.th │ ├── generic.c │ ├── generic.h │ ├── getopt_long.c │ ├── getopt_long.h │ ├── gmm.c │ ├── gmm.h │ ├── heap-def.h │ ├── hikmeans.c │ ├── hikmeans.h │ ├── hog.c │ ├── hog.h │ ├── homkermap.c │ ├── homkermap.h │ ├── host.c │ ├── host.h │ ├── ikmeans.c │ ├── ikmeans.h │ ├── ikmeans_elkan.tc │ ├── ikmeans_init.tc │ ├── ikmeans_lloyd.tc │ ├── imopv.c │ ├── imopv.h │ ├── imopv_sse2.c │ ├── imopv_sse2.h │ ├── kdtree.c │ ├── kdtree.h │ ├── kmeans.c │ ├── kmeans.h │ ├── lbp.c │ ├── lbp.h │ ├── liop.c │ ├── liop.h │ ├── mathop.c │ ├── mathop.h │ ├── mathop_avx.c │ ├── mathop_avx.h │ ├── mathop_sse2.c │ ├── mathop_sse2.h │ ├── mser.c │ ├── mser.h │ ├── pgm.c │ ├── pgm.h │ ├── qsort-def.h │ ├── quickshift.c │ ├── quickshift.h │ ├── random.c │ ├── random.h │ ├── rodrigues.c │ ├── rodrigues.h │ ├── scalespace.c │ ├── scalespace.h │ ├── shuffle-def.h │ ├── sift.c │ ├── sift.h │ ├── slic.c │ ├── slic.h │ ├── stringop.c │ ├── stringop.h │ ├── svm.c │ ├── svm.h │ ├── svmdataset.c │ ├── svmdataset.h │ ├── vlad.c │ └── vlad.h ├── hesaffnet ├── HandCraftedModules.py ├── HardNet.py ├── LAF.py ├── Losses.py ├── NMS.py ├── OnePassSIR.py ├── ReprojectionStuff.py ├── SparseImgRepresenter.py ├── Utils.py ├── architectures.py ├── extract_geomOriTh.py ├── extract_geom_and_desc_upisup.py ├── extract_geom_and_desc_upisupTh.py ├── hesaffBaum.py ├── hesaffnet.py └── pretrained │ ├── AffNet.pth │ ├── AffNetFast.caffemodel │ ├── AffNetFast.prototxt │ ├── HardNet++.pth │ ├── HardTFeat.pth │ └── OriNet.pth ├── libDA.cpp ├── libLocalDesc.py ├── library.py ├── model-data ├── model.AID_simCos_BigDesc_dropout_75.hdf5 └── model.DA_Pts_dropout_L1_75.hdf5 ├── models.py ├── py-tools ├── gen-Fig.1-WACV20.py ├── gen-Fig.4-5-WACV20.py ├── gen-GuidedMatching-Teaserimages-WACV20.py ├── gen-tables-IPOL.py ├── gen-tables-WACV20.py └── in2blocks.py └── requirements.txt /.gitignore: -------------------------------------------------------------------------------- 1 | imgs-*/ 2 | *.jpg 3 | *__pycache__/ 4 | summaries/ 5 | acc-test/*main 6 | .vscode 7 | build/ 8 | *.npz 9 | db-gen-*/ 10 | temp 11 | *.so 12 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(DeepAsift) 2 | CMAKE_MINIMUM_REQUIRED(VERSION 2.6) 3 | 4 | set(CMAKE_BUILD_TYPE Release) 5 | 6 | set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH}) 7 | 8 | # AVX does not do much benefit at the moment, but breaks compilation on some platforms. 9 | # Disabled for now until AVX becomes important enough to reconsider. 10 | SET(EMBREE_MAX_ISA "SSE4.2" CACHE STRING "Selects highest ISA to support.") 11 | set(USE_AVX FALSE CACHE BOOL "Use AVX.") 12 | set(USE_AVX2 FALSE CACHE BOOL "Use AVX2.") 13 | 14 | 15 | include(OptimizeForArchitecture) 16 | OptimizeForArchitecture() 17 | 18 | if (USE_AVX) 19 | message(STATUS "Compiling with AVX support") 20 | set(__AVX__ 1) 21 | elseif (USE_SSE4_2) 22 | message(STATUS "Compiling with SSE4.2 support") 23 | elseif (USE_SSSE3) 24 | message(STATUS "Compiling with SSE3 support") 25 | else() 26 | message(FATAL_ERROR "The target machine does not support SSE3. At least SSE3 is required") 27 | endif() 28 | 29 | foreach(flag ${Vc_ARCHITECTURE_FLAGS}) 30 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}") 31 | endforeach() 32 | message("Optimized Flags for this machine: ${CMAKE_CXX_FLAGS}") 33 | 34 | FIND_PACKAGE(OpenMP) 35 | if (OPENMP_FOUND) 36 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") 37 | endif (OPENMP_FOUND) 38 | 39 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fPIC") 40 | 41 | ADD_SUBDIRECTORY(cpp_libs) 42 | ADD_SUBDIRECTORY(cpp_libs/libNumerics) 43 | ADD_SUBDIRECTORY(cpp_libs/libOrsa) 44 | ADD_SUBDIRECTORY(cpp_libs/vl) 45 | 46 | 47 | # ACTIVATE USAC - needs libconfig and lapack 48 | set(USAC ON) 49 | set(VLFEAT ON) 50 | 51 | set(src 52 | libDA.cpp 53 | 54 | cpp_libs/ACmatch.cpp 55 | 56 | #ORSA 57 | cpp_libs/libOrsa/orsa_fundamental.cpp cpp_libs/libOrsa/conditioning.cpp 58 | cpp_libs/libOrsa/orsa_model.cpp cpp_libs/libOrsa/fundamental_model.cpp 59 | cpp_libs/libOrsa/homography_model.hpp cpp_libs/libOrsa/homography_model.cpp 60 | cpp_libs/libOrsa/orsa_homography.cpp cpp_libs/libOrsa/orsa_homography.hpp 61 | ) 62 | 63 | if (VLFEAT) 64 | SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D VL_DISABLE_AVX=1") 65 | message("************* with VLFEAT *************") 66 | set(src 67 | ${src} 68 | 69 | #affine shape adaptation 70 | cpp_libs/vl/generic.c 71 | cpp_libs/vl/covdet.c cpp_libs/vl/host.c cpp_libs/vl/random.c cpp_libs/vl/stringop.c 72 | cpp_libs/vl/scalespace.c cpp_libs/vl/imopv.c cpp_libs/vl/imopv_sse2.c 73 | cpp_libs/vl/mathop.c cpp_libs/vl/mathop_sse2.c cpp_libs/vl/mathop_avx.c 74 | cpp_libs/vl/sift.c 75 | ) 76 | include_directories(./cpp_libs/vl) 77 | endif() 78 | 79 | if (USAC) 80 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D _USAC=1") 81 | message("************* with USAC *************") 82 | set(src 83 | ${src} 84 | 85 | #USAC 86 | cpp_libs/libUSAC/config/ConfigFileReader.cpp 87 | cpp_libs/libUSAC/config/ConfigParams.cpp 88 | cpp_libs/libUSAC/config/ConfigParamsFundmatrix.cpp 89 | cpp_libs/libUSAC/config/ConfigParamsHomog.cpp 90 | cpp_libs/libUSAC/utils/FundmatrixFunctions.cpp 91 | cpp_libs/libUSAC/utils/HomographyFunctions.cpp 92 | cpp_libs/libUSAC/utils/MathFunctions.cpp 93 | ) 94 | include_directories(cpp_libs/libUSAC/config cpp_libs/libUSAC/estimators cpp_libs/libUSAC/utils) 95 | endif() 96 | 97 | include_directories(. ./cpp_libs/libOrsa) 98 | add_library(DA MODULE ${src}) 99 | TARGET_LINK_LIBRARIES(DA Numerics) 100 | if (USAC) 101 | TARGET_LINK_LIBRARIES(DA config++ lapack) 102 | endif() 103 | -------------------------------------------------------------------------------- /IPOLcaller/locate_caller.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import cv2 3 | from libLocalDesc import * 4 | from library import opt 5 | 6 | img1 = cv2.cvtColor(cv2.imread(opt.im1),cv2.COLOR_BGR2GRAY) 7 | img2 = cv2.cvtColor(cv2.imread(opt.im2),cv2.COLOR_BGR2GRAY) 8 | 9 | if opt.detector == 'HessAff': 10 | if opt.descriptor == 'AID': 11 | allmatches, good_HC, KPlist1, KPlist2, H_matrix, ET_KP, ET_M = HessAffAID(img1,img2, affmaps_method=opt.affmaps, EuPrecision=opt.precision, ransac_iters=opt.ransac_iters) 12 | elif opt.descriptor == 'HardNet': 13 | allmatches, good_HC, KPlist1, KPlist2, H_matrix, ET_KP, ET_M = HessAff_HardNet(img1,img2,HessAffNet=False, affmaps_method=opt.affmaps, EuPrecision=opt.precision, ransac_iters=opt.ransac_iters) 14 | elif opt.detector == 'SIFT': 15 | if opt.descriptor == 'AID': 16 | allmatches, good_HC, KPlist1, KPlist2, H_matrix, ET_KP, ET_M = siftAID(img1,img2, affmaps_method=opt.affmaps, EuPrecision=opt.precision, ransac_iters=opt.ransac_iters) 17 | elif opt.descriptor == 'HardNet': 18 | allmatches, good_HC, KPlist1, KPlist2, H_matrix, ET_KP, ET_M = SIFT_AffNet_HardNet(img1,img2,AffNetBeforeDesc=False,affmaps_method=opt.affmaps, EuPrecision=opt.precision, ransac_iters=opt.ransac_iters) 19 | 20 | img3 = cv2.drawMatches(img1,KPlist1,img2,KPlist2,allmatches, None,flags=2) 21 | # warped = 0.3*img2 22 | if len(good_HC)>0: 23 | print("Estimated Homography matrix :\n",H_matrix) 24 | print("%i matches out of %i are in consensus with the above homography" % (len(good_HC),len(allmatches))) 25 | h, w = img2.shape[:2] 26 | # warped = 0.7*cv2.warpPerspective(img1, H_matrix,(w, h)) + warped 27 | warped = cv2.warpPerspective(img1, H_matrix,(w, h)) 28 | 29 | 30 | cv2.imwrite(opt.workdir+'all_matches.png',img3) 31 | cv2.imwrite(opt.workdir+'queryontarget.png',warped) -------------------------------------------------------------------------------- /IPOLcaller/requirements.txt: -------------------------------------------------------------------------------- 1 | ipykernel==4.8.0 2 | ipython==6.2.1 3 | ipython-genutils==0.2.0 4 | jupyter==1.0.0 5 | jupyter-client==5.2.2 6 | jupyter-console==5.2.0 7 | jupyter-core==4.4.0 8 | Keras-Applications==1.0.8 9 | Keras-Preprocessing==1.1.0 10 | matplotlib==2.1.2 11 | nbconvert==5.3.1 12 | nbformat==4.4.0 13 | notebook==5.7.8 14 | numpy==1.18.0 15 | opencv-python==3.4.2.17 16 | opencv-contrib-python==3.4.2.17 17 | # scikit-learn==0.19.1 18 | scikit-learn 19 | scipy==1.4.1 20 | bleach==1.5.0 21 | tensorboard==1.15.0 22 | tensorflow-estimator==1.15.0 23 | # tensorflow-gpu==1.15.0 24 | psutil==5.4.5 25 | # h5py==2.7.1 26 | tqdm==4.48.2 27 | torch==1.0.1.post2 28 | torchvision==0.2.1 29 | Pillow==6.2.0 30 | seaborn==0.9.0 31 | setuptools==41.0.0 32 | -------------------------------------------------------------------------------- /IPOLcaller/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #/* 3 | # * Copyright (c) 2020, Mariano Rodriguez 4 | # * All rights reserved. 5 | # * 6 | # * This program is free software: you can use, modify and/or 7 | # * redistribute it under the terms of the GNU General Public 8 | # * License as published by the Free Software Foundation, either 9 | # * version 3 of the License, or (at your option) any later 10 | # * version. You should have received a copy of this license along 11 | # * this program. If not, see . 12 | # */ 13 | 14 | set -e 15 | 16 | virtualenv=$1 17 | demoextrasfolder=$2 18 | binfolder=$3 19 | input0="input_0.png" 20 | input1="input_1.png" 21 | gfilter=$4 22 | aid_thres=$5 23 | hardnet_thres=$6 24 | detector=$7 25 | descriptor=$8 26 | ransac_iters=$9 27 | precision=${10} 28 | 29 | 30 | # Workaround for IPOL ! 31 | if [ -d $virtualenv ]; then 32 | source $virtualenv/bin/activate 33 | if python -c "import tensorflow" &> /dev/null; then 34 | TFv="`pip list | grep tensorflow | tail -n 1`" 35 | # echo "$TFv" 36 | else 37 | echo 'Installing tensorflow...' 38 | pip install --upgrade pip 39 | pip install --upgrade setuptools 40 | pip install --upgrade tensorflow==1.15.0 tensorflow-estimator==1.15.1 41 | pip install --upgrade h5py==2.7.1 42 | fi 43 | fi 44 | 45 | # echo "$virtualenv" 46 | # echo "$binfolder" 47 | # pwd 48 | 49 | # ls -al $binfolder 50 | # ls -al 51 | 52 | locate_caller.py --im1 $input0 --im2 $input1 --gfilter $gfilter --aid_thres $aid_thres --hardnet_thres $hardnet_thres --detector $detector --descriptor $descriptor --workdir "./" --bindir $binfolder --visual --ransac_iters $ransac_iters --precision $precision 53 | 54 | # ls -al 55 | 56 | 57 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Mariano Rodriguez 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /acc-test/adam.1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rdguez-mariano/locate/599e9e1400b74c07091e29c932b625c3c0237000/acc-test/adam.1.png -------------------------------------------------------------------------------- /acc-test/adam.2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rdguez-mariano/locate/599e9e1400b74c07091e29c932b625c3c0237000/acc-test/adam.2.png -------------------------------------------------------------------------------- /acc-test/adam.txt: -------------------------------------------------------------------------------- 1 | 0.225707 -0.0112307 150.307 2 | -0.118863 0.627155 64.8939 3 | -0.000647084 1.02633e-05 1 4 | -------------------------------------------------------------------------------- /acc-test/arc.1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rdguez-mariano/locate/599e9e1400b74c07091e29c932b625c3c0237000/acc-test/arc.1.png -------------------------------------------------------------------------------- /acc-test/arc.2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rdguez-mariano/locate/599e9e1400b74c07091e29c932b625c3c0237000/acc-test/arc.2.png -------------------------------------------------------------------------------- /acc-test/arc.txt: -------------------------------------------------------------------------------- 1 | 0.343201 -0.0665513 50.5381 2 | -0.351634 0.767968 189.169 3 | -0.000654298 -4.6168e-05 1 4 | -------------------------------------------------------------------------------- /acc-test/coca.1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rdguez-mariano/locate/599e9e1400b74c07091e29c932b625c3c0237000/acc-test/coca.1.png -------------------------------------------------------------------------------- /acc-test/coca.2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rdguez-mariano/locate/599e9e1400b74c07091e29c932b625c3c0237000/acc-test/coca.2.png -------------------------------------------------------------------------------- /acc-test/coca.txt: -------------------------------------------------------------------------------- 1 | 0.779185 0.0221974 63.5547 2 | -0.230052 1.0215 83.4931 3 | -0.000321057 0.000238745 1 4 | -------------------------------------------------------------------------------- /acc-test/graf.1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rdguez-mariano/locate/599e9e1400b74c07091e29c932b625c3c0237000/acc-test/graf.1.png -------------------------------------------------------------------------------- /acc-test/graf.2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rdguez-mariano/locate/599e9e1400b74c07091e29c932b625c3c0237000/acc-test/graf.2.png -------------------------------------------------------------------------------- /acc-test/graf.txt: -------------------------------------------------------------------------------- 1 | 0.437633 -0.676111 455.782 2 | 0.447416 1.01279 -51.1117 3 | 0.000539398 -9.51134e-05 1 4 | -------------------------------------------------------------------------------- /acc-test/notredame.1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rdguez-mariano/locate/599e9e1400b74c07091e29c932b625c3c0237000/acc-test/notredame.1.png -------------------------------------------------------------------------------- /acc-test/notredame.2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rdguez-mariano/locate/599e9e1400b74c07091e29c932b625c3c0237000/acc-test/notredame.2.png -------------------------------------------------------------------------------- /acc-test/notredame.csv: -------------------------------------------------------------------------------- 1 | x1, y1, sigma1, angle1, t1_x, t1_y, theta1, x2, y2, sigma2, angle2, t2_x, t2_y, theta2, distance 2 | 490.491,371.845,5.15915,1.22292,1,2.61757,136.833,477.148,287.752,2.66778,1.15485,1,2.61757,136.833,9.38896 3 | 554.286,102,4.07074,1.29773,1,5.18168,124.988,543.407,50.6457,4.10839,1.03652,1,2.61757,114.028,9.65315 4 | 245.006,159.537,5.36273,-1.93522,1,2.61757,159.639,347.002,175.434,2.67812,-2.02473,1,5.18168,170.438,7.23481 5 | 61.0664,319.505,5.05851,-1.84091,1,1,0,289.694,282.813,2.35107,1.88462,1,2.61757,114.028,11.2665 6 | 273.242,118.639,20.1808,0.358259,1,1,0,359.174,141.323,10.4406,0.260339,1,1,0,9.58288 7 | 304.582,201.98,4.90299,0.248326,1,2.61757,91.2222,376.54,197.47,2.50303,0.408751,1,2.61757,68.4167,8.34484 8 | 553.02,419.446,2.73113,-2.09856,1,2.61757,136.833,513.261,316.002,2.01375,-2.10153,1,2.61757,136.833,9.63216 9 | 354.79,200.035,4.84102,1.3588,1,2.61757,91.2222,404.528,186.309,2.6555,1.48967,1,2.61757,68.4167,8.35188 10 | 252.23,250.563,8.75138,-1.50576,1,2.61757,114.028,357.67,232.023,4.06418,-1.55297,1,5.18168,124.988,7.62239 11 | 412.894,416.84,5.24819,0.382025,1,2.61757,136.833,432.64,320.242,2.56786,0.322029,1,2.61757,136.833,10.9468 12 | 524.382,405.529,2.05867,0.831436,1,2.61757,114.028,492.851,309.146,2.09207,1.0085,1,2.61757,114.028,9.34 13 | 457.156,145.596,4.36443,2.28199,1,2.61757,22.8056,468.184,124.443,4.13885,2.3013,1,2.61757,22.8056,7.94314 14 | 260.671,206.024,8.29974,-1.55109,1,5.18168,124.988,354.157,202.922,4.04477,-1.54431,1,5.18168,124.988,6.84932 15 | 533.016,377.224,4.95003,2.33376,1,2.61757,159.639,498.855,289.43,2.56769,2.28972,1,2.61757,159.639,8.16853 16 | 269.682,110.484,10.904,0.746583,1,2.61757,0,357.178,140.117,6.10462,0.745392,1,2.61757,0,8.64561 17 | 67.9442,320.956,2.56926,1.45012,1,2.61757,159.639,289.694,282.813,2.35107,1.88462,1,2.61757,114.028,7.33218 18 | 514.718,414.865,5.18288,0.852976,1,2.61757,136.833,491.232,317.257,2.65484,0.715511,1,2.61757,136.833,10.0112 19 | 461.077,197.417,2.52479,1.34428,1,5.18168,79.5379,460.103,171.314,4.76601,1.46754,1,2.61757,45.6111,8.47016 20 | 354.72,243.272,4.96741,1.34805,1,5.18168,124.988,405.95,221.415,2.65643,1.21718,1,5.18168,124.988,7.24 21 | 459.308,428.942,2.60667,-1.70457,1,2.61757,114.028,453.234,323.651,2.06417,-1.72674,1,2.61757,114.028,8.97341 22 | 225.538,233.258,5.25058,-1.98463,1,2.61757,159.639,343.331,230.66,2.66688,-2.15026,1,2.61757,159.639,6.48737 23 | 529.204,224.606,2.04799,-0.347067,1,5.18168,0,506.118,184.374,2.06733,0.116757,1,2.61757,0,8.89636 24 | 229.587,128.301,10.7021,-2.02012,1,2.61757,159.639,339.524,148.635,5.3079,-2.03967,1,5.18168,170.438,8.01502 25 | 527.594,213.821,2.12364,-0.94358,1,2.61757,22.8056,505.107,163.055,2.3488,-1.15774,1,2.61757,45.6111,8.0875 26 | 426.377,97.1695,8.07431,0.102782,1,1,0,444.78,76.7781,2.62429,-1.27099,1,2.61757,68.4167,7.95993 27 | 369.056,447.431,2.57958,1.5563,1,1,0,408.535,336.598,2.45654,1.5446,1,1,0,10.7851 28 | 542.328,89.1427,2.06307,1.30109,1,2.61757,114.028,542.68,44.3072,4.10581,1.4655,1,2.61757,68.4167,8.62839 29 | 280.859,132.442,3.96998,2.69912,1,5.18168,11.3626,368.325,146.008,2.06976,2.90922,1,5.18168,0,10.9756 30 | 255.796,76.2326,2.55362,0.551787,1,2.61757,0,346.724,122.732,2.4811,0.214601,1,1,0,8.4607 31 | 533.969,151.14,2.06419,-2.089,1,2.61757,136.833,516.375,99.6626,5.37513,-0.117987,1,1,0,10.0904 32 | 276.264,140.189,2.03142,-1.54728,1,5.18168,0,361.861,166.483,2.04545,-1.6954,1,2.61757,0,9.80475 33 | 511.786,384.387,5.93218,-1.25477,1,1,0,483.896,288.553,2.79932,-1.30613,1,1,0,7.37915 34 | 554.789,337.106,1.97385,-1.51614,1,2.61757,114.028,529.944,256.71,2.10011,-1.16134,1,5.18168,90.9004,9.71495 35 | 370.022,66.9451,4.10084,1.01937,1,2.61757,114.028,413.535,84.606,2.06208,1.30962,1,2.61757,68.4167,9.65407 36 | 547.385,190.608,2.46638,1.47879,1,5.18168,79.5379,538.595,143.444,5.20951,1.56931,1,5.18168,68.1753,8.7262 37 | 470.312,102.347,5.15591,-3.09386,1,2.61757,0,480.744,90.7997,4.7454,2.99116,1,2.61757,0,8.20519 38 | 509.7,37.3688,2.61365,2.3983,1,1,0,513.663,10.4383,2.35267,2.44206,1,1,0,8.06044 39 | 515.802,186.606,2.37956,0.901705,1,2.61757,136.833,491.736,151.762,2.47686,0.823946,1,2.61757,136.833,9.82557 40 | 235.005,228.758,2.7088,-1.55987,1,5.18168,113.626,344.212,231.428,2.67052,-1.83797,1,2.61757,136.833,6.90369 41 | 338.755,386.599,19.5257,1.42813,1,2.61757,159.639,399.041,313.308,10.3258,1.58984,1,2.61757,159.639,7.26177 42 | 544.72,328.767,4.71252,-1.6824,1,2.61757,114.028,505.435,247.682,4.6996,-1.57953,1,5.18168,102.263,9.16651 43 | 256.135,173.965,3.9533,-1.35405,1,5.18168,113.626,346.234,176.788,2.66814,-1.70081,1,5.18168,159.076,8.31118 44 | 533.74,394.8,2.80559,2.84014,1,5.18168,136.351,496.85,290.532,1.95622,2.88438,1,5.18168,136.351,11.2448 45 | 520.583,333.671,4.67936,-1.39024,1,5.18168,113.626,505.435,247.682,4.6996,-1.57953,1,5.18168,102.263,9.18819 46 | 366.566,312.819,4.67219,-1.62756,1,1,0,401.519,256.663,2.35148,-2.78699,1,2.61757,68.4167,9.37296 47 | 264.592,254.67,5.05061,1.13903,1,5.18168,159.076,363.04,245.883,2.60402,1.19095,1,2.61757,114.028,6.76258 48 | 226.227,272.928,2.07916,-0.667175,1,5.18168,22.7251,342.535,236.631,2.47157,-1.02473,1,2.61757,45.6111,7.59787 49 | 79.261,336.05,2.64287,-1.05488,1,2.61757,159.639,303.895,289.268,2.20004,-0.603881,1,2.61757,114.028,8.8487 50 | -------------------------------------------------------------------------------- /acc-test/notredame.txt: -------------------------------------------------------------------------------- 1 | 0.108392 0.250854 245.404 2 | -0.28619 0.696934 118.331 3 | -0.00082018 0.000610115 1 4 | -------------------------------------------------------------------------------- /cmake/CheckCCompilerFlag.cmake: -------------------------------------------------------------------------------- 1 | # - Check whether the C compiler supports a given flag. 2 | # CHECK_C_COMPILER_FLAG( ) 3 | # - the compiler flag 4 | # - variable to store the result 5 | # This internally calls the check_c_source_compiles macro. 6 | # See help for CheckCSourceCompiles for a listing of variables 7 | # that can modify the build. 8 | 9 | #============================================================================= 10 | # Copyright 2006-2009 Kitware, Inc. 11 | # Copyright 2006 Alexander Neundorf 12 | # Copyright 2011-2013 Matthias Kretz 13 | # 14 | # Redistribution and use in source and binary forms, with or without 15 | # modification, are permitted provided that the following conditions are 16 | # met: 17 | # 18 | # * Redistributions of source code must retain the above copyright notice, 19 | # this list of conditions and the following disclaimer. 20 | # 21 | # * Redistributions in binary form must reproduce the above copyright notice, 22 | # this list of conditions and the following disclaimer in the documentation 23 | # and/or other materials provided with the distribution. 24 | # 25 | # * The names of Kitware, Inc., the Insight Consortium, or the names of 26 | # any consortium members, or of any contributors, may not be used to 27 | # endorse or promote products derived from this software without 28 | # specific prior written permission. 29 | # 30 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS'' 31 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 32 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 33 | # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR 34 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 35 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 36 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 37 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 38 | # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 39 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 40 | #============================================================================= 41 | 42 | INCLUDE(CheckCSourceCompiles) 43 | 44 | MACRO (CHECK_C_COMPILER_FLAG _FLAG _RESULT) 45 | SET(SAFE_CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS}") 46 | SET(CMAKE_REQUIRED_DEFINITIONS "${_FLAG}") 47 | if(${ARGC} GREATER 2) 48 | SET(TEST_SOURCE "${ARGV2}") 49 | else() 50 | SET(TEST_SOURCE "int main() { return 0;}") 51 | endif() 52 | CHECK_C_SOURCE_COMPILES("${TEST_SOURCE}" ${_RESULT} 53 | # Some compilers do not fail with a bad flag 54 | FAIL_REGEX "error: bad value (.*) for .* switch" # GNU 55 | FAIL_REGEX "argument unused during compilation" # clang 56 | FAIL_REGEX "is valid for .* but not for C" # GNU 57 | FAIL_REGEX "unrecognized .*option" # GNU 58 | FAIL_REGEX "ignored for target" # GNU 59 | FAIL_REGEX "ignoring unknown option" # MSVC 60 | FAIL_REGEX "warning D9002" # MSVC 61 | FAIL_REGEX "[Uu]nknown option" # HP 62 | FAIL_REGEX "[Ww]arning: [Oo]ption" # SunPro 63 | FAIL_REGEX "command option .* is not recognized" # XL 64 | FAIL_REGEX "WARNING: unknown flag:" # Open64 65 | FAIL_REGEX "command line error" # ICC 66 | FAIL_REGEX "command line warning" # ICC 67 | FAIL_REGEX "#10236:" # ICC: File not found 68 | FAIL_REGEX " #10159: " # ICC 69 | FAIL_REGEX " #10353: " # ICC: option '-mfma' ignored, suggest using '-march=core-avx2' 70 | ) 71 | SET (CMAKE_REQUIRED_DEFINITIONS "${SAFE_CMAKE_REQUIRED_DEFINITIONS}") 72 | ENDMACRO (CHECK_C_COMPILER_FLAG) 73 | 74 | -------------------------------------------------------------------------------- /cmake/CheckCXXCompilerFlag.cmake: -------------------------------------------------------------------------------- 1 | # - Check whether the CXX compiler supports a given flag. 2 | # CHECK_CXX_COMPILER_FLAG( ) 3 | # - the compiler flag 4 | # - variable to store the result 5 | # This internally calls the check_cxx_source_compiles macro. See help 6 | # for CheckCXXSourceCompiles for a listing of variables that can 7 | # modify the build. 8 | 9 | #============================================================================= 10 | # Copyright 2006-2009 Kitware, Inc. 11 | # Copyright 2006 Alexander Neundorf 12 | # Copyright 2011-2013 Matthias Kretz 13 | # 14 | # Redistribution and use in source and binary forms, with or without 15 | # modification, are permitted provided that the following conditions are 16 | # met: 17 | # 18 | # * Redistributions of source code must retain the above copyright notice, 19 | # this list of conditions and the following disclaimer. 20 | # 21 | # * Redistributions in binary form must reproduce the above copyright notice, 22 | # this list of conditions and the following disclaimer in the documentation 23 | # and/or other materials provided with the distribution. 24 | # 25 | # * The names of Kitware, Inc., the Insight Consortium, or the names of 26 | # any consortium members, or of any contributors, may not be used to 27 | # endorse or promote products derived from this software without 28 | # specific prior written permission. 29 | # 30 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS'' 31 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 32 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 33 | # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR 34 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 35 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 36 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 37 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 38 | # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 39 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 40 | #============================================================================= 41 | 42 | INCLUDE(CheckCXXSourceCompiles) 43 | 44 | MACRO (CHECK_CXX_COMPILER_FLAG _FLAG _RESULT) 45 | SET(SAFE_CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS}") 46 | SET(CMAKE_REQUIRED_DEFINITIONS "${_FLAG}") 47 | if(${ARGC} GREATER 2) 48 | SET(TEST_SOURCE "${ARGV2}") 49 | else() 50 | SET(TEST_SOURCE "int main() { return 0;}") 51 | endif() 52 | CHECK_CXX_SOURCE_COMPILES("${TEST_SOURCE}" ${_RESULT} 53 | # Some compilers do not fail with a bad flag 54 | FAIL_REGEX "error: bad value (.*) for .* switch" # GNU 55 | FAIL_REGEX "argument unused during compilation" # clang 56 | FAIL_REGEX "is valid for .* but not for C\\\\+\\\\+" # GNU 57 | FAIL_REGEX "unrecognized .*option" # GNU 58 | FAIL_REGEX "ignored for target" # GNU 59 | FAIL_REGEX "ignoring unknown option" # MSVC 60 | FAIL_REGEX "warning D9002" # MSVC 61 | FAIL_REGEX "[Uu]nknown option" # HP 62 | FAIL_REGEX "[Ww]arning: [Oo]ption" # SunPro 63 | FAIL_REGEX "command option .* is not recognized" # XL 64 | FAIL_REGEX "WARNING: unknown flag:" # Open64 65 | FAIL_REGEX "command line error" # ICC 66 | FAIL_REGEX "command line warning" # ICC 67 | FAIL_REGEX "#10236:" # ICC: File not found 68 | FAIL_REGEX " #10159: " # ICC 69 | FAIL_REGEX " #10353: " # ICC: option '-mfma' ignored, suggest using '-march=core-avx2' 70 | ) 71 | SET (CMAKE_REQUIRED_DEFINITIONS "${SAFE_CMAKE_REQUIRED_DEFINITIONS}") 72 | ENDMACRO (CHECK_CXX_COMPILER_FLAG) 73 | 74 | -------------------------------------------------------------------------------- /cmake/CheckMicCCompilerFlag.cmake: -------------------------------------------------------------------------------- 1 | # - Check whether the MIC C compiler supports a given flag. 2 | # CHECK_MIC_C_COMPILER_FLAG( ) 3 | # - the compiler flag 4 | # - variable to store the result 5 | # This internally calls the check_c_source_compiles macro. See help 6 | # for CheckCSourceCompiles for a listing of variables that can 7 | # modify the build. 8 | 9 | #============================================================================= 10 | # Copyright 2006-2009 Kitware, Inc. 11 | # Copyright 2006 Alexander Neundorf 12 | # Copyright 2011-2013 Matthias Kretz 13 | # 14 | # Redistribution and use in source and binary forms, with or without 15 | # modification, are permitted provided that the following conditions are 16 | # met: 17 | # 18 | # * Redistributions of source code must retain the above copyright notice, 19 | # this list of conditions and the following disclaimer. 20 | # 21 | # * Redistributions in binary form must reproduce the above copyright notice, 22 | # this list of conditions and the following disclaimer in the documentation 23 | # and/or other materials provided with the distribution. 24 | # 25 | # * The names of Kitware, Inc., the Insight Consortium, or the names of 26 | # any consortium members, or of any contributors, may not be used to 27 | # endorse or promote products derived from this software without 28 | # specific prior written permission. 29 | # 30 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS'' 31 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 32 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 33 | # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR 34 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 35 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 36 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 37 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 38 | # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 39 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 40 | #============================================================================= 41 | 42 | macro(check_mic_c_compiler_flag _FLAG _RESULT) 43 | if(NOT DEFINED "${_RESULT}") 44 | set(_tmpdir "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp") 45 | if(${ARGC} GREATER 2) 46 | file(WRITE "${_tmpdir}/src.c" "${ARGV2}") 47 | else() 48 | file(WRITE "${_tmpdir}/src.c" "int main() { return 0; }") 49 | endif() 50 | 51 | execute_process( 52 | COMMAND "${MIC_CC}" -mmic -c -o "${_tmpdir}/src.o" 53 | "${_FLAG}" "${_tmpdir}/src.c" 54 | WORKING_DIRECTORY ${CMAKE_BINARY_DIR} 55 | RESULT_VARIABLE ${_RESULT} 56 | OUTPUT_VARIABLE OUTPUT 57 | ERROR_VARIABLE OUTPUT 58 | ) 59 | 60 | if(${_RESULT} EQUAL 0) 61 | foreach(_fail_regex 62 | "error: bad value (.*) for .* switch" # GNU 63 | "argument unused during compilation" # clang 64 | "is valid for .* but not for C" # GNU 65 | "unrecognized .*option" # GNU 66 | "ignored for target" # GNU 67 | "ignoring unknown option" # MSVC 68 | "[Uu]nknown option" # HP 69 | "[Ww]arning: [Oo]ption" # SunPro 70 | "command option .* is not recognized" # XL 71 | "WARNING: unknown flag:" # Open64 72 | "command line error" # ICC 73 | "command line warning" # ICC 74 | "#10236:" # ICC: File not found 75 | ) 76 | if("${OUTPUT}" MATCHES "${_fail_regex}") 77 | set(${_RESULT} 1) 78 | endif() 79 | endforeach() 80 | endif() 81 | 82 | if(${_RESULT} EQUAL 0) 83 | set(${_RESULT} 1 CACHE INTERNAL "Test ${_FLAG}") 84 | message(STATUS "Performing Test Check MIC C Compiler flag ${_FLAG} - Success") 85 | file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log 86 | "Performing MIC C Compiler Flag Test ${_FLAG} succeded with the following output:\n" 87 | "${OUTPUT}\n" 88 | "COMMAND: ${MIC_CC} -mmic -c -o ${_tmpdir}/src.o ${_FLAG} ${_tmpdir}/src.cpp\n" 89 | ) 90 | else() 91 | message(STATUS "Performing Test Check MIC C Compiler flag ${_FLAG} - Failed") 92 | set(${_RESULT} "" CACHE INTERNAL "Test ${_FLAG}") 93 | file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log 94 | "Performing MIC C Compiler Flag Test ${_FLAG} failed with the following output:\n" 95 | "${OUTPUT}\n" 96 | "COMMAND: ${MIC_CC} -mmic -c -o ${_tmpdir}/src.o ${_FLAG} ${_tmpdir}/src.cpp\n" 97 | ) 98 | endif() 99 | endif() 100 | endmacro() 101 | 102 | -------------------------------------------------------------------------------- /cpp_libs/ACmatch.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @authors Rafael Grompone von Gioi, Mariano Rodríguez 3 | */ 4 | 5 | /*----------------------------------------------------------------------------*/ 6 | 7 | #ifndef _CLIB_ACmatch_H_ 8 | #define _CLIB_ACmatch_H_ 9 | 10 | /*----------------------------------------------------------------------------*/ 11 | /** max value */ 12 | #define max(a,b) (((a)>(b))?(a):(b)) 13 | 14 | /** min value */ 15 | #define min(a,b) (((a)>(b))?(b):(a)) 16 | 17 | float * gradient_angle(float * image, int X, int Y, float ** modgrad); 18 | 19 | static inline float norm_angle(float a, float b); 20 | 21 | float patch_comparison( float * grad_angle1, float * grad_angle2, 22 | int X, int Y, float logNT ); 23 | 24 | 25 | 26 | 27 | void create_weights_for_patch_comparison(int X, int Y); 28 | 29 | float weighted_patch_comparison( float * grad_angle1, float * grad_angle2, 30 | float * grad_mod1, float * grad_mod2, 31 | int X, int Y, float logNT ); 32 | 33 | 34 | float nfa(float logNT, int n, int k, float p); 35 | 36 | 37 | float quantised_patch_comparison( float * grad_angle1, float * grad_angle2, 38 | float * grad_mod1, float * grad_mod2, 39 | int X, int Y, float logNT ); 40 | 41 | 42 | #endif 43 | 44 | -------------------------------------------------------------------------------- /cpp_libs/libMatch/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | CMAKE_MINIMUM_REQUIRED(VERSION 2.6) 2 | 3 | PROJECT(libMatch) 4 | 5 | ADD_LIBRARY(Match 6 | match.cpp match.h) 7 | -------------------------------------------------------------------------------- /cpp_libs/libMatch/match.cpp: -------------------------------------------------------------------------------- 1 | // Authors: Unknown. Please, if you are the author of this file, or if you 2 | // know who are the authors of this file, let us know, so we can give the 3 | // adequate credits and/or get the adequate authorizations. 4 | 5 | #include "match.h" 6 | #include 7 | #include 8 | 9 | bool loadMatch(const char* nameFile, std::vector& match) { 10 | match.clear(); 11 | std::ifstream f(nameFile); 12 | while( f.good() ) { 13 | std::string str; 14 | std::getline(f, str); 15 | if( f.good() ) { 16 | std::istringstream s(str); 17 | Match m; 18 | s >> m.x1 >> m.y1 >> m.x2 >> m.y2; 19 | if(!s.fail() ) 20 | match.push_back(m); 21 | } 22 | } 23 | return !match.empty(); 24 | } 25 | 26 | bool saveMatch(const char* nameFile, const std::vector& match) { 27 | std::ofstream f(nameFile); 28 | if( f.is_open() ) { 29 | std::vector::const_iterator it = match.begin(); 30 | for(; it != match.end(); ++it) 31 | f << it->x1 << " " << it->y1 << " " 32 | << it->x2 << " " << it->y2 << std::endl; 33 | } 34 | return f.is_open(); 35 | } 36 | -------------------------------------------------------------------------------- /cpp_libs/libMatch/match.h: -------------------------------------------------------------------------------- 1 | // Authors: Unknown. Please, if you are the author of this file, or if you 2 | // know who are the authors of this file, let us know, so we can give the 3 | // adequate credits and/or get the adequate authorizations. 4 | 5 | #ifndef MATCH_H 6 | #define MATCH_H 7 | 8 | #include 9 | 10 | struct Match { 11 | float x1, y1, x2, y2; 12 | }; 13 | 14 | bool loadMatch(const char* nameFile, std::vector& match); 15 | bool saveMatch(const char* nameFile, const std::vector& match); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /cpp_libs/libNumerics/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | CMAKE_MINIMUM_REQUIRED(VERSION 2.6) 2 | 3 | PROJECT(libNumerics) 4 | 5 | INCLUDE_DIRECTORIES(..) 6 | 7 | ADD_LIBRARY(Numerics 8 | computeH.cpp 9 | homography.cpp homography.h 10 | matrix.cpp matrix.h 11 | numerics.cpp numerics.h 12 | rodrigues.cpp rodrigues.h 13 | vector.cpp 14 | cubicRoots.h 15 | ccmath_svd.cpp 16 | ) 17 | -------------------------------------------------------------------------------- /cpp_libs/libNumerics/ccmath_svd_test.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file cc_math_svd_test.cpp 3 | * @brief SVD test 4 | * @author Pascal Monasse 5 | * 6 | * Copyright (c) 2010 Pascal Monasse 7 | * All rights reserved. 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | #include "numerics.h" 24 | #include "CppUnitLite/TestHarness.h" 25 | 26 | static const int NTESTS=100; 27 | static const double EPS=1E-5; 28 | 29 | #define EXPECT_MATRIX_NEAR(a, b, tolerance) \ 30 | do { \ 31 | bool dims_match = (a.nrow() == b.nrow()) && (a.ncol() == b.ncol()); \ 32 | CHECK_EQUAL(a.nrow(),b.nrow()); \ 33 | CHECK_EQUAL(a.ncol(),b.ncol()); \ 34 | if (dims_match) { \ 35 | for (int r = 0; r < a.nrow(); ++r) { \ 36 | for (int c = 0; c < a.ncol(); ++c) { \ 37 | DOUBLES_EQUAL(a(r, c), b(r, c), tolerance); \ 38 | } \ 39 | } \ 40 | } \ 41 | } while(false); 42 | 43 | static double max(const libNumerics::matrix& A) { 44 | double m = A(0,0); 45 | for(int i=0; im) 49 | m = abs; 50 | } 51 | return m; 52 | } 53 | 54 | TEST(SVDTest, Decomposition) { 55 | //------------------------// 56 | //-- Unit test Objective--// 57 | //------------------------// 58 | // Test SVD decomposition 59 | //-- 60 | //-- 61 | 62 | for(int k=0; k A(m,n); 66 | for(int i=0; i B=svd.compose(); 71 | double err = max(A-B); 72 | std::cout << k << ": " << m << 'x' << n << " " << err << std::endl; 73 | if(err > EPS) { 74 | std::cout << "A=" << A << std::endl; 75 | std::cout << "U=" << svd.U << std::endl; 76 | std::cout << "D=" << svd.D << std::endl; 77 | std::cout << "V=" << svd.V << std::endl; 78 | } 79 | EXPECT_MATRIX_NEAR(A, B, EPS); 80 | } 81 | } 82 | 83 | /* ************************************************************************* */ 84 | int main() { TestResult tr; return TestRegistry::runAllTests(tr);} 85 | /* ************************************************************************* */ 86 | -------------------------------------------------------------------------------- /cpp_libs/libNumerics/cubicRoots.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file cubicRoots.h 3 | * @brief Find roots of a cubic polynomial 4 | * @author Pascal Monasse 5 | * 6 | * Copyright (c) 2015 Pascal Monasse 7 | * All rights reserved. 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | #ifndef CUBICROOTS_H_ 24 | #define CUBICROOTS_H_ 25 | 26 | #define _USE_MATH_DEFINES //For Windows (M_PI) 27 | #include 28 | #include 29 | 30 | namespace orsa { 31 | 32 | /// Find roots of the cubic polynomial 33 | /// \f[ x^3 + a*x^2 + b*x + c = 0. \f] 34 | /// The number of roots is returned. 35 | template 36 | int SolveCubicPolynomial(Real a, Real b, Real c, Real x[3]) { 37 | const Real eps = std::numeric_limits::epsilon(); 38 | a /= 3; 39 | Real p = (b-3*a*a)/3; 40 | Real q = (2*a*a*a - a*b + c)/2; 41 | Real d = q*q+p*p*p; 42 | Real tolq = std::max(std::abs(2*a*a*a),std::max(std::abs(a*b),std::abs(c))); 43 | Real tolp = std::max(std::abs(b),std::abs(3*a*a)); 44 | int n = (d>eps*std::max(p*p*tolp,std::abs(q)*tolq)? 1: 3); 45 | if(n==1) { // Single root: Cardano's formula 46 | d = std::pow(std::abs(q)+std::sqrt(d), 1/(Real)3); 47 | x[0] = d - p/d; 48 | if(q>0) 49 | x[0] = -x[0]; 50 | } else { // Three roots: Viete's formula 51 | if(3*p>=-eps*tolp) { // p=0 and d<=0 implies q=0: triple root 0 52 | n = 1; 53 | x[0] = 0; 54 | } else { 55 | p = std::sqrt(-p); 56 | q /= p*p*p; 57 | d = Real((q<=-1)? M_PI: (q>=1)? 0: std::acos(q)); 58 | for(int i=0; i<3; i++) 59 | x[i] = Real(-2*p*std::cos((d+2*M_PI*i)/3)); 60 | } 61 | } 62 | for(int i=0; i 73 | int CubicRoots(const Real coeffs[4], Real roots[3]) { 74 | if(coeffs[0] == 0.0) 75 | return 0; 76 | Real a = coeffs[2] / coeffs[3]; 77 | Real b = coeffs[1] / coeffs[3]; 78 | Real c = coeffs[0] / coeffs[3]; 79 | return SolveCubicPolynomial(a, b, c, roots); 80 | } 81 | 82 | } // namespace orsa 83 | 84 | #endif // LIBS_NUMERIC_POLY_H_ 85 | -------------------------------------------------------------------------------- /cpp_libs/libNumerics/homography.cpp: -------------------------------------------------------------------------------- 1 | // Authors: Unknown. Please, if you are the author of this file, or if you 2 | // know who are the authors of this file, let us know, so we can give the 3 | // adequate credits and/or get the adequate authorizations. 4 | 5 | #include "homography.h" 6 | 7 | namespace libNumerics { 8 | 9 | /// Constructor. 10 | Homography::Homography() 11 | : m_H( matrix::eye(3) ) 12 | {} 13 | 14 | /// Put to identity. 15 | void Homography::setId() 16 | { 17 | m_H = matrix::eye(3); 18 | } 19 | 20 | /// Set to translation. 21 | void Homography::setTrans(double dx, double dy) 22 | { 23 | setId(); 24 | m_H(0,2) = dx; 25 | m_H(1,2) = dy; 26 | } 27 | 28 | /// Set to zoom. 29 | void Homography::setZoom(double zx, double zy) 30 | { 31 | setId(); 32 | m_H(0,0) = zx; 33 | m_H(1,1) = zy; 34 | } 35 | 36 | /// Apply homography. 37 | void Homography::operator()(double& x, double& y) const 38 | { 39 | vector m(3); 40 | m(0) = x; 41 | m(1) = y; 42 | m(2) = 1.0f; 43 | m = m_H * m; 44 | double z_1 = 1.0 / m(2); 45 | x = m(0) * z_1; 46 | y = m(1) * z_1; 47 | } 48 | 49 | /// Compose homographies. 50 | Homography Homography::operator*(const Homography& rhs) const 51 | { 52 | Homography h; 53 | h.m_H = m_H * rhs.m_H; 54 | h.normalize(); 55 | return h; 56 | } 57 | 58 | /// Inverse homography. 59 | Homography Homography::inverse() const 60 | { 61 | Homography h; 62 | h.m_H = m_H.inv(); 63 | h.normalize(); 64 | return h; 65 | } 66 | 67 | /// Put coef(2,2) to 1. 68 | void Homography::normalize() 69 | { 70 | m_H /= m_H(2,2); 71 | } 72 | 73 | } // libNumerics 74 | -------------------------------------------------------------------------------- /cpp_libs/libNumerics/homography.h: -------------------------------------------------------------------------------- 1 | #ifndef HOMOGRAPHY_H 2 | #define HOMOGRAPHY_H 3 | 4 | #include "matrix.h" 5 | 6 | namespace libNumerics { 7 | 8 | /// 2-D homography transform. 9 | class Homography { 10 | public: 11 | Homography(); 12 | 13 | void setId(); 14 | void setTrans(double dx, double dy); 15 | void setZoom(double zx, double zy); 16 | 17 | matrix& mat() { return m_H; } 18 | const matrix& mat() const { return m_H; } 19 | 20 | void operator()(double& x, double& y) const; 21 | Homography operator*(const Homography& rhs) const; 22 | Homography inverse() const; 23 | private: 24 | matrix m_H; 25 | void normalize(); 26 | }; 27 | 28 | /// Homography (and more restricted transforms) estimation. 29 | class ComputeH { 30 | public: 31 | enum Type { Translation, // (2 parameters) 32 | Rotation, // Rotation/Translation (3 parameters) 33 | Zoom, // Zoom/Translation (3 parameters) 34 | GeneralZoom, // Non uniform zoom/Translation (4 parameters) 35 | Similarity, // Zoom/Rotation/Translation (4 parameters) 36 | Affine, // (6 parameters) 37 | Projective // (8 parameters) 38 | }; 39 | static Type restrict(Type t); // Return less general motion 40 | public: 41 | ComputeH(Type type); 42 | ~ComputeH(); 43 | 44 | Type type() const { return _type; } 45 | void clear(); 46 | 47 | /// Add corresponding points (x1,y1) and (x2,y2) 48 | void add(float x1, float y1, float x2, float y2, float w = 1.0f); 49 | /// Add corresponding lines of equation u x + v y + w = 0 50 | void add(float a1, float b1, float c1, 51 | float a2, float b2, float c2, float w = 1.0f); 52 | 53 | float weight() const; ///< Sum of weights (=#correspondences) 54 | float q_error(const Homography& map) const; ///< Quadratic error 55 | float compute(Homography& map) const; ///< LSE motion, return support weight 56 | private: 57 | Type _type; 58 | int n; ///< Dimension of matrix = # unknown parameters 59 | double Ann[64], Bn[8], b; // Min (X 1) (A B) (X 1)^T is X^T = Ann^-1 Bn 60 | 61 | static int size(Type type); 62 | void add_4parameters(float x1, float y1, float x2, float y2, float w); 63 | void add_4parameters(float a1, float b1, float c1, 64 | float a2, float b2, float c2, float w); 65 | void wrap(Homography& map, const vector& v) const; 66 | void unwrap(const Homography& map, vector& v) const; 67 | float q_error(const vector& v) const; // Quadratic error 68 | 69 | bool compute_rotation(vector& B) const; 70 | 71 | /// For Projective, data normalization is required 72 | class Normalization { public: double x, y, s; }; 73 | bool normalize(Normalization& left, 74 | matrix& A, vector& B, 75 | Normalization& right) const; 76 | static bool de_normalize(const Normalization& left, 77 | vector& B, 78 | const Normalization& right); 79 | }; 80 | 81 | } // libNumerics 82 | 83 | #endif 84 | -------------------------------------------------------------------------------- /cpp_libs/libNumerics/numerics.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file numerics.h 3 | * @brief Linear algebra: system solving by LU decomposition and SVD 4 | * @author Pascal Monasse 5 | * 6 | * Copyright (c) 2010-2012 Pascal Monasse 7 | * All rights reserved. 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | #ifndef NUMERICS_H 24 | #define NUMERICS_H 25 | 26 | #include "matrix.h" 27 | 28 | namespace libNumerics { 29 | typedef double flnum; 30 | 31 | /// Solve system AX = B. 32 | bool solveLU(const matrix& A, const vector& B, 33 | vector& X); 34 | bool solveLU(matrix A, vector& B); 35 | 36 | /// Singular Value Decomposition: U diag(D) V, U in O(m), V in O(n), D>=0. 37 | class SVD { 38 | public: 39 | SVD(const matrix& A); 40 | matrix compose() const; 41 | flnum sv(int i) const; 42 | 43 | matrix U, V; 44 | vector D; 45 | 46 | typedef matrix Mat; 47 | typedef vector Vec; 48 | // Static functions related to SVD 49 | static bool Nullspace(const Mat& A, Vec* nullspace, 50 | double ratioExtremes=1e-2, double ratio2Min=.5); 51 | static flnum InvCond(const Mat& A); 52 | static void EnforceRank2_3x3(const Mat& A, Mat* ARank); 53 | static void Nullspace2_Remap33(const Mat& A, Mat& f1, Mat& f2); 54 | private: 55 | void sort(); 56 | }; 57 | 58 | } // namespace libNumerics 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /cpp_libs/libNumerics/rodrigues.cpp: -------------------------------------------------------------------------------- 1 | // Authors: Unknown. Please, if you are the author of this file, or if you 2 | // know who are the authors of this file, let us know, so we can give the 3 | // adequate credits and/or get the adequate authorizations. 4 | 5 | #ifdef RODRIGUES_H 6 | 7 | namespace libNumerics { 8 | 9 | template 10 | matrix skew(const vector& v) 11 | { 12 | assert(v.nrow() == 3); 13 | matrix M(3,3); 14 | M(0,0) = M(1,1) = M(2,2) = 0; 15 | M(1,2) = -(M(2,1)=v(0)); 16 | M(2,0) = -(M(0,2)=v(1)); 17 | M(0,1) = -(M(1,0)=v(2)); 18 | return M; 19 | } 20 | 21 | template 22 | matrix rotation(vector w) 23 | { 24 | assert(w.nrow() == 3); 25 | T n = sqrt(w.qnorm()); 26 | T c = cos(n); 27 | matrix R = c*matrix::eye(3); 28 | if(n) { 29 | w /= n; 30 | R += skew(sin(n)*w); 31 | R += (1-c)*w*w.t(); 32 | } 33 | return R; 34 | } 35 | 36 | template 37 | vector rotationAxis(const matrix& R) 38 | { 39 | assert(R.nrow() == 3 && R.ncol() == 3); 40 | vector w(3); 41 | T n = acos(0.5*(R.tr()-1)); 42 | if(n == 0) 43 | w = 0; 44 | else { 45 | w(0) = R(2,1)-R(1,2); 46 | w(1) = R(0,2)-R(2,0); 47 | w(2) = R(1,0)-R(0,1); 48 | w *= n/(2*sin(n)); 49 | } 50 | return w; 51 | } 52 | 53 | } // libNumerics 54 | 55 | #endif // RODRIGUES_H 56 | -------------------------------------------------------------------------------- /cpp_libs/libNumerics/rodrigues.h: -------------------------------------------------------------------------------- 1 | // Authors: Unknown. Please, if you are the author of this file, or if you 2 | // know who are the authors of this file, let us know, so we can give the 3 | // adequate credits and/or get the adequate authorizations. 4 | 5 | #ifndef RODRIGUES_H 6 | #define RODRIGUES_H 7 | 8 | #include "matrix.h" 9 | #include 10 | 11 | namespace libNumerics { 12 | 13 | /// Skew-symmetric matrix of 3-vector v. 14 | template matrix skew(const vector& v); 15 | /// Rodrigues's rotation: exp(w_x). 16 | template matrix rotation(vector w); 17 | /// Inverse Rodrigues's formula: w s.t. R=exp(w_x). 18 | template vector rotationAxis(const matrix& R); 19 | 20 | } // libNumerics 21 | 22 | #include "rodrigues.cpp" 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /cpp_libs/libOrsa/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | SET(SRC conditioning.hpp conditioning.cpp 2 | orsa_model.hpp orsa_model.cpp 3 | fundamental_model.hpp fundamental_model.cpp 4 | orsa_fundamental.hpp orsa_fundamental.cpp 5 | match.hpp) 6 | 7 | ADD_LIBRARY(Orsa ${SRC}) 8 | 9 | IF(UNIX) 10 | SET_TARGET_PROPERTIES(Orsa PROPERTIES 11 | COMPILE_FLAGS "-std=c++98 -Wall -Wextra -Werror") 12 | ENDIF(UNIX) 13 | 14 | IF(MSVC) 15 | ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS) 16 | ENDIF(MSVC) 17 | 18 | 19 | TARGET_LINK_LIBRARIES(Orsa Numerics) 20 | -------------------------------------------------------------------------------- /cpp_libs/libOrsa/conditioning.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2007-2011 libmv authors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | #include "conditioning.hpp" 22 | #include 23 | #include 24 | using namespace std; 25 | 26 | namespace orsa { 27 | 28 | void PreconditionerFromPoints(int width, int height, Mat *T) { 29 | // Build the normalization matrix 30 | double dNorm = 1.0 / sqrt( static_cast(width*height) ); 31 | 32 | (*T) = Mat::eye(3); 33 | (*T)(0,0) = (*T)(1,1) = dNorm; 34 | (*T)(0,2) = -.5f*width*dNorm; 35 | (*T)(1,2) = -.5*height*dNorm; 36 | } 37 | 38 | void NormalizePoints(const Mat &points, 39 | Mat *normalized_points, 40 | Mat *T, 41 | int width, 42 | int height) { 43 | PreconditionerFromPoints(width, height, T); 44 | ApplyTransformationToPoints(points, *T, normalized_points); 45 | } 46 | 47 | void UnnormalizerI::Unnormalize(const Mat &T1, const Mat &T2, Mat *H) { 48 | *H = T2.inv() * (*H) * T1; 49 | } 50 | 51 | // Return the square of a number. 52 | template 53 | inline T Square(T x) { 54 | return x * x; 55 | } 56 | 57 | void MeanAndVarianceAlongRows(const Mat &A, 58 | vector *mean_pointer, 59 | vector *variance_pointer) { 60 | vector &mean = *mean_pointer; 61 | vector &variance = *variance_pointer; 62 | int n = A.nrow(); 63 | int m = A.ncol(); 64 | mean = vector(n, 0.0); 65 | variance = vector(n, 0.0); 66 | 67 | for (int i = 0; i < n; ++i) { 68 | for (int j = 0; j < m; ++j) { 69 | double x = A(i, j); 70 | mean[i] += x; 71 | variance[i] += x * x; 72 | } 73 | } 74 | 75 | for (int i = 0; i < n; ++i) 76 | mean[i] /= m; 77 | 78 | for (int i = 0; i < n; ++i) { 79 | variance[i] = variance[i] / m - Square(mean[i]); 80 | } 81 | } 82 | 83 | // Hartley-Zisserman 4.4.4 pag.109 84 | void PreconditionerFromPoints(const Mat &points, Mat *T) { 85 | vector mean, variance; 86 | MeanAndVarianceAlongRows(points, &mean, &variance); 87 | 88 | double xfactor = sqrt(2.0 / variance[0]); 89 | double yfactor = sqrt(2.0 / variance[1]); 90 | 91 | // If variance is equal to 0.0 set scaling factor to identity. 92 | // -> Else it will provide nan value (because division by 0). 93 | if (variance[0] < 1e-8) 94 | xfactor = mean[0] = 1.0; 95 | if (variance[1] < 1e-8) 96 | yfactor = mean[1] = 1.0; 97 | 98 | (*T)(0,0) = xfactor; (*T)(0,1) = 0; (*T)(0,2) = -xfactor * mean[0]; 99 | (*T)(1,0) = 0; (*T)(1,1) = yfactor; (*T)(1,2) = -yfactor * mean[1]; 100 | (*T)(2,0) = 0; (*T)(2,1) = 0; (*T)(2,2) = 1.0; 101 | } 102 | 103 | void ApplyTransformationToPoints(const Mat &points, 104 | const Mat &T, 105 | Mat *transformed_points) { 106 | const int n = points.ncol(); 107 | (*transformed_points) = Mat(2,n); 108 | for (int i = 0; i < n; ++i) { 109 | Mat in(3,1), out(3,1); 110 | in(0,0) = points(0, i); in(1,0) = points(1, i); in(2,0) = 1.0; 111 | out = T * in; 112 | (*transformed_points)(0, i) = out(0)/out(2); 113 | (*transformed_points)(1, i) = out(1)/out(2); 114 | } 115 | } 116 | 117 | void NormalizePoints(const Mat &points, 118 | Mat *normalized_points, 119 | Mat *T) { 120 | PreconditionerFromPoints(points, T); 121 | ApplyTransformationToPoints(points, *T, normalized_points); 122 | } 123 | 124 | } // namespace orsa 125 | -------------------------------------------------------------------------------- /cpp_libs/libOrsa/conditioning.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2007-2011 libmv authors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | #ifndef LIBS_MULTIVIEW_CONDITIONNING_H_ 22 | #define LIBS_MULTIVIEW_CONDITIONNING_H_ 23 | 24 | #include "../libNumerics/matrix.h" 25 | 26 | //-- Implementation of normalized coordinates. 27 | // Normalization improve accuracy of results and provide benefits 28 | // that make scale and coordinate origin invariant. 29 | // Two normalization algorithm are implemented : 30 | // - Normalization from image dimension to [-.5, .5] 31 | // - Normalization with zero mean and variance to 1.0 32 | // 33 | namespace orsa { 34 | typedef libNumerics::matrix Mat; 35 | 36 | // Point conditioning (compute Transformation matrix) (T must be (3,3)) : 37 | void PreconditionerFromPoints(const Mat &points, Mat *T); 38 | 39 | // Apply a given transformation to points (T must be (3,3)) : 40 | void ApplyTransformationToPoints(const Mat &points, 41 | const Mat &T, 42 | Mat *transformed_points); 43 | // 44 | // Normalize point 45 | // The implementation follows Algorithm 4.2 from Hartley-Zisserman page 109. 46 | void NormalizePoints(const Mat &points, 47 | Mat *normalized_points, 48 | Mat *T); 49 | 50 | // Point conditioning (compute Transformation matrix) 51 | void PreconditionerFromPoints(int width, int height, Mat *T); 52 | 53 | // 54 | // Normalize point 55 | // From image coordinates to [-.5, .5] 56 | void NormalizePoints(const Mat &points, 57 | Mat *normalized_points, 58 | Mat *T, int width, int height); 59 | 60 | /// Use inverse for unnormalize 61 | struct UnnormalizerI { 62 | // Denormalize the results. See Hartley-Zisserman page 109. 63 | // All matrices must be (3,3) 64 | static void Unnormalize(const Mat &T1, const Mat &T2, Mat *H); 65 | }; 66 | 67 | } //namespace orsa 68 | 69 | #endif // LIBS_MULTIVIEW_CONDITIONNING_H_ 70 | -------------------------------------------------------------------------------- /cpp_libs/libOrsa/fundamental_model.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file fundamental_model.cpp 3 | * @brief Fundamental matrix model 4 | * @author Pascal Monasse, Pierre Moulon 5 | * 6 | * Copyright (c) 2011 Pascal Monasse, Pierre Moulon 7 | * All rights reserved. 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | #ifndef FUNDAMENTAL_MODEL_H_ 24 | #define FUNDAMENTAL_MODEL_H_ 25 | 26 | #include 27 | #include "orsa_model.hpp" 28 | #include "../libNumerics/matrix.h" 29 | 30 | namespace orsa { 31 | 32 | /// Fundamental 7-point model, used for robust estimation. 33 | /// 34 | /// See page 281 of book by Hartley-Zisserman. 35 | /// The equation is \f$det(F_1 + \alpha F_2) = 0\f$. 36 | class FundamentalModel : public OrsaModel { 37 | public: 38 | FundamentalModel(const Mat &x1, int w1, int h1, 39 | const Mat &x2, int w2, int h2, 40 | bool symError=false); 41 | 42 | /// 7 points are required to compute a fundamental matrix. 43 | int SizeSample() const { return 7;} 44 | 45 | /// Up to 3 fundamental matrices are computed from a sample of 7 points. 46 | int NbModels() const { return 3;} 47 | 48 | /// Distance used to distinguish inlier/outlier is to a line 49 | virtual bool DistToPoint() const { return false; } 50 | 51 | void Fit(const std::vector &indices, std::vector *Fs) const; 52 | 53 | /// Square reprojection error for a given point through F. 54 | double Error(const Mat &F, int index, int* side=0) const; 55 | 56 | /// Unnormalize a given model (from normalized to image space). 57 | void Unnormalize(Model *model) const; 58 | private: 59 | bool symError_; ///< Use symmetric error or transfer error in image 2? 60 | 61 | void algo7pt(const Mat& A, std::vector *Fs) const; 62 | void algo8pt(const Mat& A, std::vector *Fs) const; 63 | void checkF(const std::vector &indices, std::vector *Fs) const; 64 | }; 65 | 66 | } // namespace orsa 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /cpp_libs/libOrsa/fundamental_model_test.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2007-2011 libmv authors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | #include 22 | #include "CppUnitLite/TestHarness.h" 23 | #include "libOrsa/fundamental_model.hpp" 24 | 25 | typedef libNumerics::matrix Mat; 26 | 27 | // Check the properties of a fundamental matrix: 28 | // 29 | // 1. The determinant is 0 (rank deficient) 30 | // 2. The condition x'T*F*x = 0 is satisfied to precision. 31 | // 32 | bool ExpectFundamentalProperties(const Mat &F, 33 | const Mat &ptsA, int w1, int h1, 34 | const Mat &ptsB, int w2, int h2, 35 | double precision) { 36 | bool bOk = true; 37 | bOk &= F.det() < precision; 38 | std::cout << std::endl << F << std::endl; 39 | orsa::FundamentalModel model(ptsA, w1, h1, ptsB, w2, h2); 40 | assert(ptsA.ncol() == ptsB.ncol()); 41 | for (int i = 0; i < ptsA.ncol(); ++i) { 42 | double residual = model.Error(F,i); 43 | bOk &= residual < precision; 44 | } 45 | return bOk; 46 | } 47 | 48 | // Check the fundamental fitting: 49 | // 50 | // 1. Estimate the fundamental matrix 51 | // 2. Check epipolar distance. 52 | // 53 | template 54 | bool ExpectKernelProperties(const Mat &x1, int w1, int h1, 55 | const Mat &x2, int w2, int h2) { 56 | bool bOk = true; 57 | orsa::OrsaModel* kernel = new Kernel(x1, w1, h1, x2, w2, h2); 58 | std::vector samples; 59 | for (int i = 0; i < x1.ncol(); ++i) { 60 | samples.push_back(i); 61 | } 62 | std::vector vec_F; 63 | kernel->Fit(samples, &vec_F); 64 | for (size_t i = 0; i < vec_F.size(); ++i) 65 | { 66 | bOk &= ExpectFundamentalProperties(vec_F[i], x1, w1, h1, x2, w2, h2, 1e-8); 67 | } 68 | delete kernel; 69 | return bOk; 70 | } 71 | 72 | TEST(SevenPointTest, EasyCase) { 73 | Mat x1(2, 7), x2(2, 7); 74 | double points[] = { 0, 0, 0, 1, 1, 1, 2, 75 | 0, 1, 2, 0, 1, 2, 0}; 76 | x1.read(points); 77 | double points2[] = { 0, 0, 0, 1, 1, 1, 2, 78 | 1, 2, 3, 1, 2, 3, 1}; 79 | x2.read(points2); 80 | typedef orsa::FundamentalModel Model; 81 | CHECK(ExpectKernelProperties(x1, 3, 3, x2, 3, 3)); 82 | } 83 | 84 | TEST(SevenPointTest, RealCorrespondences) { 85 | Mat x1(2, 7), x2(2, 7); 86 | double points[] = { 723, 1091, 1691, 447, 971, 1903, 1483, 87 | 887, 699, 811, 635, 91, 447, 1555}; 88 | x1.read(points); 89 | double points2[] = { 1251, 1603, 2067, 787, 1355, 2163, 1875, 90 | 1243, 923, 1031, 484, 363, 743, 1715}; 91 | x2.read(points2); 92 | 93 | typedef orsa::FundamentalModel Model; 94 | CHECK(ExpectKernelProperties(x1, 1500, 1800, x2, 2200, 1800)); 95 | } 96 | 97 | /* ************************************************************************* */ 98 | int main() { TestResult tr; return TestRegistry::runAllTests(tr);} 99 | /* ************************************************************************* */ 100 | -------------------------------------------------------------------------------- /cpp_libs/libOrsa/fundamental_orsa_test.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2007-2011 libmv authors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | #include 22 | #include 23 | 24 | #include "libOrsa/fundamental_model.hpp" 25 | #include "CppUnitLite/TestHarness.h" 26 | 27 | typedef libNumerics::matrix Mat; 28 | 29 | // Unit test : 30 | //- It considers 16 points and an outlier. 31 | //- It asserts that the F matrix and inliers number are correct. 32 | // F should be similar to: 33 | // 0, -a, -b, 34 | // a, 0, -c, 35 | // b, c, 0 36 | // 37 | // Note : 38 | // This test use not normalized coordinates. 39 | TEST(Fundamental_Orsa, Test) 40 | { 41 | const int n = 16; 42 | Mat x1(2,n); 43 | double points[] = { 44 | 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 45 | 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 5}; 46 | x1.read(points); 47 | 48 | Mat x2 = x1; 49 | for (int i = 0; i < n; ++i) { 50 | x2(0, i) += i % 2; // Multiple horizontal disparities. 51 | } 52 | // The outlier has vertical disparity. 53 | x2(0, n - 1) = 10; 54 | x2(1, n - 1) = 10; 55 | 56 | /// Create the Kernel (Model estimator and tester) 57 | orsa::FundamentalModel model(x1, 5, 5, x2, 5, 5); 58 | Mat F(3,3); 59 | std::vector vec_inliers; 60 | /// Orsa (robust estimation routine) 61 | model.orsa(vec_inliers, 100, NULL, &F, true); 62 | 63 | const double expectedPrecision = 1e-8; 64 | const double & ep = expectedPrecision; 65 | DOUBLES_EQUAL(0.0, F(0,0), ep); 66 | DOUBLES_EQUAL(0.0, F(1,1), ep); 67 | DOUBLES_EQUAL(0.0, F(2,2), ep); 68 | DOUBLES_EQUAL(F(0,1), -F(1,0), ep); 69 | DOUBLES_EQUAL(F(0,2), -F(2,0), ep); 70 | DOUBLES_EQUAL(F(1,2), -F(2,1), ep); 71 | CHECK_EQUAL(n - 1, vec_inliers.size()); 72 | CHECK_EQUAL(true, std::find(vec_inliers.begin(), vec_inliers.end(), 15) == vec_inliers.end()); 73 | } 74 | 75 | /* ************************************************************************* */ 76 | int main() { TestResult tr; return TestRegistry::runAllTests(tr);} 77 | /* ************************************************************************* */ 78 | -------------------------------------------------------------------------------- /cpp_libs/libOrsa/homography_model.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file homography_model.hpp 3 | * @brief Homography matrix model 4 | * @author Pascal Monasse, Pierre Moulon 5 | * 6 | * Copyright (c) 2011 Pascal Monasse, Pierre Moulon 7 | * All rights reserved. 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | #ifndef HOMOGRAPHY_MODEL_H_ 24 | #define HOMOGRAPHY_MODEL_H_ 25 | 26 | #include 27 | #include 28 | #include "cpp_libs/libOrsa/orsa_model.hpp" 29 | #include "cpp_libs/libNumerics/matrix.h" 30 | 31 | namespace orsa { 32 | 33 | /// Homography model used for robust estimation with ORSA algorithm. 34 | class HomographyModel : public OrsaModel { 35 | public: 36 | HomographyModel(const Mat &x1, int w1, int h1, 37 | const Mat &x2, int w2, int h2, 38 | bool symError=false); 39 | 40 | /// 4 point correspondences required to compute a homography. 41 | int SizeSample() const { return 4; } 42 | 43 | /// Only 1 homography can be estimated from a sample of 4 points. 44 | int NbModels() const { return 1; } 45 | 46 | /// Distance used to distinguish inlier/outlier is to a point 47 | virtual bool DistToPoint() const { return true; } 48 | 49 | /// Estimated homography satisfies the equation y = H x. 50 | void Fit(const std::vector &indices, std::vector *H) const; 51 | 52 | /// Square reprojection error for a given point through the model H. 53 | double Error(const Mat &H, int index, int* side=0) const; 54 | 55 | /// Unnormalize a given model (from normalized to image space). 56 | void Unnormalize(Model *model) const; 57 | 58 | private: 59 | bool symError_; ///< Use symmetric error or transfer error in image 2? 60 | bool IsOrientationPreserving(const std::vector &indices, 61 | const Mat& H) const; 62 | }; 63 | 64 | } // namespace orsa 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /cpp_libs/libOrsa/homography_model_test.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2007-2011 libmv authors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | #include 22 | #include "libOrsa/homography_model.hpp" 23 | #include "extras/libNumerics/matrix.h" 24 | #include "testing/testing.h" 25 | 26 | typedef libNumerics::matrix Mat; 27 | 28 | void TransformH(double x, double y, const Mat & H, double & xT, double & yT ) 29 | { 30 | Mat x1_H = Mat(3,1); 31 | x1_H(0,0) = x; x1_H(1,0) = y; x1_H(2,0) = 1.0; 32 | Mat x2h_est = H * x1_H; 33 | x2h_est /= x2h_est(2,0); // homogeneous to euclidean 34 | xT = x2h_est(0); 35 | yT = x2h_est(1); 36 | } 37 | 38 | TEST(HomographyKernelTest, Fitting) { 39 | //------------------------// 40 | //-- Unit test Objective--// 41 | //------------------------// 42 | // Given two points set linked by a known homography : 43 | // -=> Compute the homography trough sampled points 44 | // -=> Assert that estimated H is good and residuals are near 0 to a given epsilon. 45 | //-- 46 | //-- 47 | 48 | typedef libNumerics::matrix Mat; 49 | 50 | // Define a few homographies. 51 | std::vector H_gt(3, Mat::zeros(3,3)); 52 | 53 | H_gt[0] = Mat::eye(3); 54 | double matGTd1[] = { 1, 0, -4, 0, 1, 5, 0, 0, 1}; 55 | H_gt[1].read(matGTd1); 56 | double matGTd2[] = { 1, 0, 3, 0, 1, -6, 0, 0, 1}; 57 | H_gt[2].read(matGTd2); 58 | 59 | // Define a set of points. 60 | Mat x(2, 9); 61 | double points[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 62 | 0,.4,.6, 0, 1, 2, 0, 1, 2}; 63 | x.read(points); 64 | 65 | for (int i = 0; i < H_gt.size(); ++i) { 66 | 67 | bool bFound = false; 68 | // Transform points by the ground truth homography. 69 | Mat y(2,9); 70 | for(int k = 0; k < 9; ++k) 71 | { 72 | TransformH(x(0,k), x(1,k), H_gt[i], y(0,k), y(1,k) ); 73 | } 74 | 75 | orsa::HomographyModel kernel(x, 10, 10, y, 10, 10); 76 | 77 | //-- Fit a model and check re-projection error. 78 | int samples_[5]={0,1,2,3,4}; 79 | std::vector samples(samples_,samples_+5); 80 | for (int j = 4; samples.size() < x.ncol(); samples.push_back(j++)) { 81 | Mat H(3,3); 82 | if(kernel.ComputeModel(samples, &H)) 83 | { 84 | EXPECT_MATRIX_NEAR(H_gt[i], H, 5e-8); 85 | bFound = true; 86 | } 87 | } 88 | EXPECT_TRUE(bFound); 89 | } 90 | } 91 | 92 | /* ************************************************************************* */ 93 | int main() { TestResult tr; return TestRegistry::runAllTests(tr);} 94 | /* ************************************************************************* */ 95 | -------------------------------------------------------------------------------- /cpp_libs/libOrsa/homography_orsa_test.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2007-2011 libmv authors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | #include 22 | #include 23 | #include "libOrsa/homography_model.hpp" 24 | #include "extras/libNumerics/matrix.h" 25 | #include "testing/testing.h" 26 | 27 | TEST(RobustHomographyEstimation, ORSA) { 28 | //------------------------// 29 | //-- Unit test Objective--// 30 | //------------------------// 31 | // Given two points set linked by a known homography : 32 | // -=> Set an outlier in the point dataset. 33 | // -=> Make a robust estimation powered with ORSA 34 | // -=> Check the estimated matrix and inliers indexes. 35 | //-- 36 | //-- 37 | 38 | typedef libNumerics::matrix Mat; 39 | 40 | // Define a synthetic dataset 41 | // - 15 points that are inlier, 42 | // - 1 point that is outlier. 43 | const int n = 16; 44 | Mat x1(2,n); 45 | Mat x2(2,n); 46 | Mat matGT(3,3); // Ground truth matrix. 47 | { 48 | // Defines input points 49 | double points[] = { 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 50 | 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 5}; 51 | x1.read(points); 52 | 53 | x2 = x1; 54 | for (int i = 0; i < n; ++i) { 55 | x2(0, i) += i + 2; // Multiple horizontal disparities. 56 | } 57 | 58 | // Last point set as an outlier 59 | x2(0, n - 1) = 10; 60 | x2(1, n - 1) = 10; 61 | 62 | // Setup Ground truth matrix. 63 | double matGTd[] = { 4, 1, 2, 0, 1, 0, 0, 0, 1}; 64 | matGT.read(matGTd); 65 | } 66 | 67 | 68 | // Robust homography solving : 69 | { 70 | orsa::HomographyModel kernel(x1, 6, 6, x2, 6, 6); 71 | 72 | std::vector vec_inliers; 73 | Mat homographyMat(3,3); 74 | 75 | kernel.orsa(vec_inliers, 100, NULL, &homographyMat, true); 76 | 77 | // Assert we found 15 inliers 78 | EXPECT_EQ(15, vec_inliers.size()); 79 | 80 | //-- Re-estimate Homography on all inliers. 81 | kernel.ComputeModel(vec_inliers, &homographyMat); 82 | 83 | // Compare matrix to Ground truth. 84 | EXPECT_MATRIX_NEAR(matGT, homographyMat, 1e-8); 85 | } 86 | } 87 | 88 | /* ************************************************************************* */ 89 | int main() { TestResult tr; return TestRegistry::runAllTests(tr);} 90 | /* ************************************************************************* */ 91 | 92 | -------------------------------------------------------------------------------- /cpp_libs/libOrsa/match.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file match.hpp 3 | * @brief Match between two image points. 4 | * @author Pascal Monasse, Pierre Moulon 5 | * 6 | * Copyright (c) 2010-2011 Pascal Monasse, Pierre Moulon 7 | * All rights reserved. 8 | * 9 | * This program is free software: you can use, modify and/or 10 | * redistribute it under the terms of the simplified BSD License. You 11 | * should have received a copy of this license along this program. If 12 | * not, see . 13 | */ 14 | 15 | #ifndef MATCH_H 16 | #define MATCH_H 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | /// Save matching position between two points. 23 | struct Match { 24 | Match() {} 25 | Match(float ix1, float iy1, float ix2, float iy2) 26 | : x1(ix1), y1(iy1), x2(ix2), y2(iy2), similarity(1.0) {} 27 | Match(float ix1, float iy1, float ix2, float iy2, float similarity) 28 | : x1(ix1), y1(iy1), x2(ix2), y2(iy2), similarity(similarity) {} 29 | float x1, y1, x2, y2, similarity; 30 | int Qidx, Tidx; 31 | 32 | /** 33 | * Load the corresponding matches from file. 34 | * \param nameFile The file where matches were saved. 35 | * \param vec_match The loaded corresponding points. 36 | * \return bool True if everything was ok, otherwise false. 37 | */ 38 | 39 | // Match operator-(const Match& in) const { 40 | // return Match(this->x1-in.x1, this->y1-in.y1, this->x2-in.x2, this->y2-in.y2); 41 | // } 42 | 43 | static bool loadMatch(const char* nameFile, std::vector& vec_match) 44 | { 45 | vec_match.clear(); 46 | std::ifstream f(nameFile); 47 | while( f.good() ) { 48 | std::string str; 49 | std::getline(f, str); 50 | if( f.good() ) { 51 | std::istringstream s(str); 52 | Match m; 53 | s >> m; 54 | if(!s.fail() ) 55 | vec_match.push_back(m); 56 | } 57 | } 58 | return !vec_match.empty(); 59 | } 60 | 61 | /** 62 | * Save the corresponding matches to file. 63 | * \param nameFile The file where matches will be saved. 64 | * \param vec_match The matches that we want to save. 65 | * \return bool True if everything was ok, otherwise false. 66 | */ 67 | static bool saveMatch(const char* nameFile, const std::vector& vec_match) 68 | { 69 | std::ofstream f(nameFile); 70 | if( f.is_open() ) { 71 | std::vector::const_iterator it = vec_match.begin(); 72 | for(; it != vec_match.end(); ++it) 73 | f << *it; 74 | } 75 | return f.is_open(); 76 | } 77 | 78 | /// Lexicographical ordering of matches. Used to remove duplicates. 79 | friend bool operator<(const Match& m1, const Match& m2) 80 | { 81 | if(m1.x1 < m2.x1) return true; 82 | if(m1.x1 > m2.x1) return false; 83 | 84 | if(m1.y1 < m2.y1) return true; 85 | if(m1.y1 > m2.y1) return false; 86 | 87 | if(m1.x2 < m2.x2) return true; 88 | if(m1.x2 > m2.x2) return false; 89 | 90 | return (m1.y2 < m2.y2); 91 | } 92 | 93 | /// Comparison Operator 94 | friend bool operator==(const Match& m1, const Match& m2) 95 | { 96 | return (m1.x1==m2.x1 && m1.y1==m2.y1 && 97 | m1.x2==m2.x2 && m1.y2==m2.y2); 98 | } 99 | 100 | friend std::ostream& operator<<(std::ostream& os, const Match & m) 101 | { 102 | return os << m.x1 << " " << m.y1 << " " 103 | << m.x2 << " " << m.y2 << std::endl; 104 | } 105 | 106 | friend std::istream& operator>>(std::istream & in, Match & m) 107 | { 108 | return in >> m.x1 >> m.y1 >> m.x2 >> m.y2; 109 | } 110 | }; 111 | 112 | #endif // MATCH_H 113 | -------------------------------------------------------------------------------- /cpp_libs/libOrsa/orsa_fundamental.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file orsa_fundamental.cpp 3 | * @brief Fundamental matrix estimation with ORSA algorithm 4 | * @author Lionel Moisan, Pascal Monasse, Pierre Moulon 5 | * 6 | * Copyright (c) 2011-2016 Lionel Moisan, Pascal Monasse, Pierre Moulon 7 | * All rights reserved. 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | #include "orsa_fundamental.hpp" 24 | #include "fundamental_model.hpp" 25 | 26 | #include 27 | #include 28 | 29 | using namespace libNumerics; 30 | 31 | namespace orsa { 32 | 33 | /// Display and return average/max error of inliers of fundamental matrix F. 34 | std::pair display_stats(const std::vector& match, 35 | const std::vector& in, 36 | const matrix& F, bool verb) { 37 | std::vector::const_iterator it=in.begin(); 38 | double l2=0, linf=0; 39 | for(; it!=in.end(); ++it) { 40 | const Match& m=match[*it]; 41 | double a = F(0,0) * m.x1 + F(1,0) * m.y1 + F(2,0); 42 | double b = F(0,1) * m.x1 + F(1,1) * m.y1 + F(2,1); 43 | double c = F(0,2) * m.x1 + F(1,2) * m.y1 + F(2,2); 44 | double d = a*m.x2 + b*m.y2 + c; 45 | double e = (d*d) / (a*a + b*b); 46 | l2 += e; 47 | if(linf < e) 48 | linf = e; 49 | } 50 | std::pair err(sqrt(l2/in.size()),sqrt(linf)); 51 | if (verb) 52 | std::cout << "Average/max error: " 53 | << err.first << "/" << err.second <& vec_matchings, 70 | int w1,int h1, int w2,int h2, 71 | double precision, int nbIter, 72 | matrix& F, 73 | std::vector& vec_inliers, double& nfa, bool verb) 74 | { 75 | const int n = static_cast( vec_matchings.size() ); 76 | if(n < 7) 77 | { 78 | //std::cerr << "Error: ORSA needs 7 matches or more to proceed" < xA(2,n), xB(2,n); 82 | for (int i=0; i < n; ++i) 83 | { 84 | xA(0,i) = vec_matchings[i].x1; 85 | xA(1,i) = vec_matchings[i].y1; 86 | xB(0,i) = vec_matchings[i].x2; 87 | xB(1,i) = vec_matchings[i].y2; 88 | } 89 | 90 | FundamentalModel model(xA, w1, h1, xB, w2, h2); 91 | //model.setConvergenceCheck(true); 92 | nfa = model.orsa(vec_inliers, nbIter, &precision, &F, verb); 93 | if(nfa>0.0) 94 | return false; 95 | std::pair err; // (RMSE,max) 96 | if (verb) 97 | std::cout << "Before refinement: "; 98 | err = display_stats(vec_matchings, vec_inliers, F,verb); 99 | matrix F2(3,3); 100 | if( model.ComputeModel(vec_inliers,&F2) ) // Re-estimate with all inliers 101 | { 102 | if (verb) 103 | std::cout << "After refinement: "; 104 | double maxBefore = err.second; 105 | if(display_stats(vec_matchings, vec_inliers, F2,verb).first <= maxBefore) 106 | F = F2; 107 | else 108 | if (verb) 109 | std::cerr << "Warning: error after refinement is too large, thus ignored" 110 | <. 21 | */ 22 | 23 | #ifndef ORSA_FUNDAMENTAL_H 24 | #define ORSA_FUNDAMENTAL_H 25 | 26 | #include 27 | #include "../libNumerics/matrix.h" 28 | #include "match.hpp" 29 | 30 | namespace orsa { 31 | /// ORSA fundamental matrix estimation. 32 | bool orsa_fundamental(const std::vector& vec_matchings, 33 | int w1,int h1, int w2,int h2, 34 | double precision, int nbIter, 35 | libNumerics::matrix& F, 36 | std::vector& vec_inliers, double& nfa,bool verb); 37 | } 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /cpp_libs/libOrsa/orsa_homography.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file orsa_homography.cpp 3 | * @brief Homographic image registration 4 | * @author Pascal Monasse, Pierre Moulon 5 | * 6 | * Copyright (c) 2011-2012 Pascal Monasse, Pierre Moulon 7 | * All rights reserved. 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | #include 24 | #include 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include "match.hpp" 31 | 32 | 33 | #include "cpp_libs/libOrsa/homography_model.hpp" 34 | 35 | #include "cpp_libs/libNumerics/numerics.h" 36 | 37 | 38 | namespace orsa { 39 | /// Number of random samples in ORSA 40 | 41 | bool TransformH(const libNumerics::matrix &H, double &x, double &y) 42 | { 43 | libNumerics::vector X(3); 44 | X(0)=x; X(1)=y; X(2)=1.0; 45 | X = H*X; 46 | bool positive = (X(2)*H(2,2)>0); 47 | X /= X(2); 48 | x = X(0); y = X(1); 49 | return positive; 50 | } 51 | 52 | 53 | /// Display average/max error of inliers of homography H. 54 | static void display_stats(const std::vector& vec_matchings, 55 | const std::vector& vec_inliers, 56 | libNumerics::matrix& H,bool verb) { 57 | std::vector::const_iterator it=vec_inliers.begin(); 58 | double l2=0, linf=0; 59 | for(; it!=vec_inliers.end(); ++it) { 60 | const Match& m=vec_matchings[*it]; 61 | double x1=m.x1, y1=m.y1; 62 | TransformH(H, x1, y1); 63 | double e = (m.x2-x1)*(m.x2-x1) + (m.y2-y1)*(m.y2-y1); 64 | l2 += e; 65 | if(linf < e) 66 | linf = e; 67 | } 68 | if (verb) 69 | std::cout << "Average/max error: " 70 | << sqrt(l2/vec_inliers.size()) << "/" 71 | << sqrt(linf) <& vec_matchings, int w1,int h1, int w2,int h2, 76 | double precision, int nbIter, libNumerics::matrix& H, std::vector& vec_inliers,double& nfa, bool verb) 77 | { 78 | const int n = static_cast( vec_matchings.size() ); 79 | if(n < 5) 80 | { 81 | if (verb) 82 | std::cerr << "Error: ORSA Homography needs 5 matches or more to proceed" < xA(2,n), xB(2,n); 86 | 87 | for (int i=0; i < n; ++i) 88 | { 89 | xA(0,i) = vec_matchings[i].x1; 90 | xA(1,i) = vec_matchings[i].y1; 91 | xB(0,i) = vec_matchings[i].x2; 92 | xB(1,i) = vec_matchings[i].y2; 93 | } 94 | 95 | orsa::HomographyModel model(xA, w1, h1, xB, w2, h2, true); 96 | //model.setConvergenceCheck(true); 97 | nfa = model.orsa(vec_inliers, nbIter, &precision, &H, verb); 98 | if(nfa>0.0) 99 | return false; 100 | 101 | if (verb) 102 | std::cout << "Before refinement: "; 103 | display_stats(vec_matchings, vec_inliers, H, verb); 104 | if( model.ComputeModel(vec_inliers,&H) ) // Re-estimate with all inliers 105 | { 106 | if (verb) 107 | std::cout << "After refinement: "; 108 | display_stats(vec_matchings, vec_inliers, H, verb); 109 | } else 110 | { 111 | if (verb) 112 | std::cerr << "Warning: error in refinement, result is suspect" <. 21 | */ 22 | 23 | #ifndef ORSA_HOMOGRAPHY_H 24 | #define ORSA_HOMOGRAPHY_H 25 | 26 | #include 27 | #include "../libNumerics/matrix.h" 28 | #include "match.hpp" 29 | 30 | namespace orsa { 31 | /// ORSA homography estimation 32 | bool ORSA_homography(const std::vector& vec_matchings, int w1,int h1, int w2,int h2, 33 | double precision, int nbIter, libNumerics::matrix& H, std::vector& vec_inliers, double& nfa,bool verb); 34 | } 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /cpp_libs/libUSAC/config/ConfigFileReader.cpp: -------------------------------------------------------------------------------- 1 | #pragma warning(disable: 4290) // disable libconfig compile warnings 2 | #include "ConfigFileReader.h" 3 | 4 | 5 | -------------------------------------------------------------------------------- /cpp_libs/libUSAC/config/ConfigFileReader.h: -------------------------------------------------------------------------------- 1 | #ifndef CONFIGFILEREADER_H 2 | #define CONFIGFILEREADER_H 3 | #pragma warning(disable: 4290) // disable libconfig compile warnings 4 | #include 5 | #include 6 | #include 7 | #include "libconfig.h++" 8 | 9 | class ConfigFileReader: public libconfig::Config 10 | { 11 | public: 12 | template 13 | bool getTopLevelParameterValue(const std::string settingName, const std::string parameterName, 14 | T& value) const 15 | { 16 | const libconfig::Setting& root = getRoot(); 17 | try 18 | { 19 | const libconfig::Setting &setting = root[settingName.c_str()]; 20 | if (!setting.lookupValue(parameterName.c_str(), value)) 21 | { 22 | std::cout << settingName << ": parameter " << parameterName << " not found" << std::endl; 23 | return false; 24 | } 25 | } // end try 26 | catch(...) 27 | { 28 | std::cerr << settingName << " block not found; recheck configuration file" << std::endl; 29 | return false; 30 | } 31 | return true; 32 | } 33 | 34 | template 35 | bool getSubLevelParameterValue(const std::string settingName, const std::string subSettingName, 36 | const std::string parameterName, T& value) const 37 | { 38 | const libconfig::Setting& root = getRoot(); 39 | try 40 | { 41 | const libconfig::Setting &setting = root[settingName.c_str()][subSettingName.c_str()]; 42 | if (!setting.lookupValue(parameterName.c_str(), value)) 43 | { 44 | std::cout << settingName << ":" << subSettingName 45 | << ": parameter " << parameterName << " not found" << std::endl; 46 | return false; 47 | } 48 | } 49 | catch(...) 50 | { 51 | std::cerr << settingName << ":" << subSettingName << " block not found; recheck configuration file" << std::endl; 52 | return false; 53 | } 54 | return true; 55 | } 56 | 57 | }; 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /cpp_libs/libUSAC/config/ConfigParams.cpp: -------------------------------------------------------------------------------- 1 | #include "ConfigFileReader.h" 2 | #include "ConfigParams.h" 3 | 4 | bool ConfigParams::initUSACParamsFromConfigFile(const ConfigFileReader& cfr) 5 | { 6 | // read in parameters 7 | try 8 | { 9 | // first get all common parameters 10 | std::string rand_sampling_method, verif_method, local_opt_method, est_problem; 11 | if( !( cfr.getTopLevelParameterValue("common", "ransac_conf", common.confThreshold) && 12 | cfr.getTopLevelParameterValue("common", "min_sample_size", common.minSampleSize) && 13 | cfr.getTopLevelParameterValue("common", "inlier_threshold", common.inlierThreshold) && 14 | cfr.getTopLevelParameterValue("common", "max_hypotheses", common.maxHypotheses) && 15 | cfr.getTopLevelParameterValue("common", "max_solutions_per_sample", common.maxSolutionsPerSample) && 16 | cfr.getTopLevelParameterValue("common", "prevalidate_sample", common.prevalidateSample) && 17 | cfr.getTopLevelParameterValue("common", "prevalidate_model", common.prevalidateModel) && 18 | cfr.getTopLevelParameterValue("common", "degen_check", common.testDegeneracy) && 19 | cfr.getTopLevelParameterValue("common", "random_sampling_method", rand_sampling_method) && 20 | cfr.getTopLevelParameterValue("common", "verif_method", verif_method) && 21 | cfr.getTopLevelParameterValue("common", "local_opt", local_opt_method) ) ) 22 | { 23 | return false; 24 | } 25 | else 26 | { 27 | // verify parameter values 28 | if (common.confThreshold < 0 || common.confThreshold > 1) 29 | { 30 | std::cout << "RANSAC confidence value must be between 0 and 1" << std::endl; 31 | return false; 32 | } 33 | 34 | if (rand_sampling_method.compare("UNIFORM") == 0) 35 | common.randomSamplingMethod = USACConfig::SAMP_UNIFORM; 36 | else if (rand_sampling_method.compare("PROSAC") == 0) 37 | common.randomSamplingMethod = USACConfig::SAMP_PROSAC; 38 | else 39 | { 40 | std::cerr << "Random sampling method " << rand_sampling_method << " not recognized" << std::endl; 41 | return false; 42 | } 43 | 44 | if (verif_method.compare("STANDARD") == 0) 45 | common.verifMethod = USACConfig::VERIF_STANDARD; 46 | else if (verif_method.compare("SPRT") == 0) 47 | common.verifMethod = USACConfig::VERIF_SPRT; 48 | else 49 | { 50 | std::cerr << "Verification method " << verif_method << " not recognized" << std::endl; 51 | return false; 52 | } 53 | 54 | if (local_opt_method.compare("NO_LO") == 0) 55 | common.localOptMethod = USACConfig::LO_NONE; 56 | else if (local_opt_method.compare("LOSAC") == 0) 57 | common.localOptMethod = USACConfig::LO_LOSAC; 58 | else 59 | { 60 | std::cerr << "Local optimization method " << local_opt_method << " not recognized" << std::endl; 61 | return false; 62 | } 63 | } 64 | 65 | // read in PROSAC parameters if required 66 | if (common.randomSamplingMethod == USACConfig::SAMP_PROSAC) 67 | { 68 | if (!( cfr.getTopLevelParameterValue("prosac", "max_prosac_samples", prosac.maxSamples) && 69 | cfr.getTopLevelParameterValue("prosac", "beta", prosac.beta) && 70 | cfr.getTopLevelParameterValue("prosac", "non_rand_conf", prosac.nonRandConf) && 71 | cfr.getTopLevelParameterValue("prosac", "min_stopping_length", prosac.minStopLen) && 72 | cfr.getTopLevelParameterValue("prosac", "sorted_points_path", prosac.sortedPointsFile) )) 73 | { 74 | return false; 75 | } 76 | } 77 | 78 | // read in SPRT parameters if required 79 | if (common.verifMethod == USACConfig::VERIF_SPRT) 80 | { 81 | if ( !(cfr.getTopLevelParameterValue("sprt", "time_model", sprt.tM) && 82 | cfr.getTopLevelParameterValue("sprt", "models_per_sample", sprt.mS) && 83 | cfr.getTopLevelParameterValue("sprt", "delta", sprt.delta) && 84 | cfr.getTopLevelParameterValue("sprt", "epsilon", sprt.epsilon)) ) 85 | { 86 | return false; 87 | } 88 | } 89 | 90 | // read in local optimization parameters if required 91 | if (common.localOptMethod == USACConfig::LO_LOSAC) 92 | { 93 | if ( !(cfr.getTopLevelParameterValue("losac", "inner_sample_size", losac.innerSampleSize) && 94 | cfr.getTopLevelParameterValue("losac", "inner_ransac_repetitions", losac.innerRansacRepetitions) && 95 | cfr.getTopLevelParameterValue("losac", "threshold_multiplier", losac.thresholdMultiplier) && 96 | cfr.getTopLevelParameterValue("losac", "num_steps", losac.numStepsIterative)) ) 97 | { 98 | return false; 99 | } 100 | } 101 | } 102 | catch(...) 103 | { 104 | return false; 105 | } 106 | 107 | return true; 108 | } 109 | 110 | bool ConfigParams::initParamsFromConfigFile(std::string& configFilePath) { 111 | std::cerr << "Implement this in the derived class" << std::endl; 112 | return false; 113 | } -------------------------------------------------------------------------------- /cpp_libs/libUSAC/config/ConfigParams.h: -------------------------------------------------------------------------------- 1 | #ifndef CONFIGPARAMS_H 2 | #define CONFIGPARAMS_H 3 | 4 | #include 5 | #include "ConfigFileReader.h" 6 | 7 | namespace USACConfig 8 | { 9 | enum RandomSamplingMethod {SAMP_UNIFORM, SAMP_PROSAC, SAMP_UNIFORM_MM}; 10 | enum VerifMethod {VERIF_STANDARD, VERIF_SPRT}; 11 | enum LocalOptimizationMethod {LO_NONE, LO_LOSAC}; 12 | 13 | // common USAC parameters 14 | struct Common 15 | { 16 | // change these parameters according to the problem of choice 17 | Common(): confThreshold (0.95), 18 | minSampleSize (7), 19 | inlierThreshold (0.001), 20 | maxHypotheses (100000), 21 | maxSolutionsPerSample (3), 22 | numDataPoints (0), 23 | prevalidateSample (false), 24 | prevalidateModel (false), 25 | testDegeneracy (false), 26 | randomSamplingMethod (SAMP_UNIFORM), 27 | verifMethod (VERIF_STANDARD), 28 | localOptMethod (LO_NONE) 29 | {} 30 | double confThreshold; 31 | unsigned int minSampleSize; 32 | double inlierThreshold; 33 | unsigned int maxHypotheses; 34 | unsigned int maxSolutionsPerSample; 35 | unsigned int numDataPoints; 36 | bool prevalidateSample; 37 | bool prevalidateModel; 38 | bool testDegeneracy; 39 | RandomSamplingMethod randomSamplingMethod; 40 | VerifMethod verifMethod; 41 | LocalOptimizationMethod localOptMethod; 42 | }; 43 | 44 | // PROSAC parameters 45 | struct Prosac 46 | { 47 | Prosac(): maxSamples (200000), 48 | beta (0.05), 49 | nonRandConf (0.95), 50 | minStopLen (20), 51 | sortedPointsFile (""), // leave blank if not reading from file 52 | sortedPointIndices (NULL) // this should point to an array of point indices 53 | // sorted in decreasing order of quality scores 54 | {} 55 | unsigned int maxSamples; 56 | double beta; 57 | double nonRandConf; 58 | unsigned int minStopLen; 59 | std::string sortedPointsFile; 60 | unsigned int* sortedPointIndices; 61 | }; 62 | 63 | // SPRT parameters 64 | struct Sprt 65 | { 66 | Sprt(): tM (200.0), 67 | mS (2.38), 68 | delta (0.05), 69 | epsilon (0.2) 70 | {} 71 | double tM; 72 | double mS; 73 | double delta; 74 | double epsilon; 75 | }; 76 | 77 | // LOSAC parameters 78 | struct Losac 79 | { 80 | Losac(): innerSampleSize (14), 81 | innerRansacRepetitions (10), 82 | thresholdMultiplier (2.0), 83 | numStepsIterative (4) 84 | {} 85 | unsigned int innerSampleSize; 86 | unsigned int innerRansacRepetitions; 87 | double thresholdMultiplier; 88 | unsigned int numStepsIterative; 89 | }; 90 | 91 | } 92 | 93 | // main configuration struct that is passed to USAC 94 | class ConfigParams 95 | { 96 | public: 97 | // to be overridden to read in model specific data 98 | virtual bool initParamsFromConfigFile(std::string& configFilePath); 99 | 100 | // function to read in common usac parameters from config file 101 | bool initUSACParamsFromConfigFile(const ConfigFileReader& cfr); 102 | 103 | USACConfig::Common common; 104 | USACConfig::Prosac prosac; 105 | USACConfig::Sprt sprt; 106 | USACConfig::Losac losac; 107 | }; 108 | 109 | 110 | #endif -------------------------------------------------------------------------------- /cpp_libs/libUSAC/config/ConfigParamsFundmatrix.cpp: -------------------------------------------------------------------------------- 1 | #include "ConfigParamsFundmatrix.h" 2 | #include "ConfigFileReader.h" 3 | 4 | bool ConfigParamsFund::initParamsFromConfigFile(std::string &configFilePath) 5 | { 6 | // initialize the config file reader with the input config file 7 | ConfigFileReader cfr; 8 | try 9 | { 10 | cfr.readFile(configFilePath.c_str()); 11 | } 12 | catch(const libconfig::FileIOException) 13 | { 14 | std::cerr << "I/O error while reading file." << std::endl; 15 | return false; 16 | } 17 | catch(const libconfig::ParseException &pex) 18 | { 19 | std::cerr << "Parse error at " << pex.getFile() << ":" << pex.getLine() 20 | << " - " << pex.getError() << std::endl; 21 | return false; 22 | } 23 | 24 | // now read in parameters 25 | try 26 | { 27 | // usac parameters 28 | if (!initUSACParamsFromConfigFile(cfr)) 29 | { 30 | 31 | std::cerr << "Error reading USAC parameters from config file." << std::endl; 32 | return false; 33 | } 34 | 35 | // fundmatrix parameters 36 | if ( !cfr.getTopLevelParameterValue("problem_specific", "input_file_path", fund.inputFilePath) ) 37 | { 38 | return false; 39 | } 40 | 41 | if ( common.testDegeneracy ) 42 | { 43 | if ( !(cfr.getTopLevelParameterValue("problem_specific", "h_degen_threshold", fund.hDegenThreshold) && 44 | cfr.getTopLevelParameterValue("problem_specific", "max_upgrade_samples", fund.maxUpgradeSamples) )) 45 | { 46 | return false; 47 | } 48 | } 49 | 50 | std::string decomp_type; 51 | if ( !cfr.getTopLevelParameterValue("problem_specific", "matrix_decomposition", decomp_type) ) 52 | { 53 | return false; 54 | } 55 | if (decomp_type.compare("LU") == 0) 56 | { 57 | fund.decompositionAlg = USACConfig::DECOMP_LU; 58 | } 59 | else if (decomp_type.compare("QR") == 0) 60 | { 61 | fund.decompositionAlg = USACConfig::DECOMP_QR; 62 | } 63 | else 64 | { 65 | std::cerr << "Matrix decomposition " << decomp_type << " not supported" << std::endl; 66 | return false; 67 | } 68 | } 69 | catch(...) 70 | { 71 | return false; 72 | } 73 | 74 | return true; 75 | } -------------------------------------------------------------------------------- /cpp_libs/libUSAC/config/ConfigParamsFundmatrix.h: -------------------------------------------------------------------------------- 1 | #ifndef CONFIGPARAMSFUND_H 2 | #define CONFIGPARAMSFUND_H 3 | 4 | #include "ConfigParams.h" 5 | 6 | namespace USACConfig 7 | { 8 | enum MatrixDecomposition {DECOMP_QR, DECOMP_LU}; 9 | 10 | // problem specific/data-related parameters: fundamental matrix 11 | struct Fund 12 | { 13 | Fund(): decompositionAlg (DECOMP_QR), 14 | hDegenThreshold (0.0), 15 | maxUpgradeSamples (500), 16 | inputFilePath ("") // leave blank if not using config file 17 | {} 18 | 19 | MatrixDecomposition decompositionAlg; 20 | double hDegenThreshold; 21 | unsigned int maxUpgradeSamples; 22 | std::string inputFilePath; 23 | }; 24 | } 25 | 26 | class ConfigParamsFund: public ConfigParams 27 | { 28 | public: 29 | // simple function to read in parameters from config file 30 | bool initParamsFromConfigFile(std::string& configFilePath); 31 | 32 | USACConfig::Fund fund; 33 | }; 34 | 35 | #endif -------------------------------------------------------------------------------- /cpp_libs/libUSAC/config/ConfigParamsHomog.cpp: -------------------------------------------------------------------------------- 1 | #include "ConfigParamsHomog.h" 2 | #include "ConfigFileReader.h" 3 | 4 | bool ConfigParamsHomog::initParamsFromConfigFile(std::string &configFilePath) 5 | { 6 | // initialize the config file reader with the input config file 7 | ConfigFileReader cfr; 8 | try 9 | { 10 | cfr.readFile(configFilePath.c_str()); 11 | } 12 | catch(const libconfig::FileIOException) 13 | { 14 | std::cerr << "I/O error while reading file." << std::endl; 15 | return false; 16 | } 17 | catch(const libconfig::ParseException &pex) 18 | { 19 | std::cerr << "Parse error at " << pex.getFile() << ":" << pex.getLine() 20 | << " - " << pex.getError() << std::endl; 21 | return false; 22 | } 23 | 24 | // now read in parameters 25 | try 26 | { 27 | // usac parameters 28 | if (!initUSACParamsFromConfigFile(cfr)) 29 | { 30 | 31 | std::cerr << "Error reading USAC parameters from config file." << std::endl; 32 | return false; 33 | } 34 | 35 | // homog parameters 36 | if ( !cfr.getTopLevelParameterValue("problem_specific", "input_file_path", homog.inputFilePath) ) 37 | { 38 | return false; 39 | } 40 | } 41 | catch(...) 42 | { 43 | return false; 44 | } 45 | 46 | return true; 47 | } -------------------------------------------------------------------------------- /cpp_libs/libUSAC/config/ConfigParamsHomog.h: -------------------------------------------------------------------------------- 1 | #ifndef CONFIGPARAMSHOMOG_H 2 | #define CONFIGPARAMSHOMOG_H 3 | 4 | #include "ConfigParams.h" 5 | 6 | namespace USACConfig 7 | { 8 | // problem specific/data-related parameters: fundamental matrix 9 | struct Homog 10 | { 11 | Homog(): inputFilePath ("") // leave blank if not using config file 12 | {} 13 | 14 | std::string inputFilePath; 15 | }; 16 | } 17 | 18 | class ConfigParamsHomog: public ConfigParams 19 | { 20 | public: 21 | // simple function to read in parameters from config file 22 | bool initParamsFromConfigFile(std::string& configFilePath); 23 | 24 | USACConfig::Homog homog; 25 | }; 26 | 27 | #endif -------------------------------------------------------------------------------- /cpp_libs/libUSAC/fundamental.cfg: -------------------------------------------------------------------------------- 1 | // example configuration file for fundamental matrix estimation 2 | 3 | // ======================================================================================== 4 | // common RANSAC parameters 5 | 6 | common = 7 | { 8 | // ransac_conf: 0.0 - 1.0 (must be float) 9 | // specifies the confidence parameter 10 | ransac_conf = 0.99; 11 | 12 | // min_sample_size: int 13 | // number of points used to generate models 14 | min_sample_size = 7; 15 | 16 | // inlier_threshold: float 17 | // threshold for inlier classification 18 | inlier_threshold = 1.5; 19 | 20 | // max_hypotheses: int 21 | // maximum number of samples to be drawn before aborting 22 | max_hypotheses = 850000; 23 | 24 | // max_solutions_per_sample: int 25 | // number of possible solutions using the minimal sample 26 | max_solutions_per_sample = 3; 27 | 28 | // prevalidate_sample: true, false 29 | // specifies whether samples are to be prevalidated prior to model generation 30 | prevalidate_sample = true; 31 | 32 | // prevalidate_model: true, false 33 | // specifies whether models are to be prevalidated prior to verification against data points 34 | prevalidate_model = true; 35 | 36 | // degen_check: true, false 37 | // specifies whether degeneracy testing is to be performed 38 | degen_check = true; 39 | 40 | // random_sampling_method: UNIFORM, PROSAC (string) 41 | // specifies the type of random sampling to be used to generate hypotheses 42 | random_sampling_method = "UNIFORM"; 43 | 44 | // verif_method: STANDARD, SPRT (string) 45 | // specifies the type of model verification to be performed 46 | verif_method = "SPRT"; 47 | 48 | // local_opt: NO_LO, LOSAC (string) 49 | // specifies what type of local optimization is to be performed 50 | local_opt = "LOSAC"; 51 | }; 52 | 53 | 54 | // ======================================================================================== 55 | // PROSAC parameters 56 | 57 | prosac = 58 | { 59 | // max_prosac_samples: int 60 | // number of samples after which PROSAC behaves like RANSAC 61 | max_prosac_samples = 100000; 62 | 63 | // beta: float 64 | // probability of incorrect model being support by a random data point 65 | // can be adapted to use values from sprt 66 | beta = 0.09; 67 | 68 | // min_stopping_length: int 69 | min_stopping_length = 20; 70 | 71 | // non_rand_conf: float 72 | // find non-minimal subset with probability of randomness smaller than (1-non_rand_conf) 73 | non_rand_conf = 0.99; 74 | 75 | // sorted_points_path: string 76 | // path to file containing indices of points sorted by quality scores 77 | sorted_points_path = "./sorting.txt"; 78 | }; 79 | 80 | 81 | // ======================================================================================== 82 | // SPRT parameters 83 | 84 | sprt = 85 | { 86 | time_model = 200.0; 87 | 88 | models_per_sample = 2.38; 89 | 90 | delta = 0.05; 91 | 92 | epsilon = 0.15; 93 | }; 94 | 95 | 96 | // ======================================================================================== 97 | // Local optimization parameters 98 | 99 | losac = 100 | { 101 | inner_sample_size = 15; 102 | 103 | inner_ransac_repetitions = 5; 104 | 105 | threshold_multiplier = 2.0; 106 | 107 | num_steps = 4; 108 | }; 109 | 110 | 111 | // ======================================================================================== 112 | // Problem specific parameters 113 | 114 | problem_specific = 115 | { 116 | // matrix_decomposition: QR, LU 117 | matrix_decomposition = "QR"; 118 | 119 | // h_degen_threshold: float 120 | // inlier threshold for the h-degeneracy test (set to 0.0 if not being used) 121 | h_degen_threshold = 6.5; 122 | 123 | // max_upgrade_samples: int 124 | // maximum number of 2-point samples to draw in the model upgrade loop 125 | max_upgrade_samples = 8000; 126 | 127 | // path to file containing the input points 128 | input_file_path = "./orig_pts.txt"; 129 | 130 | }; 131 | -------------------------------------------------------------------------------- /cpp_libs/libUSAC/homography.cfg: -------------------------------------------------------------------------------- 1 | // example configuration file for fundamental matrix estimation 2 | 3 | // ======================================================================================== 4 | // common RANSAC parameters 5 | 6 | common = 7 | { 8 | // ransac_conf: 0.0 - 1.0 (must be float) 9 | // specifies the confidence parameter 10 | ransac_conf = 0.99; 11 | 12 | // min_sample_size: int 13 | // number of points used to generate models 14 | min_sample_size = 4; 15 | 16 | // inlier_threshold: float 17 | // threshold for inlier classification 18 | inlier_threshold = 2.0; 19 | 20 | // max_hypotheses: int 21 | // maximum number of samples to be drawn before aborting 22 | max_hypotheses = 850000; 23 | 24 | // max_solutions_per_sample: int 25 | // number of possible solutions using the minimal sample 26 | max_solutions_per_sample = 1; 27 | 28 | // prevalidate_sample: true, false 29 | // specifies whether samples are to be prevalidated prior to model generation 30 | prevalidate_sample = true; 31 | 32 | // prevalidate_model: true, false 33 | // specifies whether models are to be prevalidated prior to verification against data points 34 | prevalidate_model = true; 35 | 36 | // degen_check: true, false 37 | // specifies whether degeneracy testing is to be performed 38 | degen_check = true; 39 | 40 | // random_sampling_method: UNIFORM, PROSAC (string) 41 | // specifies the type of random sampling to be used to generate hypotheses 42 | //random_sampling_method = "PROSAC"; 43 | random_sampling_method = "UNIFORM"; 44 | 45 | // verif_method: STANDARD, SPRT (string) 46 | // specifies the type of model verification to be performed 47 | verif_method = "SPRT"; 48 | 49 | // local_opt: NO_LO, LOSAC (string) 50 | // specifies what type of local optimization is to be performed 51 | local_opt = "LOSAC"; 52 | }; 53 | 54 | 55 | // ======================================================================================== 56 | // PROSAC parameters 57 | 58 | prosac = 59 | { 60 | // max_prosac_samples: int 61 | // number of samples after which PROSAC behaves like RANSAC 62 | max_prosac_samples = 500000; 63 | 64 | // beta: float 65 | // probability of incorrect model being support by a random data point 66 | // can be adapted to use values from sprt 67 | beta = 0.09; 68 | 69 | // min_stopping_length: int 70 | min_stopping_length = 20; 71 | 72 | // non_rand_conf: float 73 | // find non-minimal subset with probability of randomness smaller than (1-non_rand_conf) 74 | non_rand_conf = 0.99; 75 | 76 | // sorted_points_path: string 77 | // path to file containing indices of points sorted by quality scores 78 | sorted_points_path = "./sorting.txt"; 79 | }; 80 | 81 | 82 | // ======================================================================================== 83 | // SPRT parameters 84 | 85 | sprt = 86 | { 87 | time_model = 100.0; 88 | 89 | models_per_sample = 1.0; 90 | 91 | delta = 0.01; 92 | 93 | epsilon = 0.2; 94 | }; 95 | 96 | 97 | // ======================================================================================== 98 | // Local optimization parameters 99 | 100 | losac = 101 | { 102 | inner_sample_size = 12; 103 | 104 | inner_ransac_repetitions = 3; 105 | 106 | threshold_multiplier = 2.0; 107 | 108 | num_steps = 4; 109 | }; 110 | 111 | 112 | // ======================================================================================== 113 | // Problem specific parameters 114 | 115 | problem_specific = 116 | { 117 | // path to file containing the (normalized) input points 118 | input_file_path = "./orig_pts.txt"; 119 | }; 120 | -------------------------------------------------------------------------------- /cpp_libs/libUSAC/utils/FundmatrixFunctions.h: -------------------------------------------------------------------------------- 1 | #ifndef FTOOLS_H 2 | #define FTOOLS_H 3 | #include 4 | #include "MathFunctions.h" 5 | 6 | namespace FTools 7 | { 8 | void normalizePoints(double* inputPointsUnNorm, double* inputPoints, unsigned int numPoints, 9 | double* T1, double* T2); 10 | void computeDataMatrix(double* data_matrix, unsigned int num_points, double* points); 11 | int nullspaceQR7x9(const double* A, double* N); 12 | int nullspace(double* matrix, double* nullspace, int n, int* buffer); 13 | void makePolynomial(double* A, double* B, double* p); 14 | unsigned int rroots3 (double* po, double* r); 15 | void formCovMat(double* Cv, const double* A, unsigned int len, unsigned int siz); 16 | void singulF(double* F); 17 | void computeEpipole(double* e, const double* F); 18 | double getOriSign(double* F, double* e, double* pt); 19 | void computeHFromF(const std::vector& sample, double* u, double* ep, double* F, double* H); 20 | unsigned int getHError(const std::vector& test, unsigned int numPoints, std::vector& errs, 21 | double* u, double* H, double threshold); 22 | unsigned int computeHFromCorrs(const std::vector& sample, unsigned int numPoints, 23 | unsigned int numDataPoints, double* u, double* H); 24 | unsigned int computeHFromMinCorrs(const std::vector& sample, unsigned int numPoints, 25 | unsigned int numDataPoints, double* u, double* H); 26 | } 27 | #endif 28 | -------------------------------------------------------------------------------- /cpp_libs/libUSAC/utils/HomographyFunctions.cpp: -------------------------------------------------------------------------------- 1 | #include "HomographyFunctions.h" 2 | 3 | namespace HTools 4 | { 5 | 6 | void computeDataMatrix(double* data_matrix, unsigned int num_points, double* points) 7 | { 8 | // linearizes corresp. with respect to entries of homography matrix, 9 | // so that u' = H u -> A h 10 | 11 | const double *data_ptr; 12 | double *p; 13 | unsigned int offset = 2*num_points; 14 | 15 | for (unsigned int i = 0; i < num_points; ++i) 16 | { 17 | data_ptr = points + 6*i; 18 | p = data_matrix + 2*i; 19 | 20 | *p = 0; 21 | *(p + offset) = 0; 22 | *(p + 2*offset) = 0; 23 | *(p + 3*offset) = -data_ptr[0]; 24 | *(p + 4*offset) = -data_ptr[1]; 25 | *(p + 5*offset) = -data_ptr[2]; 26 | *(p + 6*offset) = data_ptr[4] * data_ptr[0]; 27 | *(p + 7*offset) = data_ptr[4] * data_ptr[1]; 28 | *(p + 8*offset) = data_ptr[4] * data_ptr[2]; 29 | 30 | p = data_matrix + 2*i + 1; 31 | 32 | *p = data_ptr[0]; 33 | *(p + offset) = data_ptr[1]; 34 | *(p + 2*offset) = data_ptr[2]; 35 | *(p + 3*offset) = 0; 36 | *(p + 4*offset) = 0; 37 | *(p + 5*offset) = 0; 38 | *(p + 6*offset) = -data_ptr[3] * data_ptr[0]; 39 | *(p + 7*offset) = -data_ptr[3] * data_ptr[1]; 40 | *(p + 8*offset) = -data_ptr[3] * data_ptr[2]; 41 | } 42 | } // end computeDataMatrix 43 | 44 | void crossprod(double *out, const double *a, const double *b, unsigned int st) 45 | { 46 | unsigned int st2 = 2 * st; 47 | out[0] = a[st]*b[st2] - a[st2]*b[st]; 48 | out[1] = a[st2]*b[0] - a[0]*b[st2]; 49 | out[2] = a[0]*b[st] - a[st]*b[0]; 50 | } 51 | 52 | } -------------------------------------------------------------------------------- /cpp_libs/libUSAC/utils/HomographyFunctions.h: -------------------------------------------------------------------------------- 1 | #ifndef HTOOLS_H 2 | #define HTOOLS_H 3 | 4 | #include "MathFunctions.h" 5 | 6 | namespace HTools 7 | { 8 | void computeDataMatrix(double* data_matrix, unsigned int num_points, double* points); 9 | void crossprod(double *out, const double *a, const double *b, unsigned int st); 10 | } 11 | #endif -------------------------------------------------------------------------------- /cpp_libs/libUSAC/utils/MathFunctions.h: -------------------------------------------------------------------------------- 1 | #ifndef MATHFUNCTIONS_H 2 | #define MATHFUNCTIONS_H 3 | 4 | #include 5 | #include 6 | 7 | namespace MathTools 8 | { 9 | typedef int integer; 10 | typedef double doublereal; 11 | 12 | extern "C" { 13 | int dgeqp3_(integer const *m, 14 | integer const *n, 15 | doublereal *a, 16 | integer const *lda, 17 | integer *jpvt, 18 | doublereal *tau, 19 | doublereal *work, 20 | integer *lwork, 21 | integer *info); 22 | } 23 | 24 | // the below functions are from ccmath 25 | int svdu1v(double *d, double *a, int m, double *v, int n); 26 | int svduv(double *d, double *a, double *u, int m, double *v, int n); 27 | void ldumat(double *x, double *y, int i, int k); 28 | void ldvmat(double *x, double *y, int k); 29 | void atou1(double *r, int i, int j); 30 | int qrbdu1(double *w, double *x, double *y, int k, double *z, int l); 31 | int qrbdv(double *x, double *y, double *z, int i, double *w, int j); 32 | int minv(double *a,int n); 33 | void vmul(double *vp,double *mat,double *v,int n); 34 | void mattr(double *a,double *b,int m,int n) ; 35 | void skew_sym(double *A, double *a); 36 | void mmul(double *c,double *a,double *b,int n); 37 | void crossprod(double *out, const double *a, const double *b, unsigned int st); 38 | void trnm(double *a,int n); 39 | } 40 | #endif 41 | -------------------------------------------------------------------------------- /cpp_libs/vl/aib.h: -------------------------------------------------------------------------------- 1 | /** @file aib.h 2 | ** @brief AIB (@ref aib) 3 | ** @author Brian Fulkerson 4 | ** @author Andrea Vedaldi 5 | **/ 6 | 7 | /* 8 | Copyright (C) 2007-12 Andrea Vedaldi and Brian Fulkerson. 9 | All rights reserved. 10 | 11 | This file is part of the VLFeat library and is made available under 12 | the terms of the BSD license (see the COPYING file). 13 | */ 14 | 15 | #ifndef VL_AIB_H 16 | #define VL_AIB_H 17 | 18 | #include "generic.h" 19 | #include "mathop.h" 20 | 21 | /** ------------------------------------------------------------------ 22 | ** @internal 23 | ** @brief AIB algorithm data 24 | ** 25 | ** The implementation is quite straightforward, but the way feature 26 | ** values are handled in order to support efficient joins, 27 | ** deletions and re-arrangement needs to be explained. This is 28 | ** achieved by adding a layer of indirection: 29 | ** - Call each feature value (either original or obtained by a join 30 | ** operation) a node. Nodes are identified by numbers. 31 | ** - Call each element of the various arrays (such as VlAIB::Px) 32 | ** an entry. 33 | ** - Entries are dynamically associated to nodes as specified by 34 | ** VlAIB::nodes. For example, @c Px[i] refers to the node @c 35 | ** nodes[i]. 36 | **/ 37 | 38 | typedef struct _VlAIB 39 | { 40 | vl_uint *nodes ; /**< Entires to nodes */ 41 | vl_uint nentries ; /**< Total number of entries (= # active nodes) */ 42 | double *beta ; /**< Minimum distance to an entry */ 43 | vl_uint *bidx ; /**< Closest entry */ 44 | 45 | 46 | vl_uint *which ; /**< List of entries to update */ 47 | vl_uint nwhich ; /**< Number of entries to update */ 48 | 49 | double *Pcx; /**< Joint probability table */ 50 | double *Px; /**< Marginal. */ 51 | double *Pc; /**< Marginal. */ 52 | vl_uint nvalues; /**< Number of feature values */ 53 | vl_uint nlabels; /**< Number of labels */ 54 | 55 | vl_uint *parents; /**< Array of parents */ 56 | double *costs; /**< Cost of each merge */ 57 | 58 | vl_uint verbosity ; /** Verbosity level */ 59 | } VlAIB; 60 | 61 | /** @name Create and destroy 62 | ** @{ 63 | **/ 64 | VL_EXPORT 65 | VlAIB * vl_aib_new(double * Pcx, vl_uint nvalues, vl_uint nlabels); 66 | 67 | VL_EXPORT 68 | void vl_aib_delete (VlAIB * aib); 69 | /** @} */ 70 | 71 | /** @name Process data 72 | ** @{ 73 | **/ 74 | VL_EXPORT 75 | void vl_aib_process(VlAIB * aib); 76 | /** @} */ 77 | 78 | /** @name Retrieve results 79 | ** @{ 80 | **/ 81 | VL_INLINE vl_uint * vl_aib_get_parents(VlAIB const * aib); 82 | VL_INLINE double * vl_aib_get_costs(VlAIB const * aib); 83 | /** @} */ 84 | 85 | 86 | /* ------------------------------------------------------------------- 87 | * Inline functions implementation 88 | * ---------------------------------------------------------------- */ 89 | 90 | /** ------------------------------------------------------------------ 91 | ** @brief Get resulting list of parents 92 | ** @param aib AIB filter. 93 | ** @return An array of parents 94 | **/ 95 | VL_INLINE 96 | vl_uint * vl_aib_get_parents(VlAIB const * aib) 97 | { 98 | return aib->parents; 99 | } 100 | 101 | /** ------------------------------------------------------------------ 102 | ** @brief Get a list of merge costs 103 | ** @param aib AIB filter. 104 | ** @return An array of costs 105 | **/ 106 | VL_INLINE 107 | double * vl_aib_get_costs(VlAIB const * aib) 108 | { 109 | return aib->costs; 110 | } 111 | 112 | /* ----------------------------------------------------------------- */ 113 | /** @brief Set the verbosity 114 | ** @param self AIB object. 115 | ** @param verbosity a non-negative integer. 116 | **/ 117 | VL_INLINE void 118 | vl_aib_set_verbosity (VlAIB * self, int verbosity) 119 | { 120 | self->verbosity = verbosity ; 121 | } 122 | 123 | /** @brief Get the verbosity 124 | ** @param self AIB object. 125 | ** @return the verbosity level. 126 | **/ 127 | VL_INLINE int 128 | vl_aib_get_verbosity (VlAIB const * self) 129 | { 130 | return self->verbosity ; 131 | } 132 | 133 | /* VL_AIB_H */ 134 | #endif 135 | -------------------------------------------------------------------------------- /cpp_libs/vl/array.h: -------------------------------------------------------------------------------- 1 | /** @file array.h 2 | ** @brief Array - Definition 3 | ** @author Andrea Vedaldi 4 | **/ 5 | 6 | /* 7 | Copyright (C) 2007-12 Andrea Vedaldi and Brian Fulkerson. 8 | All rights reserved. 9 | 10 | This file is part of the VLFeat library and is made available under 11 | the terms of the BSD license (see the COPYING file). 12 | */ 13 | 14 | #ifndef VL_ARRAY_H 15 | #define VL_ARRAY_H 16 | 17 | #include "generic.h" 18 | 19 | /** @brief Maximum number of array dimensions */ 20 | #define VL_ARRAY_MAX_NUM_DIMENSIONS 16 21 | 22 | /** @brief Numeric array */ 23 | typedef struct _VlArray 24 | { 25 | vl_type type ; 26 | vl_bool isEnvelope ; 27 | vl_bool isSparse ; 28 | vl_size numDimensions ; 29 | vl_size dimensions [VL_ARRAY_MAX_NUM_DIMENSIONS] ; 30 | void * data ; 31 | void * rowPointers ; 32 | void * columnPointers ; 33 | } VlArray ; 34 | 35 | 36 | /** @name Get data and parameters 37 | ** @{ */ 38 | 39 | /** @brief Get number of dimensions 40 | ** @param self array. 41 | ** @return number of dimensions. 42 | **/ 43 | 44 | VL_INLINE vl_size 45 | vl_array_get_num_dimensions (VlArray const * self) 46 | { 47 | return self->numDimensions ; 48 | } 49 | 50 | /** @brief Get dimensions 51 | ** @param self array. 52 | ** @return dimensions. 53 | **/ 54 | 55 | VL_INLINE vl_size const * 56 | vl_array_get_dimensions (VlArray const * self) 57 | { 58 | return self->dimensions ; 59 | } 60 | 61 | /** @brief Get data 62 | ** @param self array. 63 | ** @return data. 64 | **/ 65 | 66 | VL_INLINE void * 67 | vl_array_get_data (VlArray const * self) 68 | { 69 | return self->data; 70 | } 71 | 72 | /** @brief Get type 73 | ** @param self array. 74 | ** @return type. 75 | **/ 76 | 77 | VL_INLINE vl_type 78 | vl_array_get_data_type (VlArray const * self) 79 | { 80 | return self->type ; 81 | } 82 | 83 | VL_EXPORT vl_size vl_array_get_num_elements (VlArray const * self) ; 84 | 85 | /** @{ */ 86 | 87 | /** @name Constructing and destroying 88 | ** @{ */ 89 | 90 | VL_EXPORT VlArray * vl_array_init (VlArray * self, vl_type type, vl_size numDimension, vl_size const * dimensions) ; 91 | VL_EXPORT VlArray * vl_array_init_envelope (VlArray *self, void * data, vl_type type, vl_size numDimension, vl_size const * dimensions) ; 92 | VL_EXPORT VlArray * vl_array_init_matrix (VlArray * self, vl_type type, vl_size numRows, vl_size numColumns) ; 93 | VL_EXPORT VlArray * vl_array_init_matrix_envelope (VlArray * self, void * data, vl_type type, vl_size numRows, vl_size numColumns) ; 94 | 95 | VL_EXPORT VlArray * vl_array_new (vl_type type, vl_size numDimension, vl_size const * dimensions) ; 96 | VL_EXPORT VlArray * vl_array_new_envelope (void * data, vl_type type, vl_size numDimension, vl_size const * dimensions) ; 97 | VL_EXPORT VlArray * vl_array_new_matrix (vl_type type, vl_size numRows, vl_size numColumns) ; 98 | VL_EXPORT VlArray * vl_array_new_matrix_envelope (void * data, vl_type type, vl_size numRows, vl_size numColumns) ; 99 | 100 | VL_EXPORT void vl_array_dealloc (VlArray * self) ; 101 | VL_EXPORT void vl_array_delete (VlArray * self) ; 102 | /** @} */ 103 | 104 | /* VL_ARRAY_H */ 105 | #endif 106 | -------------------------------------------------------------------------------- /cpp_libs/vl/fisher.h: -------------------------------------------------------------------------------- 1 | /** @file fisher.h 2 | ** @brief Fisher encoding (@ref fisher) 3 | ** @author David Novotny 4 | ** @author Andrea Vedaldi 5 | ** @see @ref fisher 6 | **/ 7 | 8 | /* 9 | Copyright (C) 2013 David Novotny and Andrea Vedaldi. 10 | All rights reserved. 11 | 12 | This file is part of the VLFeat library and is made available under 13 | the terms of the BSD license (see the COPYING file). 14 | */ 15 | 16 | #ifndef VL_FISHER_H 17 | #define VL_FISHER_H 18 | 19 | #include "generic.h" 20 | 21 | /** @name Fisher vector options 22 | ** @{ */ 23 | #define VL_FISHER_FLAG_SQUARE_ROOT (0x1 << 0) 24 | #define VL_FISHER_FLAG_NORMALIZED (0x1 << 1) 25 | #define VL_FISHER_FLAG_IMPROVED (VL_FISHER_FLAG_NORMALIZED|VL_FISHER_FLAG_SQUARE_ROOT) 26 | #define VL_FISHER_FLAG_FAST (0x1 << 2) 27 | 28 | /** @def VL_FISHER_FLAG_SQUARE_ROOT 29 | ** @brief Use signed squared-root (@ref fisher-normalization). 30 | **/ 31 | 32 | /** @def VL_FISHER_FLAG_NORMALIZED 33 | ** @brief Gobally normalize the Fisher vector in L2 norm (@ref fisher-normalization). 34 | **/ 35 | 36 | /** @def VL_FISHER_FLAG_IMPROVED 37 | ** @brief Improved Fisher vector. 38 | ** This is the same as @c VL_FISHER_FLAG_SQUARE_ROOT|VL_FISHER_FLAG_NORMALIZED. 39 | **/ 40 | 41 | /** @def VL_FISHER_FLAG_FAST 42 | ** @brief Fast but more approximate calculations (@ref fisher-fast). 43 | ** Keep only the larges data to cluster assignment (posterior). 44 | **/ 45 | 46 | /** @} */ 47 | 48 | VL_EXPORT vl_size vl_fisher_encode 49 | (void * enc, vl_type dataType, 50 | void const * means, vl_size dimension, vl_size numClusters, 51 | void const * covariances, 52 | void const * priors, 53 | void const * data, vl_size numData, 54 | int flags) ; 55 | 56 | /* VL_FISHER_H */ 57 | #endif 58 | -------------------------------------------------------------------------------- /cpp_libs/vl/float.th: -------------------------------------------------------------------------------- 1 | /** @file float.th 2 | ** @brief Float - Template 3 | ** @author Andrea Vedaldi 4 | ** @author David Novotny 5 | **/ 6 | 7 | /* 8 | Copyright (C) 2014 Andrea Vedaldi. 9 | Copyright (C) 2013 David Novotny. 10 | Copyright (C) 2007-12 Andrea Vedaldi and Brian Fulkerson. 11 | All rights reserved. 12 | 13 | This file is part of the VLFeat library and is made available under 14 | the terms of the BSD license (see the COPYING file). 15 | */ 16 | 17 | #include "generic.h" 18 | 19 | #undef T 20 | #undef SFX 21 | #undef VSIZE 22 | #undef VSFX 23 | #undef VTYPE 24 | #undef VSIZEavx 25 | #undef VSFXavx 26 | #undef VTYPEavx 27 | 28 | #if (FLT == VL_TYPE_FLOAT) 29 | # define T float 30 | # define SFX f 31 | #elif (FLT == VL_TYPE_DOUBLE) 32 | # define T double 33 | # define SFX d 34 | #elif (FLT == VL_TYPE_UINT32) 35 | # define T vl_uint32 36 | # define SFX ui32 37 | #elif (FLT == VL_TYPE_INT32) 38 | # define T vl_int32 39 | # define SFX i32 40 | #endif 41 | 42 | /* ---------------------------------------------------------------- */ 43 | /* AVX */ 44 | /* ---------------------------------------------------------------- */ 45 | 46 | #ifdef __AVX__ 47 | 48 | #if (FLT == VL_TYPE_FLOAT) 49 | # define VSIZEavx 8 50 | # define VSFXavx s 51 | # define VTYPEavx __m256 52 | #elif (FLT == VL_TYPE_DOUBLE) 53 | # define VSIZEavx 4 54 | # define VSFXavx d 55 | # define VTYPEavx __m256d 56 | #endif 57 | 58 | #define VALIGNEDavx(x) (! (((vl_uintptr)(x)) & 0x1F)) 59 | 60 | #define VMULavx VL_XCAT(_mm256_mul_p, VSFX) 61 | #define VDIVavx VL_XCAT(_mm256_div_p, VSFX) 62 | #define VADDavx VL_XCAT(_mm256_add_p, VSFX) 63 | #define VHADDavx VL_XCAT(_mm_hadd_p, VSFX) 64 | #define VHADD2avx VL_XCAT(_mm256_hadd_p, VSFX) 65 | #define VSUBavx VL_XCAT(_mm256_sub_p, VSFX) 66 | #define VSTZavx VL_XCAT(_mm256_setzero_p, VSFX) 67 | #define VLD1avx VL_XCAT(_mm256_broadcast_s, VSFX) 68 | #define VLDUavx VL_XCAT(_mm256_loadu_p, VSFX) 69 | #define VST1avx VL_XCAT(_mm256_store_s, VSFX) 70 | #define VST2avx VL_XCAT(_mm256_store_p, VSFX) 71 | #define VST2Uavx VL_XCAT(_mm256_storeu_p, VSFX) 72 | #define VPERMavx VL_XCAT(_mm256_permute2f128_p, VSFX) 73 | //#define VCSTavx VL_XCAT( _mm256_castps256_ps128, VSFX) 74 | #define VCSTavx VL_XCAT5(_mm256_castp,VSFX,256_p,VSFX,128) 75 | 76 | /* __AVX__ */ 77 | #endif 78 | 79 | /* ---------------------------------------------------------------- */ 80 | /* SSE2 */ 81 | /* ---------------------------------------------------------------- */ 82 | 83 | #ifdef __SSE2__ 84 | 85 | #if (FLT == VL_TYPE_FLOAT) 86 | # define VSIZE 4 87 | # define VSFX s 88 | # define VTYPE __m128 89 | #elif (FLT == VL_TYPE_DOUBLE) 90 | # define VSIZE 2 91 | # define VSFX d 92 | # define VTYPE __m128d 93 | #endif 94 | 95 | #define VALIGNED(x) (! (((vl_uintptr)(x)) & 0xF)) 96 | 97 | #define VMAX VL_XCAT(_mm_max_p, VSFX) 98 | #define VMUL VL_XCAT(_mm_mul_p, VSFX) 99 | #define VDIV VL_XCAT(_mm_div_p, VSFX) 100 | #define VADD VL_XCAT(_mm_add_p, VSFX) 101 | #define VSUB VL_XCAT(_mm_sub_p, VSFX) 102 | #define VSTZ VL_XCAT(_mm_setzero_p, VSFX) 103 | #define VLD1 VL_XCAT(_mm_load1_p, VSFX) 104 | #define VLDU VL_XCAT(_mm_loadu_p, VSFX) 105 | #define VST1 VL_XCAT(_mm_store_s, VSFX) 106 | #define VSET1 VL_XCAT(_mm_set_s, VSFX) 107 | #define VSHU VL_XCAT(_mm_shuffle_p, VSFX) 108 | #define VNEQ VL_XCAT(_mm_cmpneq_p, VSFX) 109 | #define VAND VL_XCAT(_mm_and_p, VSFX) 110 | #define VANDN VL_XCAT(_mm_andnot_p, VSFX) 111 | #define VST2 VL_XCAT(_mm_store_p, VSFX) 112 | #define VST2U VL_XCAT(_mm_storeu_p, VSFX) 113 | 114 | /* __SSE2__ */ 115 | #endif 116 | 117 | -------------------------------------------------------------------------------- /cpp_libs/vl/getopt_long.h: -------------------------------------------------------------------------------- 1 | /** @file getopt_long.h 2 | ** @brief getopt_long 3 | ** @author Andrea Vedaldi 4 | **/ 5 | 6 | /* 7 | Copyright (C) 2007-12 Andrea Vedaldi and Brian Fulkerson. 8 | All rights reserved. 9 | 10 | This file is part of the VLFeat library and is made available under 11 | the terms of the BSD license (see the COPYING file). 12 | */ 13 | 14 | #ifndef VL_GETOPT_LONG_H 15 | #define VL_GETOPT_LONG_H 16 | 17 | #include "generic.h" 18 | 19 | VL_EXPORT int opterr ; /**< code of the last error occured while parsing an option */ 20 | VL_EXPORT int optind ; /**< index of the next option to process in @c argv */ 21 | VL_EXPORT int optopt ; /**< current option */ 22 | VL_EXPORT char * optarg ; /**< argument of the current option */ 23 | VL_EXPORT int optreset ; /**< reset flag */ 24 | 25 | /** @brief ::getopt_long option */ 26 | struct option 27 | { 28 | const char *name ; /**< option long name */ 29 | int has_arg ; /**< flag indicating whether the option has no, required or optional argument */ 30 | int *flag ; /**< pointer to a variable to set (if @c NULL, the value is returned instead) */ 31 | int val ; /**< value to set or to return */ 32 | } ; 33 | 34 | #define no_argument 0 /**< ::option with no argument */ 35 | #define required_argument 1 /**< ::option with required argument */ 36 | #define optional_argument 2 /**< ::option with optional argument */ 37 | 38 | VL_EXPORT int getopt_long(int argc, char * const argv[], 39 | const char * optstring, 40 | const struct option * longopts, int * longindex); 41 | 42 | /* VL_GETOPT_LONG_H */ 43 | #endif 44 | -------------------------------------------------------------------------------- /cpp_libs/vl/gmm.h: -------------------------------------------------------------------------------- 1 | /** @file gmm.h 2 | ** @brief GMM (@ref gmm) 3 | ** @author David Novotny 4 | ** @author Andrea Vedaldi 5 | **/ 6 | 7 | /* 8 | Copyright (C) 2013 David Novotny and Andrea Vedaldi. 9 | All rights reserved. 10 | 11 | This file is part of the VLFeat library and is made available under 12 | the terms of the BSD license (see the COPYING file). 13 | */ 14 | 15 | #ifndef VL_GMM_H 16 | #define VL_GMM_H 17 | 18 | #include "kmeans.h" 19 | 20 | /** @brief GMM initialization algorithms */ 21 | typedef enum _VlGMMInitialization 22 | { 23 | VlGMMKMeans, /**< Initialize GMM from KMeans clustering. */ 24 | VlGMMRand, /**< Initialize GMM parameters by selecting points at random. */ 25 | VlGMMCustom /**< User specifies the initial GMM parameters. */ 26 | } VlGMMInitialization ; 27 | 28 | 29 | #ifndef __DOXYGEN__ 30 | struct _VlGMM ; 31 | typedef struct _VlGMM VlGMM ; 32 | #else 33 | /** @brief GMM quantizer */ 34 | typedef OPAQUE VlGMM ; 35 | #endif 36 | 37 | /** @name Create and destroy 38 | ** @{ 39 | **/ 40 | VL_EXPORT VlGMM * vl_gmm_new (vl_type dataType, vl_size dimension, vl_size numComponents) ; 41 | VL_EXPORT VlGMM * vl_gmm_new_copy (VlGMM const * gmm) ; 42 | VL_EXPORT void vl_gmm_delete (VlGMM * self) ; 43 | VL_EXPORT void vl_gmm_reset (VlGMM * self); 44 | /** @} */ 45 | 46 | /** @name Basic data processing 47 | ** @{ 48 | **/ 49 | VL_EXPORT double 50 | vl_gmm_cluster 51 | (VlGMM * self, 52 | void const * data, 53 | vl_size numData); 54 | /** @} */ 55 | 56 | /** @name Fine grained data processing 57 | ** @{ */ 58 | 59 | VL_EXPORT void 60 | vl_gmm_init_with_rand_data 61 | (VlGMM * self, 62 | void const * data, 63 | vl_size numData) ; 64 | 65 | VL_EXPORT void 66 | vl_gmm_init_with_kmeans 67 | (VlGMM * self, 68 | void const * data, 69 | vl_size numData, 70 | VlKMeans * kmeansInit); 71 | 72 | VL_EXPORT double 73 | vl_gmm_em 74 | (VlGMM * self, 75 | void const * data, 76 | vl_size numData); 77 | /** @} */ 78 | 79 | VL_EXPORT void 80 | vl_gmm_set_means 81 | (VlGMM * self, 82 | void const * means); 83 | 84 | VL_EXPORT void 85 | vl_gmm_set_covariances 86 | (VlGMM * self, 87 | void const * covariances); 88 | 89 | VL_EXPORT void 90 | vl_gmm_set_priors 91 | (VlGMM * self, 92 | void const * priors); 93 | 94 | VL_EXPORT double 95 | vl_get_gmm_data_posteriors_f(float * posteriors, 96 | vl_size numClusters, 97 | vl_size numData, 98 | float const * priors, 99 | float const * means, 100 | vl_size dimension, 101 | float const * covariances, 102 | float const * data) ; 103 | 104 | VL_EXPORT double 105 | vl_get_gmm_data_posteriors_d(double * posteriors, 106 | vl_size numClusters, 107 | vl_size numData, 108 | double const * priors, 109 | double const * means, 110 | vl_size dimension, 111 | double const * covariances, 112 | double const * data) ; 113 | /** @} */ 114 | 115 | /** @name Set parameters 116 | ** @{ 117 | **/ 118 | VL_EXPORT void vl_gmm_set_num_repetitions (VlGMM * self, vl_size numRepetitions) ; 119 | VL_EXPORT void vl_gmm_set_max_num_iterations (VlGMM * self, vl_size maxNumIterations) ; 120 | VL_EXPORT void vl_gmm_set_verbosity (VlGMM * self, int verbosity) ; 121 | VL_EXPORT void vl_gmm_set_initialization (VlGMM * self, VlGMMInitialization init); 122 | VL_EXPORT void vl_gmm_set_kmeans_init_object (VlGMM * self, VlKMeans * kmeans); 123 | VL_EXPORT void vl_gmm_set_covariance_lower_bounds (VlGMM * self, double const * bounds); 124 | VL_EXPORT void vl_gmm_set_covariance_lower_bound (VlGMM * self, double bound) ; 125 | /** @} */ 126 | 127 | /** @name Get parameters 128 | ** @{ 129 | **/ 130 | VL_EXPORT void const * vl_gmm_get_means (VlGMM const * self); 131 | VL_EXPORT void const * vl_gmm_get_covariances (VlGMM const * self); 132 | VL_EXPORT void const * vl_gmm_get_priors (VlGMM const * self); 133 | VL_EXPORT void const * vl_gmm_get_posteriors (VlGMM const * self); 134 | VL_EXPORT vl_type vl_gmm_get_data_type (VlGMM const * self); 135 | VL_EXPORT vl_size vl_gmm_get_dimension (VlGMM const * self); 136 | VL_EXPORT vl_size vl_gmm_get_num_repetitions (VlGMM const * self); 137 | VL_EXPORT vl_size vl_gmm_get_num_data (VlGMM const * self); 138 | VL_EXPORT vl_size vl_gmm_get_num_clusters (VlGMM const * self); 139 | VL_EXPORT double vl_gmm_get_loglikelihood (VlGMM const * self); 140 | VL_EXPORT int vl_gmm_get_verbosity (VlGMM const * self); 141 | VL_EXPORT vl_size vl_gmm_get_max_num_iterations (VlGMM const * self); 142 | VL_EXPORT vl_size vl_gmm_get_num_repetitions (VlGMM const * self); 143 | VL_EXPORT VlGMMInitialization vl_gmm_get_initialization (VlGMM const * self); 144 | VL_EXPORT VlKMeans * vl_gmm_get_kmeans_init_object (VlGMM const * self); 145 | VL_EXPORT double const * vl_gmm_get_covariance_lower_bounds (VlGMM const * self); 146 | /** @} */ 147 | 148 | /* VL_GMM_H */ 149 | #endif 150 | -------------------------------------------------------------------------------- /cpp_libs/vl/hikmeans.h: -------------------------------------------------------------------------------- 1 | /** @file hikmeans.h 2 | ** @brief Hierarchical Integer K-Means Clustering 3 | ** @author Brian Fulkerson 4 | **/ 5 | 6 | /* 7 | Copyright (C) 2007-12 Andrea Vedaldi and Brian Fulkerson. 8 | All rights reserved. 9 | 10 | This file is part of the VLFeat library and is made available under 11 | the terms of the BSD license (see the COPYING file). 12 | */ 13 | 14 | #ifndef VL_HIKMEANS_H 15 | #define VL_HIKMEANS_H 16 | 17 | #include "generic.h" 18 | #include "ikmeans.h" 19 | 20 | struct _VLHIKMTree ; 21 | struct _VLHIKMNode ; 22 | 23 | /** @brief HIKM tree node 24 | ** 25 | ** The number of children @a K is not bigger than the @a K parameter 26 | ** of the HIKM tree. 27 | **/ 28 | typedef struct _VlHIKMNode 29 | { 30 | VlIKMFilt *filter ; /**< IKM filter for this node*/ 31 | struct _VlHIKMNode **children ; /**< Node children (if any) */ 32 | } VlHIKMNode ; 33 | 34 | /** @brief HIKM tree */ 35 | typedef struct _VlHIKMTree { 36 | vl_size M ; /**< IKM: data dimensionality */ 37 | vl_size K ; /**< IKM: K */ 38 | vl_size depth ; /**< Depth of the tree */ 39 | vl_size max_niters ; /**< IKM: maximum # of iterations */ 40 | int method ; /**< IKM: method */ 41 | int verb ; /**< Verbosity level */ 42 | VlHIKMNode * root; /**< Tree root node */ 43 | } VlHIKMTree ; 44 | 45 | /** @name Create and destroy 46 | ** @{ 47 | **/ 48 | VL_EXPORT VlHIKMTree *vl_hikm_new (int method) ; 49 | VL_EXPORT void vl_hikm_delete (VlHIKMTree *f) ; 50 | /** @} */ 51 | 52 | /** @name Retrieve data and parameters 53 | ** @{ 54 | **/ 55 | VL_EXPORT vl_size vl_hikm_get_ndims (VlHIKMTree const *f) ; 56 | VL_EXPORT vl_size vl_hikm_get_K (VlHIKMTree const *f) ; 57 | VL_EXPORT vl_size vl_hikm_get_depth (VlHIKMTree const *f) ; 58 | VL_EXPORT int vl_hikm_get_verbosity (VlHIKMTree const *f) ; 59 | VL_EXPORT vl_size vl_hikm_get_max_niters (VlHIKMTree const *f) ; 60 | VL_EXPORT VlHIKMNode const * vl_hikm_get_root (VlHIKMTree const *f) ; 61 | /** @} */ 62 | 63 | /** @name Set parameters 64 | ** @{ 65 | **/ 66 | VL_EXPORT void vl_hikm_set_verbosity (VlHIKMTree *f, int verb) ; 67 | VL_EXPORT void vl_hikm_set_max_niters (VlHIKMTree *f, int max_niters) ; 68 | /** @} */ 69 | 70 | /** @name Process data 71 | ** @{ 72 | **/ 73 | VL_EXPORT void vl_hikm_init (VlHIKMTree *f, vl_size M, vl_size K, vl_size depth) ; 74 | VL_EXPORT void vl_hikm_train (VlHIKMTree *f, vl_uint8 const *data, vl_size N) ; 75 | VL_EXPORT void vl_hikm_push (VlHIKMTree *f, vl_uint32 *asgn, vl_uint8 const *data, vl_size N) ; 76 | /** @} */ 77 | 78 | 79 | /* VL_HIKMEANS_H */ 80 | #endif 81 | -------------------------------------------------------------------------------- /cpp_libs/vl/hog.h: -------------------------------------------------------------------------------- 1 | /** @file hog.h 2 | ** @brief Histogram of Oriented Gradients (@ref hog) 3 | ** @author Andrea Vedaldi 4 | **/ 5 | 6 | /* 7 | Copyright (C) 2007-12 Andrea Vedaldi and Brian Fulkerson. 8 | All rights reserved. 9 | 10 | This file is part of the VLFeat library and is made available under 11 | the terms of the BSD license (see the COPYING file). 12 | */ 13 | 14 | #ifndef VL_HOG_H 15 | #define VL_HOG_H 16 | 17 | #include "generic.h" 18 | 19 | enum VlHogVariant_ { VlHogVariantDalalTriggs, VlHogVariantUoctti } ; 20 | 21 | typedef enum VlHogVariant_ VlHogVariant ; 22 | 23 | struct VlHog_ 24 | { 25 | VlHogVariant variant ; 26 | vl_size dimension ; 27 | vl_size numOrientations ; 28 | vl_bool transposed ; 29 | vl_bool useBilinearOrientationAssigment ; 30 | 31 | /* left-right flip permutation */ 32 | vl_index * permutation ; 33 | 34 | /* glyphs */ 35 | float * glyphs ; 36 | vl_size glyphSize ; 37 | 38 | /* helper vectors */ 39 | float * orientationX ; 40 | float * orientationY ; 41 | 42 | /* buffers */ 43 | float * hog ; 44 | float * hogNorm ; 45 | vl_size hogWidth ; 46 | vl_size hogHeight ; 47 | } ; 48 | 49 | typedef struct VlHog_ VlHog ; 50 | 51 | VL_EXPORT VlHog * vl_hog_new (VlHogVariant variant, vl_size numOrientations, vl_bool transposed) ; 52 | VL_EXPORT void vl_hog_delete (VlHog * self) ; 53 | VL_EXPORT void vl_hog_process (VlHog * self, 54 | float * features, 55 | float const * image, 56 | vl_size width, vl_size height, vl_size numChannels, 57 | vl_size cellSize) ; 58 | 59 | VL_EXPORT void vl_hog_put_image (VlHog * self, 60 | float const * image, 61 | vl_size width, vl_size height, vl_size numChannels, 62 | vl_size cellSize) ; 63 | 64 | VL_EXPORT void vl_hog_put_polar_field (VlHog * self, 65 | float const * modulus, 66 | float const * angle, 67 | vl_bool directed, 68 | vl_size width, vl_size height, vl_size cellSize) ; 69 | 70 | VL_EXPORT void vl_hog_extract (VlHog * self, float * features) ; 71 | VL_EXPORT vl_size vl_hog_get_height (VlHog * self) ; 72 | VL_EXPORT vl_size vl_hog_get_width (VlHog * self) ; 73 | 74 | 75 | VL_EXPORT void vl_hog_render (VlHog const * self, 76 | float * image, 77 | float const * features, 78 | vl_size width, 79 | vl_size height) ; 80 | 81 | VL_EXPORT vl_size vl_hog_get_dimension (VlHog const * self) ; 82 | VL_EXPORT vl_index const * vl_hog_get_permutation (VlHog const * self) ; 83 | VL_EXPORT vl_size vl_hog_get_glyph_size (VlHog const * self) ; 84 | 85 | VL_EXPORT vl_bool vl_hog_get_use_bilinear_orientation_assignments (VlHog const * self) ; 86 | VL_EXPORT void vl_hog_set_use_bilinear_orientation_assignments (VlHog * self, vl_bool x) ; 87 | 88 | /* VL_HOG_H */ 89 | #endif 90 | -------------------------------------------------------------------------------- /cpp_libs/vl/homkermap.h: -------------------------------------------------------------------------------- 1 | /** @file homkermap.h 2 | ** @brief Homogeneous kernel map (@ref homkermap) 3 | ** @author Andrea Vedaldi 4 | **/ 5 | 6 | /* 7 | Copyright (C) 2007-12 Andrea Vedaldi and Brian Fulkerson. 8 | All rights reserved. 9 | 10 | This file is part of the VLFeat library and is made available under 11 | the terms of the BSD license (see the COPYING file). 12 | */ 13 | 14 | #ifndef VL_HOMKERMAP_H 15 | #define VL_HOMKERMAP_H 16 | 17 | #include "generic.h" 18 | 19 | #include 20 | 21 | /** @brief Type of kernel */ 22 | typedef enum { 23 | VlHomogeneousKernelIntersection = 0, /**< intersection kernel */ 24 | VlHomogeneousKernelChi2, /**< Chi2 kernel */ 25 | VlHomogeneousKernelJS /**< Jensen-Shannon kernel */ 26 | } VlHomogeneousKernelType ; 27 | 28 | /** @brief Type of spectral windowing function */ 29 | typedef enum { 30 | VlHomogeneousKernelMapWindowUniform = 0, /**< uniform window */ 31 | VlHomogeneousKernelMapWindowRectangular = 1, /**< rectangular window */ 32 | } VlHomogeneousKernelMapWindowType ; 33 | 34 | #ifndef __DOXYGEN__ 35 | struct _VlHomogeneousKernelMap ; 36 | typedef struct _VlHomogeneousKernelMap VlHomogeneousKernelMap ; 37 | #else 38 | /** @brief Homogeneous kernel map object */ 39 | typedef OPAQUE VlHomogeneousKernelMap ; 40 | #endif 41 | 42 | /** @name Create and destroy 43 | ** @{ */ 44 | VL_EXPORT VlHomogeneousKernelMap * 45 | vl_homogeneouskernelmap_new (VlHomogeneousKernelType kernelType, 46 | double gamma, 47 | vl_size order, 48 | double period, 49 | VlHomogeneousKernelMapWindowType windowType) ; 50 | VL_EXPORT void 51 | vl_homogeneouskernelmap_delete (VlHomogeneousKernelMap * self) ; 52 | /** @} */ 53 | 54 | /** @name Process data 55 | ** @{ */ 56 | VL_EXPORT void 57 | vl_homogeneouskernelmap_evaluate_d (VlHomogeneousKernelMap const * self, 58 | double * destination, 59 | vl_size stride, 60 | double x) ; 61 | 62 | VL_EXPORT void 63 | vl_homogeneouskernelmap_evaluate_f (VlHomogeneousKernelMap const * self, 64 | float * destination, 65 | vl_size stride, 66 | double x) ; 67 | /** @} */ 68 | 69 | 70 | /** @name Retrieve data and parameters 71 | ** @{ */ 72 | VL_EXPORT vl_size 73 | vl_homogeneouskernelmap_get_order (VlHomogeneousKernelMap const * self) ; 74 | 75 | VL_EXPORT vl_size 76 | vl_homogeneouskernelmap_get_dimension (VlHomogeneousKernelMap const * self) ; 77 | 78 | VL_EXPORT VlHomogeneousKernelType 79 | vl_homogeneouskernelmap_get_kernel_type (VlHomogeneousKernelMap const * self) ; 80 | 81 | VL_EXPORT VlHomogeneousKernelMapWindowType 82 | vl_homogeneouskernelmap_get_window_type (VlHomogeneousKernelMap const * self) ; 83 | /** @} */ 84 | 85 | /* VL_HOMKERMAP_H */ 86 | #endif 87 | -------------------------------------------------------------------------------- /cpp_libs/vl/ikmeans.h: -------------------------------------------------------------------------------- 1 | /** @file ikmeans.h 2 | ** @brief Integer K-Means clustering 3 | ** @author Brian Fulkerson 4 | ** @author Andrea Vedaldi 5 | **/ 6 | 7 | /* 8 | Copyright (C) 2014 Andrea Vedaldi. 9 | Copyright (C) 2007-12 Andrea Vedaldi and Brian Fulkerson. 10 | All rights reserved. 11 | 12 | This file is part of the VLFeat library and is made available under 13 | the terms of the BSD license (see the COPYING file). 14 | */ 15 | 16 | #ifndef VL_IKMEANS_H 17 | #define VL_IKMEANS_H 18 | 19 | #include "generic.h" 20 | #include "random.h" 21 | 22 | #if 0 23 | typedef vl_int64 vl_ikmacc_t ; /**< IKM accumulator data type */ 24 | #define VL_IKMACC_MAX 0x7fffffffffffffffULL 25 | #else 26 | typedef vl_int32 vl_ikmacc_t ; /**< IKM accumulator data type */ 27 | #define VL_IKMACC_MAX 0x7fffffffUL 28 | #endif 29 | 30 | 31 | /** ------------------------------------------------------------------ 32 | ** @brief IKM algorithms 33 | **/ 34 | 35 | enum VlIKMAlgorithms { 36 | VL_IKM_LLOYD, /**< Lloyd algorithm */ 37 | VL_IKM_ELKAN, /**< Elkan algorithm */ 38 | } ; 39 | 40 | /** ------------------------------------------------------------------ 41 | ** @brief IKM quantizer 42 | **/ 43 | 44 | typedef struct _VlIKMFilt 45 | { 46 | vl_size M ; /**< data dimensionality */ 47 | vl_size K ; /**< number of centers */ 48 | vl_size max_niters ; /**< Lloyd: maximum number of iterations */ 49 | int method ; /**< Learning method */ 50 | int verb ; /**< verbosity level */ 51 | vl_ikmacc_t *centers ; /**< centers */ 52 | vl_ikmacc_t *inter_dist ; /**< centers inter-distances */ 53 | } VlIKMFilt ; 54 | 55 | /** @name Create and destroy 56 | ** @{ */ 57 | VL_EXPORT VlIKMFilt *vl_ikm_new (int method) ; 58 | VL_EXPORT void vl_ikm_delete (VlIKMFilt *f) ; 59 | /** @} */ 60 | 61 | /** @name Process data 62 | ** @{ */ 63 | VL_EXPORT void vl_ikm_init (VlIKMFilt *f, vl_ikmacc_t const *centers, vl_size M, vl_size K) ; 64 | VL_EXPORT void vl_ikm_init_rand (VlIKMFilt *f, vl_size M, vl_size K) ; 65 | VL_EXPORT void vl_ikm_init_rand_data (VlIKMFilt *f, vl_uint8 const *data, vl_size M, vl_size N, vl_size K) ; 66 | VL_EXPORT int vl_ikm_train (VlIKMFilt *f, vl_uint8 const *data, vl_size N) ; 67 | VL_EXPORT void vl_ikm_push (VlIKMFilt *f, vl_uint32 *asgn, vl_uint8 const *data, vl_size N) ; 68 | VL_EXPORT vl_uint vl_ikm_push_one (vl_ikmacc_t const *centers, vl_uint8 const *data, vl_size M, vl_size K) ; 69 | /** @} */ 70 | 71 | /** @name Retrieve data and parameters 72 | ** @{ */ 73 | VL_EXPORT vl_size vl_ikm_get_ndims (VlIKMFilt const *f) ; 74 | VL_EXPORT vl_size vl_ikm_get_K (VlIKMFilt const *f) ; 75 | VL_EXPORT int vl_ikm_get_verbosity (VlIKMFilt const *f) ; 76 | VL_EXPORT vl_size vl_ikm_get_max_niters (VlIKMFilt const *f) ; 77 | VL_EXPORT vl_ikmacc_t const *vl_ikm_get_centers (VlIKMFilt const *f) ; 78 | /** @} */ 79 | 80 | /** @name Set parameters 81 | ** @{ */ 82 | VL_EXPORT void vl_ikm_set_verbosity (VlIKMFilt *f, int verb) ; 83 | VL_EXPORT void vl_ikm_set_max_niters (VlIKMFilt *f, vl_size max_niters) ; 84 | /** @} */ 85 | 86 | /* VL_IKMEANS_H */ 87 | #endif 88 | -------------------------------------------------------------------------------- /cpp_libs/vl/ikmeans_init.tc: -------------------------------------------------------------------------------- 1 | /** @file ikmeans_init.tc 2 | ** @brief Integer K-Means - Initialization - Definition 3 | ** @author Andrea Vedaldi 4 | **/ 5 | 6 | /* 7 | Copyright (C) 2007-12 Andrea Vedaldi and Brian Fulkerson. 8 | All rights reserved. 9 | 10 | This file is part of the VLFeat library and is made available under 11 | the terms of the BSD license (see the COPYING file). 12 | */ 13 | 14 | #include "random.h" 15 | 16 | /* pairs are used to generate random permutations of data */ 17 | typedef struct 18 | { 19 | vl_index w; 20 | vl_index j; 21 | } pair_t; 22 | 23 | static int cmp_pair (void const *a, void const *b) 24 | { 25 | pair_t *pa = (pair_t *) a; 26 | pair_t *pb = (pair_t *) b; 27 | int d = (int)(pa->w - pb->w) ; 28 | if (d) return d ; 29 | /* break ties based on index (compensates for qsort not being stable) */ 30 | return (int)(pa->j - pb->j); 31 | } 32 | 33 | VL_INLINE vl_ikmacc_t calc_dist2 (vl_ikmacc_t const* A, vl_uint8 const* B, vl_size M) 34 | { 35 | vl_ikmacc_t acc = 0 ; 36 | vl_uindex i = 0 ; 37 | for (i = 0 ; i < M ; ++i) { 38 | vl_ikmacc_t dist = (vl_ikmacc_t)A[i] - (vl_ikmacc_t)B[i] ; 39 | acc += (vl_uindex)(dist * dist) ; 40 | } 41 | return acc ; 42 | } 43 | 44 | /** @internal 45 | ** @brief Helper function to allocate memory for an IKM quantizer 46 | ** @param f quantizer. 47 | ** @param M data dimensionality. 48 | ** @param K number of clusters. 49 | **/ 50 | 51 | static void alloc (VlIKMFilt *f, vl_size M, vl_size K) 52 | { 53 | if (f->centers) vl_free(f->centers) ; 54 | f->K = K ; 55 | f->M = M ; 56 | f->centers = vl_malloc(sizeof(vl_ikmacc_t) * M * K) ; 57 | } 58 | 59 | 60 | /** @brief Helper function to initialize the quantizer 61 | ** @param f IKM quantizer. 62 | **/ 63 | 64 | static 65 | void vl_ikm_init_helper (VlIKMFilt *f) 66 | { 67 | switch (f-> method) { 68 | case VL_IKM_LLOYD: vl_ikm_init_lloyd (f) ; break ; 69 | case VL_IKM_ELKAN: vl_ikm_init_elkan (f) ; break ; 70 | } 71 | } 72 | 73 | /** @brief Initialize quantizer with centers 74 | ** @param f IKM quantizer. 75 | ** @param centers centers. 76 | ** @param M data dimensionality. 77 | ** @param K number of clusters. 78 | **/ 79 | 80 | VL_EXPORT void 81 | vl_ikm_init (VlIKMFilt* f, vl_ikmacc_t const * centers, vl_size M, vl_size K) 82 | { 83 | alloc (f, M, K) ; 84 | memcpy (f->centers, centers, sizeof(vl_ikmacc_t) * M * K) ; 85 | vl_ikm_init_helper (f) ; 86 | } 87 | 88 | /** @brief Initialize quantizer with random centers 89 | ** @param f IKM quantizer. 90 | ** @param M data dimensionality. 91 | ** @param K number of clusters. 92 | **/ 93 | 94 | VL_EXPORT void 95 | vl_ikm_init_rand 96 | (VlIKMFilt* f, vl_size M, vl_size K) 97 | { 98 | vl_uindex k, i ; 99 | VlRand * rand = vl_get_rand() ; 100 | 101 | alloc (f, M, K) ; 102 | 103 | for (k = 0 ; k < K ; ++ k) { 104 | for (i = 0 ; i < M ; ++ i) { 105 | f-> centers [k * M + i] = (vl_ikmacc_t) (vl_rand_uint32 (rand)) ; 106 | } 107 | } 108 | 109 | vl_ikm_init_helper (f) ; 110 | } 111 | 112 | /** @brief Initialize with centers from random data 113 | ** @param f IKM quantizer. 114 | ** @param data data. 115 | ** @param M data dimensionality. 116 | ** @param N number of data. 117 | ** @param K number of clusters. 118 | **/ 119 | 120 | VL_EXPORT void 121 | vl_ikm_init_rand_data 122 | (VlIKMFilt* f, vl_uint8 const* data, vl_size M, vl_size N, vl_size K) 123 | { 124 | vl_uindex i, j, k ; 125 | VlRand *rand = vl_get_rand () ; 126 | pair_t *pairs = (pair_t *) vl_malloc (sizeof(pair_t) * N); 127 | 128 | alloc (f, M, K) ; 129 | 130 | /* permute the data randomly */ 131 | for (j = 0 ; j < N ; ++j) { 132 | pairs[j].j = j ; 133 | pairs[j].w = ((vl_int32) vl_rand_uint32 (rand)) >> 2 ; 134 | } 135 | 136 | qsort (pairs, N, sizeof(pair_t), cmp_pair); 137 | 138 | /* initialize centers from random data points */ 139 | for (j = 0, k = 0 ; k < K ; ++ k) { 140 | 141 | /* search for the next candidate which is not a dup */ 142 | for ( ; j < N - 1 ; ++j) { 143 | vl_uindex prevk = 0 ; 144 | for (prevk = 0 ; prevk < k ; ++ prevk) { 145 | vl_ikmacc_t dist = calc_dist2(f-> centers + prevk * M, 146 | data + pairs[j].j * M, 147 | M) ; 148 | if (dist == 0) break ; 149 | } 150 | if (prevk == k) break ; 151 | } 152 | 153 | for (i = 0 ; i < M ; ++ i) { 154 | f-> centers [k * M + i] = data [(vl_uint64)pairs[j].j * M + i] ; 155 | } 156 | 157 | if (j < N - 1) ++ j ; 158 | } 159 | 160 | vl_free (pairs) ; 161 | vl_ikm_init_helper (f) ; 162 | } 163 | 164 | /* 165 | * Local Variables: * 166 | * mode: C * 167 | * End: * 168 | */ 169 | -------------------------------------------------------------------------------- /cpp_libs/vl/ikmeans_lloyd.tc: -------------------------------------------------------------------------------- 1 | /** @file ikmeans_lloyd.tc 2 | ** @brief Integer K-Means - LLoyd Algorithm - Definition 3 | ** @author Brian Fulkerson 4 | ** @author Andrea Vedaldi 5 | **/ 6 | 7 | /* 8 | Copyright (C) 2007-12 Andrea Vedaldi and Brian Fulkerson. 9 | All rights reserved. 10 | 11 | This file is part of the VLFeat library and is made available under 12 | the terms of the BSD license (see the COPYING file). 13 | */ 14 | 15 | /** @internal 16 | ** @brief Helper function to initialize a filter for Lloyd algorithm 17 | ** 18 | ** @param f filter. 19 | **/ 20 | 21 | static void 22 | vl_ikm_init_lloyd (VlIKMFilt * f VL_UNUSED) 23 | { } 24 | 25 | /** @internal 26 | ** @brief LLoyd algorithm 27 | ** @param f IKM quantizer. 28 | ** @param data Training data. 29 | ** @param N Number of traning data. 30 | ** @return error code. 31 | **/ 32 | 33 | static int 34 | vl_ikm_train_lloyd (VlIKMFilt* f, vl_uint8 const* data, vl_size N) 35 | { 36 | int err = 0 ; 37 | vl_uindex iter, i, j, k ; 38 | vl_uint32 *asgn = vl_malloc (sizeof(vl_uint32) * N) ; 39 | vl_uint32 *counts = vl_malloc (sizeof(vl_uint32) * N) ; 40 | 41 | for (iter = 0 ; 1 ; ++ iter) { 42 | vl_bool done = 1 ; 43 | 44 | /* --------------------------------------------------------------- 45 | * Calc. assignments 46 | * ------------------------------------------------------------ */ 47 | 48 | for (j = 0 ; j < N ; ++j) { 49 | vl_ikmacc_t best_dist = 0 ; 50 | vl_index best = -1 ; 51 | 52 | for (k = 0; k < f->K ; ++k) { 53 | vl_ikmacc_t dist = 0 ; 54 | 55 | /* compute distance with this center */ 56 | for (i = 0; i < f->M ; ++i) { 57 | vl_ikmacc_t delta = 58 | data [j * f->M + i] - f->centers [k * f->M + i] ; 59 | dist += delta * delta ; 60 | } 61 | 62 | /* compare with current best */ 63 | if (best == -1 || dist < best_dist) { 64 | best = k ; 65 | best_dist = dist ; 66 | } 67 | } 68 | if (asgn [j] != best) { 69 | asgn [j] = (vl_uint32) best ; 70 | done = 0 ; 71 | } 72 | } 73 | 74 | /* stopping condition */ 75 | if (done || iter == f->max_niters) break ; 76 | 77 | /* --------------------------------------------------------------- 78 | * Calc. centers 79 | * ------------------------------------------------------------ */ 80 | 81 | /* re-compute centers */ 82 | memset (f->centers, 0, sizeof(*f->centers) * f->M * f->K); 83 | memset (counts, 0, sizeof(*counts) * f->K); 84 | for (j = 0; j < N; ++j) { 85 | vl_uindex this_center = asgn [j] ; 86 | ++ counts [this_center] ; 87 | for (i = 0; i < f->M ; ++i) { 88 | f->centers [this_center * f->M + i] += data[j * f->M + i] ; 89 | } 90 | } 91 | 92 | for (k = 0; k < f->K; ++k) { 93 | vl_index n = counts [k]; 94 | if (n > 0xffffff) { 95 | err = 1 ; 96 | } 97 | if (n > 0) { 98 | for (i = 0; i < f->M; ++i) { 99 | f->centers [k * f->M + i] /= n; 100 | } 101 | } else { 102 | /* 103 | If no data are assigned to the center, it is not changed 104 | with respect to the previous iteration, so we do not do anything. 105 | */ 106 | } 107 | } 108 | } 109 | 110 | vl_free (counts) ; 111 | vl_free (asgn) ; 112 | return err ; 113 | } 114 | 115 | 116 | /** @internal 117 | ** @brief LLoyd algorithm 118 | ** @param f IKM quantizer. 119 | ** @param asgn Assignments (out). 120 | ** @param data Data to quantize. 121 | ** @param N Number of data. 122 | **/ 123 | 124 | static void 125 | vl_ikm_push_lloyd (VlIKMFilt *f, vl_uint32 *asgn, vl_uint8 const *data, vl_size N) 126 | { 127 | vl_uindex j ; 128 | for(j = 0 ; j < N ; ++j) { 129 | asgn[j] = vl_ikm_push_one (f->centers, data + j * f->M, f->M, f->K); 130 | } 131 | } 132 | 133 | /* 134 | * Local Variables: * 135 | * mode: C * 136 | * End: * 137 | */ 138 | -------------------------------------------------------------------------------- /cpp_libs/vl/imopv_sse2.h: -------------------------------------------------------------------------------- 1 | /** @file imopv_sse2.h 2 | ** @brief Vectorized image operations - SSE2 3 | ** @author Andrea Vedaldi 4 | **/ 5 | 6 | /* 7 | Copyright (C) 2007-12 Andrea Vedaldi and Brian Fulkerson. 8 | All rights reserved. 9 | 10 | This file is part of the VLFeat library and is made available under 11 | the terms of the BSD license (see the COPYING file). 12 | */ 13 | 14 | #ifndef VL_IMOPV_SSE2_H 15 | #define VL_IMOPV_SSE2_H 16 | 17 | #include "generic.h" 18 | 19 | #ifndef VL_DISABLE_SSE2 20 | 21 | VL_EXPORT 22 | void _vl_imconvcol_vf_sse2 (float* dst, vl_size dst_stride, 23 | float const* src, 24 | vl_size src_width, vl_size src_height, vl_size src_stride, 25 | float const* filt, vl_index filt_begin, vl_index filt_end, 26 | int step, unsigned int flags) ; 27 | 28 | VL_EXPORT 29 | void _vl_imconvcol_vd_sse2 (double* dst, vl_size dst_stride, 30 | double const* src, 31 | vl_size src_width, vl_size src_height, vl_size src_stride, 32 | double const* filt, vl_index filt_begin, vl_index filt_end, 33 | int step, unsigned int flags) ; 34 | 35 | /* 36 | VL_EXPORT 37 | void _vl_imconvcoltri_vf_sse2 (float* dst, int dst_stride, 38 | float const* src, 39 | int src_width, int src_height, int src_stride, 40 | int filt_size, 41 | int step, unsigned int flags) ; 42 | 43 | VL_EXPORT 44 | void _vl_imconvcoltri_vd_sse2 (double* dst, int dst_stride, 45 | double const* src, 46 | int src_width, int src_height, int src_stride, 47 | int filt_size, 48 | int step, unsigned int flags) ; 49 | */ 50 | 51 | #endif 52 | 53 | /* VL_IMOPV_SSE2_H */ 54 | #endif 55 | -------------------------------------------------------------------------------- /cpp_libs/vl/lbp.h: -------------------------------------------------------------------------------- 1 | /** @file lbp.h 2 | ** @brief Local Binary Patterns (LBP) descriptor (@ref lbp) 3 | ** @author Andrea Vedaldi 4 | **/ 5 | 6 | /* 7 | Copyright (C) 2007-12 Andrea Vedaldi and Brian Fulkerson. 8 | All rights reserved. 9 | 10 | This file is part of the VLFeat library and is made available under 11 | the terms of the BSD license (see the COPYING file). 12 | */ 13 | 14 | #ifndef VL_LBP_H 15 | #define VL_LBP_H 16 | 17 | #include "generic.h" 18 | 19 | /** @brief Type of quantization for the LBP descriptors 20 | ** @see @ref lbp-quantization 21 | **/ 22 | typedef enum _VlLbpMappingType 23 | { 24 | VlLbpUniform /**< Uniform local binary patterns. */ 25 | } VlLbpMappingType ; 26 | 27 | /** @brief Local Binary Pattern extractor */ 28 | typedef struct VlLbp_ 29 | { 30 | vl_size dimension ; 31 | vl_uint8 mapping [256] ; 32 | vl_bool transposed ; 33 | } VlLbp ; 34 | 35 | VL_EXPORT VlLbp * vl_lbp_new(VlLbpMappingType type, vl_bool transposed) ; 36 | VL_EXPORT void vl_lbp_delete(VlLbp * self) ; 37 | VL_EXPORT void vl_lbp_process(VlLbp * self, 38 | float * features, 39 | float * image, vl_size width, vl_size height, 40 | vl_size cellSize) ; 41 | VL_EXPORT vl_size vl_lbp_get_dimension(VlLbp * self) ; 42 | 43 | /* VL_LBP_H */ 44 | #endif 45 | -------------------------------------------------------------------------------- /cpp_libs/vl/liop.h: -------------------------------------------------------------------------------- 1 | /** @file liop.h 2 | ** @brief Local Intensity Order Pattern (LIOP) descriptor (@ref liop) 3 | ** @author Hana Sarbortova 4 | ** @author Andrea Vedaldi 5 | ** @see @ref liop 6 | **/ 7 | 8 | /* 9 | Copyright (C) 2013 Hana Sarbortova and Andrea Vedaldi. 10 | All rights reserved. 11 | 12 | This file is part of the VLFeat library and is made available under 13 | the terms of the BSD license (see the COPYING file). 14 | */ 15 | 16 | #ifndef VL_LIOP_H 17 | #define VL_LIOP_H 18 | 19 | #include "generic.h" 20 | 21 | /** @brief LIOP descriptor extractor object */ 22 | typedef struct _VlLiopDesc 23 | { 24 | vl_int numNeighbours; /**< Number of neighbours. */ 25 | vl_int numSpatialBins; /**< Number of bins. */ 26 | float intensityThreshold; /**< Weight threshold. */ 27 | vl_size dimension; /**< LIOP descriptor size. */ 28 | 29 | /* Pixels in the circular patch */ 30 | vl_size patchSideLength ; 31 | vl_size patchSize ; /* only circular neighbourhood */ 32 | vl_uindex * patchPixels ; 33 | float * patchIntensities ; 34 | vl_uindex * patchPermutation ; 35 | 36 | /* Neighbourhoods of each pixel (samples in a circle) */ 37 | float neighRadius; /**< Point to neighbour radius (distance). */ 38 | 39 | float * neighIntensities ; 40 | vl_uindex * neighPermutation ; 41 | double * neighSamplesX ; 42 | double * neighSamplesY ; 43 | 44 | } VlLiopDesc ; 45 | 46 | /** @name Construct and destroy 47 | ** @{ */ 48 | VL_EXPORT 49 | VlLiopDesc * vl_liopdesc_new (vl_int numNeighbours, 50 | vl_int numSpatialBins, 51 | float radius, 52 | vl_size sideLength) ; 53 | 54 | VL_EXPORT 55 | VlLiopDesc * vl_liopdesc_new_basic (vl_size sideLength) ; 56 | 57 | VL_EXPORT 58 | void vl_liopdesc_delete (VlLiopDesc * self) ; 59 | /** @} */ 60 | 61 | /** @name Get data and parameters 62 | ** @{ */ 63 | VL_EXPORT vl_size vl_liopdesc_get_dimension (VlLiopDesc const * self) ; 64 | VL_EXPORT vl_size vl_liopdesc_get_num_neighbours (VlLiopDesc const * self) ; 65 | VL_EXPORT float vl_liopdesc_get_intensity_threshold (VlLiopDesc const * self) ; 66 | VL_EXPORT vl_size vl_liopdesc_get_num_spatial_bins (VlLiopDesc const * self) ; 67 | VL_EXPORT double vl_liopdesc_get_neighbourhood_radius (VlLiopDesc const * self) ; 68 | VL_EXPORT void vl_liopdesc_set_intensity_threshold (VlLiopDesc * self, float x) ; 69 | /** @} */ 70 | 71 | /** @name Compute LIOP descriptor 72 | ** @{ */ 73 | VL_EXPORT 74 | void vl_liopdesc_process (VlLiopDesc * liop, float * desc, float const * patch) ; 75 | /** @} */ 76 | 77 | /* VL_LIOP_H */ 78 | #endif 79 | -------------------------------------------------------------------------------- /cpp_libs/vl/mathop_avx.h: -------------------------------------------------------------------------------- 1 | /** @file mathop_avx.h 2 | ** @brief mathop for avx 3 | ** @author Andrea Vedaldi 4 | **/ 5 | 6 | /* 7 | Copyright (C) 2007-12 Andrea Vedaldi and Brian Fulkerson. 8 | All rights reserved. 9 | 10 | This file is part of the VLFeat library and is made available under 11 | the terms of the BSD license (see the COPYING file). 12 | */ 13 | 14 | /* ---------------------------------------------------------------- */ 15 | #ifndef VL_MATHOP_AVX_H_INSTANTIATING 16 | 17 | #ifndef VL_MATHOP_AVX_H 18 | #define VL_MATHOP_AVX_H 19 | 20 | #undef FLT 21 | #define FLT VL_TYPE_DOUBLE 22 | #define VL_MATHOP_AVX_H_INSTANTIATING 23 | #include "mathop_avx.h" 24 | 25 | #undef FLT 26 | #define FLT VL_TYPE_FLOAT 27 | #define VL_MATHOP_AVX_H_INSTANTIATING 28 | #include "mathop_avx.h" 29 | 30 | /* VL_MATHOP_AVX_H */ 31 | #endif 32 | 33 | /* ---------------------------------------------------------------- */ 34 | /* VL_MATHOP_AVX_H_INSTANTIATING */ 35 | #else 36 | 37 | #ifndef VL_DISABLE_AVX 38 | #include "generic.h" 39 | #include "float.th" 40 | 41 | VL_EXPORT T 42 | VL_XCAT(_vl_distance_mahalanobis_sq_avx_, SFX) 43 | (vl_size dimension, T const * X, T const * MU, T const * S); 44 | 45 | VL_EXPORT T 46 | VL_XCAT(_vl_distance_l2_avx_, SFX) 47 | (vl_size dimension, T const * X, T const * Y); 48 | 49 | VL_EXPORT void 50 | VL_XCAT(_vl_weighted_sigma_avx_, SFX) 51 | (vl_size dimension, T * S, T const * X, T const * Y, T const W); 52 | 53 | VL_EXPORT void 54 | VL_XCAT(_vl_weighted_mean_avx_, SFX) 55 | (vl_size dimension, T * MU, T const * X, T const W); 56 | 57 | /* ! VL_DISABLE_AVX */ 58 | #endif 59 | 60 | #undef VL_MATHOP_AVX_H_INSTANTIATING 61 | #endif 62 | -------------------------------------------------------------------------------- /cpp_libs/vl/mathop_sse2.h: -------------------------------------------------------------------------------- 1 | /** @file mathop_sse2.h 2 | ** @brief mathop for sse2 3 | ** @author Andrea Vedaldi 4 | **/ 5 | 6 | /* 7 | Copyright (C) 2007-12 Andrea Vedaldi and Brian Fulkerson. 8 | All rights reserved. 9 | 10 | This file is part of the VLFeat library and is made available under 11 | the terms of the BSD license (see the COPYING file). 12 | */ 13 | 14 | /* ---------------------------------------------------------------- */ 15 | #ifndef VL_MATHOP_SSE2_H_INSTANTIATING 16 | 17 | #ifndef VL_MATHOP_SSE2_H 18 | #define VL_MATHOP_SSE2_H 19 | 20 | #undef FLT 21 | #define FLT VL_TYPE_DOUBLE 22 | #define VL_MATHOP_SSE2_H_INSTANTIATING 23 | #include "mathop_sse2.h" 24 | 25 | #undef FLT 26 | #define FLT VL_TYPE_FLOAT 27 | #define VL_MATHOP_SSE2_H_INSTANTIATING 28 | #include "mathop_sse2.h" 29 | 30 | /* VL_MATHOP_SSE2_H */ 31 | #endif 32 | 33 | /* ---------------------------------------------------------------- */ 34 | /* VL_MATHOP_SSE2_H_INSTANTIATING */ 35 | #else 36 | 37 | #ifndef VL_DISABLE_SSE2 38 | 39 | #include "generic.h" 40 | #include "float.th" 41 | 42 | VL_EXPORT T 43 | VL_XCAT(_vl_dot_sse2_, SFX) 44 | (vl_size dimension, T const * X, T const * Y) ; 45 | 46 | VL_EXPORT T 47 | VL_XCAT(_vl_distance_l2_sse2_, SFX) 48 | (vl_size dimension, T const * X, T const * Y) ; 49 | 50 | VL_EXPORT T 51 | VL_XCAT(_vl_distance_l1_sse2_, SFX) 52 | (vl_size dimension, T const * X, T const * Y) ; 53 | 54 | VL_EXPORT T 55 | VL_XCAT(_vl_distance_chi2_sse2_, SFX) 56 | (vl_size dimension, T const * X, T const * Y) ; 57 | 58 | VL_EXPORT T 59 | VL_XCAT(_vl_kernel_l2_sse2_, SFX) 60 | (vl_size dimension, T const * X, T const * Y) ; 61 | 62 | VL_EXPORT T 63 | VL_XCAT(_vl_kernel_l1_sse2_, SFX) 64 | (vl_size dimension, T const * X, T const * Y) ; 65 | 66 | VL_EXPORT T 67 | VL_XCAT(_vl_kernel_chi2_sse2_, SFX) 68 | (vl_size dimension, T const * X, T const * Y) ; 69 | 70 | VL_EXPORT T 71 | VL_XCAT(_vl_distance_mahalanobis_sq_sse2_, SFX) 72 | (vl_size dimension, T const * X, T const * MU, T const * S); 73 | 74 | VL_EXPORT void 75 | VL_XCAT(_vl_weighted_sigma_sse2_, SFX) 76 | (vl_size dimension, T * S, T const * X, T const * Y, T const W); 77 | 78 | VL_EXPORT void 79 | VL_XCAT(_vl_weighted_mean_sse2_, SFX) 80 | (vl_size dimension, T * MU, T const * X, T const W); 81 | 82 | /* ! VL_DISABLE_SSE2 */ 83 | #endif 84 | #undef VL_MATHOP_SSE2_INSTANTIATING 85 | #endif 86 | -------------------------------------------------------------------------------- /cpp_libs/vl/pgm.h: -------------------------------------------------------------------------------- 1 | /** @file pgm.h 2 | ** @brief Portable graymap format (PGM) parser 3 | ** @author Andrea Vedaldi 4 | **/ 5 | 6 | /* 7 | Copyright (C) 2007-12 Andrea Vedaldi and Brian Fulkerson. 8 | All rights reserved. 9 | 10 | This file is part of the VLFeat library and is made available under 11 | the terms of the BSD license (see the COPYING file). 12 | */ 13 | 14 | #ifndef VL_PGM_H 15 | #define VL_PGM_H 16 | 17 | #include "generic.h" 18 | #include "mathop.h" 19 | #include 20 | 21 | /** @name PGM parser error codes 22 | ** @{ */ 23 | #define VL_ERR_PGM_INV_HEAD 101 /**< Invalid PGM header section. */ 24 | #define VL_ERR_PGM_INV_META 102 /**< Invalid PGM meta section. */ 25 | #define VL_ERR_PGM_INV_DATA 103 /**< Invalid PGM data section.*/ 26 | #define VL_ERR_PGM_IO 104 /**< Generic I/O error. */ 27 | /** @} */ 28 | 29 | /** @brief PGM image meta data 30 | ** 31 | ** A PGM image is a 2-D array of pixels of width #width and height 32 | ** #height. Each pixel is an integer one or two bytes wide, depending 33 | ** whether #max_value is smaller than 256. 34 | **/ 35 | 36 | typedef struct _VlPgmImage 37 | { 38 | vl_size width ; /**< image width. */ 39 | vl_size height ; /**< image height. */ 40 | vl_size max_value ; /**< pixel maximum value (<= 2^16-1). */ 41 | vl_bool is_raw ; /**< is RAW format? */ 42 | } VlPgmImage ; 43 | 44 | /** @name Core operations 45 | ** @{ */ 46 | VL_EXPORT int vl_pgm_extract_head (FILE *f, VlPgmImage *im) ; 47 | VL_EXPORT int vl_pgm_extract_data (FILE *f, VlPgmImage const *im, void *data) ; 48 | VL_EXPORT int vl_pgm_insert (FILE *f, 49 | VlPgmImage const *im, 50 | void const*data ) ; 51 | VL_EXPORT vl_size vl_pgm_get_npixels (VlPgmImage const *im) ; 52 | VL_EXPORT vl_size vl_pgm_get_bpp (VlPgmImage const *im) ; 53 | /** @} */ 54 | 55 | /** @name Helper functions 56 | ** @{ */ 57 | VL_EXPORT int vl_pgm_write (char const *name, 58 | vl_uint8 const *data, 59 | int width, int height) ; 60 | VL_EXPORT int vl_pgm_write_f (char const *name, 61 | float const *data, 62 | int width, int height) ; 63 | VL_EXPORT int vl_pgm_read_new (char const *name, 64 | VlPgmImage *im, 65 | vl_uint8 **data) ; 66 | VL_EXPORT int vl_pgm_read_new_f (char const *name, 67 | VlPgmImage *im, 68 | float **data) ; 69 | 70 | /** @} */ 71 | 72 | /* VL_PGM_H */ 73 | #endif 74 | -------------------------------------------------------------------------------- /cpp_libs/vl/random.h: -------------------------------------------------------------------------------- 1 | /** @file random.h 2 | ** @brief Random number generator (@ref random) 3 | ** @author Andrea Vedaldi 4 | ** @see @ref random 5 | **/ 6 | 7 | /* 8 | Copyright (C) 2007-12 Andrea Vedaldi and Brian Fulkerson. 9 | All rights reserved. 10 | 11 | This file is part of the VLFeat library and is made available under 12 | the terms of the BSD license (see the COPYING file). 13 | */ 14 | 15 | #ifndef VL_RANDOM_H 16 | #define VL_RANDOM_H 17 | 18 | #include "host.h" 19 | 20 | /** @brief Random numbber generator state */ 21 | typedef struct _VlRand { 22 | vl_uint32 mt [624] ; 23 | vl_uint32 mti ; 24 | } VlRand ; 25 | 26 | /** @name Setting and reading the state 27 | ** 28 | ** @{ */ 29 | VL_EXPORT void vl_rand_init (VlRand * self) ; 30 | VL_EXPORT void vl_rand_seed (VlRand * self, vl_uint32 s) ; 31 | VL_EXPORT void vl_rand_seed_by_array (VlRand * self, 32 | vl_uint32 const key [], 33 | vl_size keySize) ; 34 | /** @} */ 35 | 36 | /** @name Generate random numbers 37 | ** 38 | ** @{ */ 39 | VL_INLINE vl_uint64 vl_rand_uint64 (VlRand * self) ; 40 | VL_INLINE vl_int64 vl_rand_int63 (VlRand * self) ; 41 | VL_EXPORT vl_uint32 vl_rand_uint32 (VlRand * self) ; 42 | VL_INLINE vl_int32 vl_rand_int31 (VlRand * self) ; 43 | VL_INLINE double vl_rand_real1 (VlRand * self) ; 44 | VL_INLINE double vl_rand_real2 (VlRand * self) ; 45 | VL_INLINE double vl_rand_real3 (VlRand * self) ; 46 | VL_INLINE double vl_rand_res53 (VlRand * self) ; 47 | VL_INLINE vl_uindex vl_rand_uindex (VlRand * self, vl_uindex range) ; 48 | /** @} */ 49 | 50 | VL_EXPORT void vl_rand_permute_indexes (VlRand * self, vl_index* array, vl_size size) ; 51 | 52 | /* ---------------------------------------------------------------- */ 53 | 54 | /** @brief Generate a random index in a given range 55 | ** @param self random number generator. 56 | ** @param range range. 57 | ** @return an index sampled uniformly at random in the interval [0, @c range - 1] 58 | ** 59 | ** @remark Currently, this function uses a simple algorithm that 60 | ** may yield slightly biased samples if @c range is not a power of 61 | ** two. 62 | **/ 63 | 64 | VL_INLINE vl_uindex 65 | vl_rand_uindex (VlRand * self, vl_uindex range) 66 | { 67 | if (range <= 0xffffffff) { 68 | /* 32-bit version */ 69 | return (vl_rand_uint32 (self) % (vl_uint32)range) ; 70 | } else { 71 | /* 64-bit version */ 72 | return (vl_rand_uint64 (self) % range) ; 73 | } 74 | } 75 | 76 | /** @brief Generate a random UINT64 77 | ** @param self random number generator. 78 | ** @return a random number in [0, 0xffffffffffffffff]. 79 | **/ 80 | 81 | VL_INLINE vl_uint64 82 | vl_rand_uint64 (VlRand * self) 83 | { 84 | vl_uint64 a = vl_rand_uint32 (self) ; 85 | vl_uint64 b = vl_rand_uint32 (self) ; 86 | return (a << 32) | b ; 87 | } 88 | 89 | /** @brief Generate a random INT63 90 | ** @param self random number generator. 91 | ** @return a random number in [0, 0x7fffffffffffffff]. 92 | **/ 93 | 94 | VL_INLINE vl_int64 95 | vl_rand_int63 (VlRand * self) 96 | { 97 | return (vl_int64)(vl_rand_uint64 (self) >> 1) ; 98 | } 99 | 100 | /** @brief Generate a random INT31 101 | ** @param self random number generator. 102 | ** @return a random number in [0, 0x7fffffff]. 103 | **/ 104 | 105 | VL_INLINE vl_int32 106 | vl_rand_int31 (VlRand * self) 107 | { 108 | return (vl_int32)(vl_rand_uint32 (self) >> 1) ; 109 | } 110 | 111 | /** @brief Generate a random number in [0,1] 112 | ** @param self random number generator. 113 | ** @return a random number. 114 | **/ 115 | 116 | VL_INLINE double 117 | vl_rand_real1 (VlRand * self) 118 | { 119 | return vl_rand_uint32(self)*(1.0/4294967295.0); 120 | /* divided by 2^32-1 */ 121 | } 122 | 123 | /** @brief Generate a random number in [0,1) 124 | ** @param self random number generator. 125 | ** @return a random number. 126 | **/ 127 | 128 | VL_INLINE double 129 | vl_rand_real2 (VlRand * self) 130 | { 131 | return vl_rand_uint32(self)*(1.0/4294967296.0); 132 | /* divided by 2^32 */ 133 | } 134 | 135 | /** @brief Generate a random number in (0,1) 136 | ** @param self random number generator. 137 | ** @return a random number. 138 | **/ 139 | 140 | VL_INLINE double 141 | vl_rand_real3 (VlRand * self) 142 | { 143 | return (((double)vl_rand_uint32(self)) + 0.5)*(1.0/4294967296.0); 144 | /* divided by 2^32 */ 145 | } 146 | 147 | /** @brief Generate a random number in [0,1) with 53-bit resolution 148 | ** @param self random number generator. 149 | ** @return a random number. 150 | **/ 151 | 152 | VL_INLINE double 153 | vl_rand_res53 (VlRand * self) 154 | { 155 | vl_uint32 156 | a = vl_rand_uint32(self) >> 5, 157 | b = vl_rand_uint32(self) >> 6 ; 158 | return (a * 67108864.0 + b) * (1.0 / 9007199254740992.0) ; 159 | } 160 | 161 | /* VL_RANDOM_H */ 162 | #endif 163 | -------------------------------------------------------------------------------- /cpp_libs/vl/rodrigues.h: -------------------------------------------------------------------------------- 1 | /** @file rodrigues.h 2 | ** @brief Rodrigues formulas 3 | ** @author Andrea Vedaldi 4 | **/ 5 | 6 | /* 7 | Copyright (C) 2007-13 Andrea Vedaldi and Brian Fulkerson. 8 | All rights reserved. 9 | 10 | This file is part of the VLFeat library and is made available under 11 | the terms of the BSD license (see the COPYING file). 12 | */ 13 | 14 | /** @file rodrigues.h 15 | 16 | @section rodrigues Rodrigues formulas 17 | 18 | - Use ::vl_rodrigues to compute the Rodrigues formula and its derivative. 19 | - Use ::vl_irodrigues to compute the inverse Rodrigues formula and 20 | its derivative. 21 | 22 | **/ 23 | 24 | #ifndef VL_RODRIGUES 25 | #define VL_RODRIGUES 26 | 27 | #include "generic.h" 28 | 29 | VL_EXPORT void vl_rodrigues (double* R_pt, double* dR_pt, const double* om_pt) ; 30 | VL_EXPORT void vl_irodrigues (double* om_pt, double* dom_pt, const double* R_pt) ; 31 | 32 | /* VL_RODRIGUES */ 33 | #endif 34 | -------------------------------------------------------------------------------- /cpp_libs/vl/scalespace.h: -------------------------------------------------------------------------------- 1 | /** @file scalespace.h 2 | ** @brief Scale Space (@ref scalespace) 3 | ** @author Andrea Vedaldi 4 | ** @author Karel Lenc 5 | ** @author Michal Perdoch 6 | **/ 7 | 8 | /* 9 | Copyright (C) 2007-12 Andrea Vedaldi and Brian Fulkerson. 10 | All rights reserved. 11 | 12 | This file is part of the VLFeat library and is made available under 13 | the terms of the BSD license (see the COPYING file). 14 | */ 15 | 16 | #ifndef VL_SCALESPACE_H 17 | #define VL_SCALESPACE_H 18 | 19 | #include "generic.h" 20 | #include "imopv.h" 21 | #include "mathop.h" 22 | 23 | /* ---------------------------------------------------------------- */ 24 | /* VlScaleSpaceGeometry */ 25 | /* ---------------------------------------------------------------- */ 26 | 27 | /** @brief Geometry of a scale space 28 | ** 29 | ** There are a few restrictions on the valid geometrties. 30 | */ 31 | typedef struct _VlScaleSpaceGeometry 32 | { 33 | vl_size width ; /**< Image width */ 34 | vl_size height ; /**< Image height */ 35 | vl_index firstOctave ; /**< Index of the fisrt octave */ 36 | vl_index lastOctave ; /**< Index of the last octave */ 37 | vl_size octaveResolution ; /**< Number of octave subdivisions */ 38 | vl_index octaveFirstSubdivision ; /**< Index of the first octave subdivision */ 39 | vl_index octaveLastSubdivision ; /**< Index of the last octave subdivision */ 40 | double baseScale ; /**< Base smoothing (smoothing of octave 0, level 0) */ 41 | double nominalScale ; /**< Nominal smoothing of the original image */ 42 | } VlScaleSpaceGeometry ; 43 | 44 | VL_EXPORT 45 | vl_bool vl_scalespacegeometry_is_equal (VlScaleSpaceGeometry a, 46 | VlScaleSpaceGeometry b) ; 47 | 48 | /* ---------------------------------------------------------------- */ 49 | /* VlScaleSpaceOctaveGeometry */ 50 | /* ---------------------------------------------------------------- */ 51 | 52 | /** @brief Geometry of one octave of a scale space */ 53 | typedef struct _VlScaleSpaceOctaveGeometry 54 | { 55 | vl_size width ; /**< Width (number of pixels) */ 56 | vl_size height ; /**< Height (number of pixels) */ 57 | double step ; /**< Sampling step (size of a pixel) */ 58 | } VlScaleSpaceOctaveGeometry ; 59 | 60 | /* ---------------------------------------------------------------- */ 61 | /* VlScaleSpace */ 62 | /* ---------------------------------------------------------------- */ 63 | 64 | typedef struct _VlScaleSpace VlScaleSpace ; 65 | 66 | /** @name Create and destroy 67 | ** @{ 68 | **/ 69 | VL_EXPORT VlScaleSpaceGeometry vl_scalespace_get_default_geometry(vl_size width, vl_size height) ; 70 | VL_EXPORT VlScaleSpace * vl_scalespace_new (vl_size width, vl_size height) ; 71 | VL_EXPORT VlScaleSpace * vl_scalespace_new_with_geometry (VlScaleSpaceGeometry geom) ; 72 | VL_EXPORT VlScaleSpace * vl_scalespace_new_copy (VlScaleSpace* src); 73 | VL_EXPORT VlScaleSpace * vl_scalespace_new_shallow_copy (VlScaleSpace* src); 74 | VL_EXPORT void vl_scalespace_delete (VlScaleSpace *self) ; 75 | /** @} */ 76 | 77 | /** @name Process data 78 | ** @{ 79 | **/ 80 | VL_EXPORT void 81 | vl_scalespace_put_image (VlScaleSpace *self, float const* image); 82 | /** @} */ 83 | 84 | /** @name Retrieve data and parameters 85 | ** @{ 86 | **/ 87 | VL_EXPORT VlScaleSpaceGeometry vl_scalespace_get_geometry (VlScaleSpace const * self) ; 88 | VL_EXPORT VlScaleSpaceOctaveGeometry vl_scalespace_get_octave_geometry (VlScaleSpace const * self, vl_index o) ; 89 | VL_EXPORT float * 90 | vl_scalespace_get_level (VlScaleSpace * self, vl_index o, vl_index s) ; 91 | VL_EXPORT float const * 92 | vl_scalespace_get_level_const (VlScaleSpace const * self, vl_index o, vl_index s) ; 93 | VL_EXPORT double 94 | vl_scalespace_get_level_sigma (VlScaleSpace const *self, vl_index o, vl_index s) ; 95 | /** @} */ 96 | 97 | /* VL_SCALESPACE_H */ 98 | #endif 99 | 100 | -------------------------------------------------------------------------------- /cpp_libs/vl/shuffle-def.h: -------------------------------------------------------------------------------- 1 | /** @file shuffle-def.h 2 | ** @brief Shuffle preprocessor metaprogram 3 | ** @author Andrea Vedaldi 4 | **/ 5 | 6 | /* 7 | Copyright (C) 2007-12 Andrea Vedaldi and Brian Fulkerson. 8 | All rights reserved. 9 | 10 | This file is part of the VLFeat library and is made available under 11 | the terms of the BSD license (see the COPYING file). 12 | */ 13 | 14 | /** @file shuffle-def.h 15 | 16 | @todo large array compatibility. 17 | **/ 18 | 19 | #include "host.h" 20 | #include "random.h" 21 | #include 22 | 23 | #ifndef VL_SHUFFLE_prefix 24 | #error "VL_SHUFFLE_prefix must be defined" 25 | #endif 26 | 27 | #ifndef VL_SHUFFLE_array 28 | #ifndef VL_SHUFFLE_type 29 | #error "VL_SHUFFLE_type must be defined if VL_SHUFFLE_array is not" 30 | #endif 31 | #define VL_SHUFFLE_array VL_SHUFFLE_type* 32 | #endif 33 | 34 | #ifdef __DOXYGEN__ 35 | #define VL_SHUFFLE_prefix ShufflePrefix /**< Prefix of the shuffle functions */ 36 | #define VL_SHUFFLE_type ShuffleType /**< Data type of the shuffle elements */ 37 | #define VL_SHUFFLE_array ShuffleType* /**< Data type of the shuffle container */ 38 | #endif 39 | 40 | /* ---------------------------------------------------------------- */ 41 | 42 | #if ! defined(VL_SHUFFLE_swap) || defined(__DOXYGEN__) 43 | #define VL_SHUFFLE_swap VL_XCAT(VL_SHUFFLE_prefix, _swap) 44 | 45 | /** @brief Swap two array elements 46 | ** @param array shuffle array. 47 | ** @param indexA index of the first element to swap. 48 | ** @param indexB index of the second element to swap. 49 | ** 50 | ** The function swaps the two elements @a a and @ b. The function 51 | ** uses a temporary element of type ::VL_SHUFFLE_type 52 | ** and the copy operator @c =. 53 | **/ 54 | 55 | VL_INLINE void 56 | VL_SHUFFLE_swap 57 | (VL_SHUFFLE_array array, 58 | vl_uindex indexA, 59 | vl_uindex indexB) 60 | { 61 | VL_SHUFFLE_type t = array [indexA] ; 62 | array [indexA] = array [indexB] ; 63 | array [indexB] = t ; 64 | } 65 | 66 | /* VL_SHUFFLE_swap */ 67 | #endif 68 | 69 | /* ---------------------------------------------------------------- */ 70 | 71 | #if ! defined(VL_SHUFFLE_shuffle) || defined(__DOXYGEN__) 72 | #define VL_SHUFFLE_shuffle VL_XCAT(VL_SHUFFLE_prefix, _shuffle) 73 | 74 | /** @brief Shuffle 75 | ** @param array (in/out) pointer to the array. 76 | ** @param size size of the array. 77 | ** @param rand random number generator to use. 78 | ** 79 | ** The function randomly permutes the array. 80 | **/ 81 | 82 | VL_INLINE void 83 | VL_SHUFFLE_shuffle 84 | (VL_SHUFFLE_array array, vl_size size, VlRand * rand) 85 | { 86 | vl_uindex n = size ; 87 | while (n > 1) { 88 | vl_uindex k = vl_rand_uindex (rand, n) ; 89 | n -- ; 90 | VL_SHUFFLE_swap (array, n, k) ; 91 | } 92 | } 93 | 94 | /* VL_SHUFFLE_shuffle */ 95 | #endif 96 | 97 | #undef VL_SHUFFLE_prefix 98 | #undef VL_SHUFFLE_swap 99 | #undef VL_SHUFFLE_shuffle 100 | #undef VL_SHUFFLE_type 101 | #undef VL_SHUFFLE_array 102 | -------------------------------------------------------------------------------- /cpp_libs/vl/slic.h: -------------------------------------------------------------------------------- 1 | /** @file slic.h 2 | ** @brief SLIC superpixels (@ref slic) 3 | ** @author Andrea Vedaldi 4 | **/ 5 | 6 | /* 7 | Copyright (C) 2007-12 Andrea Vedaldi and Brian Fulkerson. 8 | All rights reserved. 9 | 10 | This file is part of the VLFeat library and is made available under 11 | the terms of the BSD license (see the COPYING file). 12 | */ 13 | 14 | #ifndef VL_SLIC_H 15 | #define VL_SLIC_H 16 | 17 | #include "generic.h" 18 | 19 | VL_EXPORT void 20 | vl_slic_segment (vl_uint32 * segmentation, 21 | float const * image, 22 | vl_size width, 23 | vl_size height, 24 | vl_size numChannels, 25 | vl_size regionSize, 26 | float regularization, 27 | vl_size minRegionSize) ; 28 | 29 | /* VL_SLIC_H */ 30 | #endif 31 | -------------------------------------------------------------------------------- /cpp_libs/vl/stringop.h: -------------------------------------------------------------------------------- 1 | /** @file stringop.h 2 | ** @brief String operations 3 | ** @author Andrea Vedaldi 4 | **/ 5 | 6 | /* 7 | Copyright (C) 2007-12 Andrea Vedaldi and Brian Fulkerson. 8 | All rights reserved. 9 | 10 | This file is part of the VLFeat library and is made available under 11 | the terms of the BSD license (see the COPYING file). 12 | */ 13 | 14 | #ifndef VL_STRINGOP_H 15 | #define VL_STRINGOP_H 16 | 17 | #include "generic.h" 18 | 19 | /** @brief File protocols */ 20 | enum { 21 | VL_PROT_UNKNOWN = -1, /**< unknown protocol */ 22 | VL_PROT_NONE = 0, /**< no protocol */ 23 | VL_PROT_ASCII, /**< ASCII protocol */ 24 | VL_PROT_BINARY /**< Binary protocol */ 25 | } ; 26 | 27 | 28 | VL_EXPORT vl_size vl_string_copy (char *destination, vl_size destinationSize, char const *source) ; 29 | VL_EXPORT vl_size vl_string_copy_sub (char *destination, vl_size destinationSize, 30 | char const *beginning, char const *end) ; 31 | VL_EXPORT char *vl_string_parse_protocol (char const *string, int *protocol) ; 32 | VL_EXPORT char const *vl_string_protocol_name (int prot) ; 33 | VL_EXPORT vl_size vl_string_basename (char *destination, vl_size destinationSize, 34 | char const *source, vl_size maxNumStrippedExtension) ; 35 | VL_EXPORT vl_size vl_string_replace_wildcard (char * destination, vl_size destinationSize, 36 | char const *src, char wildcardChar, char escapeChar, 37 | char const *replacement) ; 38 | VL_EXPORT char *vl_string_find_char_rev (char const *beginning, char const *end, char c) ; 39 | VL_EXPORT vl_size vl_string_length (char const *string) ; 40 | VL_EXPORT int vl_string_casei_cmp (const char *string1, const char *string2) ; 41 | 42 | /** @name String enumerations 43 | ** @{ */ 44 | 45 | /** @brief Member of an enumeration */ 46 | typedef struct _VlEnumerator 47 | { 48 | char const *name ; /**< enumeration member name. */ 49 | vl_index value ; /**< enumeration member value. */ 50 | } VlEnumerator ; 51 | 52 | VL_EXPORT VlEnumerator *vl_enumeration_get (VlEnumerator const *enumeration, char const *name) ; 53 | VL_EXPORT VlEnumerator *vl_enumeration_get_casei (VlEnumerator const *enumeration, char const *name) ; 54 | VL_EXPORT VlEnumerator *vl_enumeration_get_by_value (VlEnumerator const *enumeration, vl_index value) ; 55 | /** @} */ 56 | 57 | /* VL_STRINGOP_H */ 58 | #endif 59 | -------------------------------------------------------------------------------- /cpp_libs/vl/svmdataset.h: -------------------------------------------------------------------------------- 1 | /** @file svmdataset.h 2 | ** @brief SVM Dataset 3 | ** @author Daniele Perrone 4 | ** @author Andrea Vedaldi 5 | **/ 6 | 7 | /* 8 | Copyright (C) 2012 Daniele Perrone. 9 | Copyright (C) 2013 Andrea Vedaldi. 10 | All rights reserved. 11 | 12 | This file is part of the VLFeat library and is made available under 13 | the terms of the BSD license (see the COPYING file). 14 | */ 15 | 16 | #ifndef VL_SVMDATASET_H 17 | #define VL_SVMDATASET_H 18 | 19 | #include "generic.h" 20 | #include "homkermap.h" 21 | 22 | struct VlSvm_ ; 23 | 24 | /** @typedef VlSvmDataset 25 | ** @brief SVM dataset object 26 | ** 27 | ** This objects contain a training set to be used in combination with 28 | ** the SVM solver object ::VlSvm. Its main purpose is to implement 29 | ** the two basic operations inner product (::VlSvmInnerProductFunction) 30 | ** and accumulation (::VlSvmAccumulateFunction). 31 | ** 32 | ** See @ref svm and @ref svm-advanced for further information. 33 | **/ 34 | 35 | #ifndef __DOXYGEN__ 36 | struct VlSvmDataset_ ; 37 | typedef struct VlSvmDataset_ VlSvmDataset ; 38 | #else 39 | typedef OPAQUE VlSvmDataset ; 40 | #endif 41 | 42 | /** @name SVM callbacks 43 | ** @{ */ 44 | typedef void (*VlSvmDiagnosticFunction) (struct VlSvm_ *svm, void *data) ; 45 | typedef double (*VlSvmLossFunction) (double inner, double label) ; 46 | typedef double (*VlSvmDcaUpdateFunction) (double alpha, double inner, double norm2, double label) ; 47 | typedef double (*VlSvmInnerProductFunction)(const void *data, vl_uindex element, double *model) ; 48 | typedef void (*VlSvmAccumulateFunction) (const void *data, vl_uindex element, double *model, double multiplier) ; 49 | /* typedef double (*VlSvmSquareNormFunction) (const void *data, vl_uindex element) ; */ 50 | /** @} */ 51 | 52 | /** @name Create and destroy 53 | ** @{ 54 | **/ 55 | VL_EXPORT VlSvmDataset* vl_svmdataset_new (vl_type dataType, void *data, vl_size dimension, vl_size numData) ; 56 | VL_EXPORT void vl_svmdataset_delete (VlSvmDataset * dataset) ; 57 | /** @} */ 58 | 59 | /** @name Set parameters 60 | ** @{ 61 | **/ 62 | VL_EXPORT void vl_svmdataset_set_homogeneous_kernel_map (VlSvmDataset * self, 63 | VlHomogeneousKernelMap * hom) ; 64 | /** @} */ 65 | 66 | /** @name Get data and parameters 67 | ** @{ 68 | **/ 69 | VL_EXPORT void* vl_svmdataset_get_data (VlSvmDataset const *self) ; 70 | VL_EXPORT vl_size vl_svmdataset_get_num_data (VlSvmDataset const *self) ; 71 | VL_EXPORT vl_size vl_svmdataset_get_dimension (VlSvmDataset const *self) ; 72 | VL_EXPORT void* vl_svmdataset_get_map (VlSvmDataset const *self) ; 73 | VL_EXPORT vl_size vl_svmdataset_get_mapDim (VlSvmDataset const *self) ; 74 | VL_EXPORT VlSvmAccumulateFunction vl_svmdataset_get_accumulate_function (VlSvmDataset const *self) ; 75 | VL_EXPORT VlSvmInnerProductFunction vl_svmdataset_get_inner_product_function (VlSvmDataset const * self) ; 76 | VL_EXPORT VlHomogeneousKernelMap * vl_svmdataset_get_homogeneous_kernel_map (VlSvmDataset const * self) ; 77 | /** @} */ 78 | 79 | /* VL_SVMDATASET_H */ 80 | #endif 81 | 82 | 83 | -------------------------------------------------------------------------------- /cpp_libs/vl/vlad.h: -------------------------------------------------------------------------------- 1 | /** @file vlad.h 2 | ** @brief VLAD encoding (@ref vlad) 3 | ** @author David Novotny 4 | ** @author Andrea Vedaldi 5 | ** @see @ref vlad 6 | **/ 7 | 8 | /* 9 | Copyright (C) 2013 David Novotny and Andera Vedaldi. 10 | All rights reserved. 11 | 12 | This file is part of the VLFeat library and is made available under 13 | the terms of the BSD license (see the COPYING file). 14 | */ 15 | 16 | #ifndef VL_VLAD_H 17 | #define VL_VLAD_H 18 | 19 | #include "generic.h" 20 | 21 | /** @name VLAD options 22 | ** @{ */ 23 | #define VL_VLAD_FLAG_NORMALIZE_COMPONENTS (0x1 << 0) 24 | #define VL_VLAD_FLAG_SQUARE_ROOT (0x1 << 1) 25 | #define VL_VLAD_FLAG_UNNORMALIZED (0x1 << 2) 26 | #define VL_VLAD_FLAG_NORMALIZE_MASS (0x1 << 3) 27 | 28 | /** @def VL_VLAD_FLAG_NORMALIZE_COMPONENTS 29 | ** @brief Normalize each VLAD component individually. 30 | **/ 31 | 32 | /** @def VL_VLAD_FLAG_SQUARE_ROOT 33 | ** @brief Use signed squared-root. 34 | **/ 35 | 36 | /** @def VL_VLAD_FLAG_UNNORMALIZED 37 | ** @brief Do not globally normalize the VLAD descriptor. 38 | **/ 39 | 40 | /** @def VL_VLAD_FLAG_NORMALIZE_MASS 41 | ** @brief Normalize each component by the number of features assigned to it. 42 | **/ 43 | /** @} */ 44 | 45 | VL_EXPORT void vl_vlad_encode 46 | (void * enc, vl_type dataType, 47 | void const * means, vl_size dimension, vl_size numClusters, 48 | void const * data, vl_size numData, 49 | void const * assignments, 50 | int flags) ; 51 | 52 | /* VL_VLAD_H */ 53 | #endif 54 | -------------------------------------------------------------------------------- /hesaffnet/HardNet.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import torch 3 | import torch.nn as nn 4 | import torch.nn.functional as F 5 | from torch.autograd import Variable 6 | import torch.backends.cudnn as cudnn 7 | import time 8 | import os 9 | import math 10 | import numpy as np 11 | 12 | class L2Norm(nn.Module): 13 | def __init__(self): 14 | super(L2Norm,self).__init__() 15 | self.eps = 1e-8 16 | def forward(self, x): 17 | norm = torch.sqrt(torch.sum(x * x, dim = 1) + self.eps) 18 | x= x / norm.unsqueeze(-1).expand_as(x) 19 | return x 20 | 21 | class L1Norm(nn.Module): 22 | def __init__(self): 23 | super(L1Norm,self).__init__() 24 | self.eps = 1e-10 25 | def forward(self, x): 26 | norm = torch.sum(torch.abs(x), dim = 1) + self.eps 27 | x= x / norm.expand_as(x) 28 | return x 29 | 30 | class HardNetNarELU(nn.Module): 31 | """TFeat model definition 32 | """ 33 | 34 | def __init__(self,sm): 35 | super(HardNetNarELU, self).__init__() 36 | 37 | self.features = nn.Sequential( 38 | nn.Conv2d(1, 16, kernel_size=3, padding=1), 39 | nn.ELU(), 40 | nn.Conv2d(16, 16, kernel_size=3, padding=1), 41 | nn.ELU(), 42 | nn.Conv2d(16, 32, kernel_size=3, stride=2, padding=1), 43 | nn.ELU(), 44 | nn.Conv2d(32, 32, kernel_size=3, padding=1), 45 | nn.ELU(), 46 | nn.Conv2d(32, 64, kernel_size=3, stride=2,padding=1), 47 | nn.ELU(), 48 | nn.Conv2d(64, 64, kernel_size=3, padding=1), 49 | nn.ELU() 50 | ) 51 | self.classifier = nn.Sequential( 52 | nn.Dropout(0.1), 53 | nn.Conv2d(64, 128, kernel_size=8), 54 | nn.BatchNorm2d(128, affine=False)) 55 | self.SIFT = sm 56 | return 57 | 58 | def input_norm(self,x): 59 | flat = x.view(x.size(0), -1) 60 | mp = torch.mean(flat, dim=1) 61 | sp = torch.std(flat, dim=1) + 1e-7 62 | #print(sp) 63 | return (x - mp.unsqueeze(-1).unsqueeze(-1).unsqueeze(-1).expand_as(x)) / sp.unsqueeze(-1).unsqueeze(-1).unsqueeze(1).expand_as(x) 64 | 65 | def forward(self, input): 66 | x_features = self.features(input)#self.input_norm(input)) 67 | #x = self.classifier[1](x_features) 68 | x = nn.AdaptiveAvgPool2d(1)(x_features).view(x_features.size(0), -1) 69 | return x 70 | #return L2Norm()(x) 71 | 72 | 73 | class HardNet(nn.Module): 74 | """HardNet model definition 75 | """ 76 | def __init__(self): 77 | super(HardNet, self).__init__() 78 | 79 | self.features = nn.Sequential( 80 | nn.Conv2d(1, 32, kernel_size=3, padding=1, bias = False), 81 | nn.BatchNorm2d(32, affine=False), 82 | nn.ReLU(), 83 | nn.Conv2d(32, 32, kernel_size=3, padding=1, bias = False), 84 | nn.BatchNorm2d(32, affine=False), 85 | nn.ReLU(), 86 | nn.Conv2d(32, 64, kernel_size=3, stride=2, padding=1, bias = False), 87 | nn.BatchNorm2d(64, affine=False), 88 | nn.ReLU(), 89 | nn.Conv2d(64, 64, kernel_size=3, padding=1, bias = False), 90 | nn.BatchNorm2d(64, affine=False), 91 | nn.ReLU(), 92 | nn.Conv2d(64, 128, kernel_size=3, stride=2,padding=1, bias = False), 93 | nn.BatchNorm2d(128, affine=False), 94 | nn.ReLU(), 95 | nn.Conv2d(128, 128, kernel_size=3, padding=1, bias = False), 96 | nn.BatchNorm2d(128, affine=False), 97 | nn.ReLU(), 98 | nn.Dropout(0.1), 99 | nn.Conv2d(128, 128, kernel_size=8, bias = False), 100 | nn.BatchNorm2d(128, affine=False), 101 | ) 102 | #self.features.apply(weights_init) 103 | 104 | def input_norm(self,x): 105 | flat = x.view(x.size(0), -1) 106 | mp = torch.mean(flat, dim=1) 107 | sp = torch.std(flat, dim=1) + 1e-7 108 | return (x - mp.detach().unsqueeze(-1).unsqueeze(-1).unsqueeze(-1).expand_as(x)) / sp.detach().unsqueeze(-1).unsqueeze(-1).unsqueeze(1).expand_as(x) 109 | 110 | def forward(self, input): 111 | x_features = self.features(self.input_norm(input)) 112 | x = x_features.view(x_features.size(0), -1) 113 | return L2Norm()(x) 114 | -------------------------------------------------------------------------------- /hesaffnet/NMS.py: -------------------------------------------------------------------------------- 1 | import torch 2 | from torch import nn 3 | import torch.nn.functional as F 4 | from torch.autograd import Variable 5 | from Utils import CircularGaussKernel, generate_2dgrid, generate_2dgrid, generate_3dgrid, zero_response_at_border 6 | from LAF import sc_y_x2LAFs 7 | 8 | class NMS2d(nn.Module): 9 | def __init__(self, kernel_size = 3, threshold = 0): 10 | super(NMS2d, self).__init__() 11 | self.MP = nn.MaxPool2d(kernel_size, stride=1, return_indices=False, padding = kernel_size/2) 12 | self.eps = 1e-5 13 | self.th = threshold 14 | return 15 | def forward(self, x): 16 | #local_maxima = self.MP(x) 17 | if self.th > self.eps: 18 | return x * (x > self.th).float() * ((x + self.eps - self.MP(x)) > 0).float() 19 | else: 20 | return ((x - self.MP(x) + self.eps) > 0).float() * x 21 | 22 | class NMS3d(nn.Module): 23 | def __init__(self, kernel_size = 3, threshold = 0): 24 | super(NMS3d, self).__init__() 25 | self.MP = nn.MaxPool3d(kernel_size, stride=1, return_indices=False, padding = (0, kernel_size/2, kernel_size/2)) 26 | self.eps = 1e-5 27 | self.th = threshold 28 | return 29 | def forward(self, x): 30 | #local_maxima = self.MP(x) 31 | if self.th > self.eps: 32 | return x * (x > self.th).float() * ((x + self.eps - self.MP(x)) > 0).float() 33 | else: 34 | return ((x - self.MP(x) + self.eps) > 0).float() * x 35 | 36 | 37 | class NMS3dAndComposeA(nn.Module): 38 | def __init__(self,kernel_size = 3, threshold = 0, scales = None, border = 3, mrSize = 1.0): 39 | super(NMS3dAndComposeA, self).__init__() 40 | self.eps = 1e-7 41 | self.ks = 3 42 | if type(scales) is not list: 43 | self.grid = generate_3dgrid(3,self.ks,self.ks) 44 | else: 45 | self.grid = generate_3dgrid(scales,self.ks,self.ks) 46 | self.grid = Variable(self.grid.t().contiguous().view(3,3,3,3), requires_grad=False) 47 | self.th = threshold 48 | self.cube_idxs = [] 49 | self.border = border 50 | self.mrSize = mrSize 51 | self.beta = 1.0 52 | self.grid_ones = Variable(torch.ones(3,3,3,3), requires_grad=False) 53 | self.NMS3d = NMS3d(kernel_size, threshold) 54 | return 55 | def forward(self, low, cur, high, octaveMap = None, num_features = 0): 56 | assert low.size() == cur.size() == high.size() 57 | 58 | #Filter responce map 59 | self.is_cuda = low.is_cuda; 60 | resp3d = torch.cat([low,cur,high], dim = 1) 61 | 62 | mrSize_border = int(self.mrSize); 63 | if octaveMap is not None: 64 | nmsed_resp = zero_response_at_border(self.NMS3d(resp3d.unsqueeze(1)).squeeze(1)[:,1:2,:,:], mrSize_border) * (1. - octaveMap.float()) 65 | else: 66 | nmsed_resp = zero_response_at_border(self.NMS3d(resp3d.unsqueeze(1)).squeeze(1)[:,1:2,:,:], mrSize_border) 67 | 68 | num_of_nonzero_responces = (nmsed_resp > 0).sum().data[0] 69 | if (num_of_nonzero_responces == 0): 70 | return None,None,None 71 | if octaveMap is not None: 72 | octaveMap = (octaveMap.float() + nmsed_resp.float()).byte() 73 | 74 | nmsed_resp = nmsed_resp.view(-1) 75 | if (num_features > 0) and (num_features < num_of_nonzero_responces): 76 | nmsed_resp, idxs = torch.topk(nmsed_resp, k = num_features); 77 | else: 78 | idxs = nmsed_resp.data.nonzero().squeeze() 79 | nmsed_resp = nmsed_resp[idxs] 80 | 81 | #Get point coordinates 82 | 83 | spatial_grid = Variable(generate_2dgrid(low.size(2), low.size(3), False)).view(1,low.size(2), low.size(3),2) 84 | spatial_grid = spatial_grid.permute(3,1, 2, 0) 85 | if self.is_cuda: 86 | spatial_grid = spatial_grid.cuda() 87 | self.grid = self.grid.cuda() 88 | self.grid_ones = self.grid_ones.cuda() 89 | #residual_to_patch_center 90 | sc_y_x = F.conv2d(resp3d, self.grid, 91 | padding = 1) / (F.conv2d(resp3d, self.grid_ones, padding = 1) + 1e-8) 92 | 93 | ##maxima coords 94 | sc_y_x[0,1:,:,:] = sc_y_x[0,1:,:,:] + spatial_grid[:,:,:,0] 95 | sc_y_x = sc_y_x.view(3,-1).t() 96 | sc_y_x = sc_y_x[idxs,:] 97 | 98 | min_size = float(min((cur.size(2)), cur.size(3))) 99 | sc_y_x[:,0] = sc_y_x[:,0] / min_size 100 | sc_y_x[:,1] = sc_y_x[:,1] / float(cur.size(2)) 101 | sc_y_x[:,2] = sc_y_x[:,2] / float(cur.size(3)) 102 | 103 | return nmsed_resp, sc_y_x2LAFs(sc_y_x), octaveMap -------------------------------------------------------------------------------- /hesaffnet/extract_geomOriTh.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python2 -utt 2 | # -*- coding: utf-8 -*- 3 | from __future__ import print_function 4 | import torch 5 | import torch.nn as nn 6 | import numpy as np 7 | import sys 8 | import os 9 | import time 10 | 11 | from PIL import Image 12 | from torch.autograd import Variable 13 | import torch.backends.cudnn as cudnn 14 | import torch.optim as optim 15 | from tqdm import tqdm 16 | import math 17 | import torch.nn.functional as F 18 | 19 | from copy import deepcopy 20 | from HardNet import HardNet 21 | from OnePassSIR import OnePassSIR 22 | from LAF import denormalizeLAFs, LAFs2ell,LAFs2ellT, abc2A 23 | from Utils import line_prepender 24 | from architectures import AffNetFastFullAff, OriNetFast 25 | from time import time 26 | USE_CUDA = True 27 | 28 | try: 29 | input_img_fname = sys.argv[1] 30 | output_fname = sys.argv[2] 31 | th = 28.41#float(sys.argv[3]) 32 | except: 33 | print("Wrong input format. Try python hesaffnet.py imgs/cat.png cat.txt 5.3333") 34 | sys.exit(1) 35 | 36 | def get_geometry_and_descriptors(img, det,desc): 37 | with torch.no_grad(): 38 | tt = time() 39 | LAFs, resp = det(img) 40 | print(('det time = ', time() - tt)) 41 | tt = time() 42 | patches = det.extract_patches_from_pyr(LAFs, PS = 32) 43 | print(('extract time = ', time() - tt)) 44 | tt = time() 45 | descriptors = desc(patches) 46 | print(('desc time = ', time() - tt)) 47 | return LAFs, descriptors 48 | def load_grayscale_var(fname): 49 | img = Image.open(fname).convert('RGB') 50 | img = np.mean(np.array(img), axis = 2) 51 | var_image = torch.autograd.Variable(torch.from_numpy(img.astype(np.float32)), volatile = True) 52 | var_image_reshape = var_image.view(1, 1, var_image.size(0),var_image.size(1)) 53 | if USE_CUDA: 54 | var_image_reshape = var_image_reshape.cuda() 55 | return var_image_reshape 56 | 57 | 58 | img = load_grayscale_var(input_img_fname) 59 | AffNetPix = AffNetFastFullAff(PS = 32) 60 | weightd_fname = 'hesaffnet/pretrained/AffNet.pth' 61 | checkpoint = torch.load(weightd_fname) 62 | AffNetPix.load_state_dict(checkpoint['state_dict']) 63 | AffNetPix.eval() 64 | ONet = OriNetFast(PS =32) 65 | o_fname = 'hesaffnet/pretrained/OriNet.pth' 66 | checkpoint = torch.load(o_fname) 67 | ONet.load_state_dict(checkpoint['state_dict']) 68 | ONet.eval() 69 | descriptor = HardNet() 70 | model_weights = 'hesaffnet/pretrained/HardNet++.pth' 71 | hncheckpoint = torch.load(model_weights) 72 | descriptor.load_state_dict(hncheckpoint['state_dict']) 73 | descriptor.eval() 74 | 75 | HA = OnePassSIR( mrSize = 5.192, num_features = -1, th = th, border = 15, num_Baum_iters = 1, AffNet = AffNetPix, OriNet = ONet) 76 | import scipy.io as sio 77 | if USE_CUDA: 78 | HA = HA.cuda() 79 | descriptor = descriptor.cuda() 80 | with torch.no_grad(): 81 | t = time() 82 | LAFs,descs = get_geometry_and_descriptors(img, HA,descriptor) 83 | #lt = time() 84 | #ells = LAFs2ellT(LAFs.cpu()).cpu().numpy() 85 | #print ('LAFs2ell time', time() - lt) 86 | #print ('Total time', time() - t) 87 | #sio.savemat('descs.mat', {'descs': descs.cpu().numpy()}) 88 | #sio.savemat('geoms.mat', {'LAFs': LAFs.cpu().numpy()}) 89 | np.save('lafs1.npy',LAFs.cpu().numpy()) 90 | #np.savetxt(output_fname, ells, delimiter=' ', fmt='%10.10f') 91 | #line_prepender(output_fname, str(len(ells))) 92 | #line_prepender(output_fname, '1.0') 93 | #torch.save(descs, 'dd.t7') 94 | -------------------------------------------------------------------------------- /hesaffnet/extract_geom_and_desc_upisup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python2 -utt 2 | # -*- coding: utf-8 -*- 3 | from __future__ import print_function 4 | import torch 5 | import torch.nn as nn 6 | import numpy as np 7 | import sys 8 | import os 9 | import time 10 | 11 | from PIL import Image 12 | from torch.autograd import Variable 13 | import torch.backends.cudnn as cudnn 14 | import torch.optim as optim 15 | from tqdm import tqdm 16 | import math 17 | import torch.nn.functional as F 18 | 19 | from copy import deepcopy 20 | from HardNet import HardNet 21 | from OnePassSIR import OnePassSIR 22 | from LAF import denormalizeLAFs, LAFs2ell,LAFs2ellT, abc2A 23 | from Utils import line_prepender 24 | from architectures import AffNetFastFullAff 25 | from time import time 26 | USE_CUDA = True 27 | 28 | try: 29 | input_img_fname = sys.argv[1] 30 | output_fname = sys.argv[2] 31 | nfeats = int(sys.argv[3]) 32 | except: 33 | print("Wrong input format. Try python hesaffnet.py imgs/cat.png cat.txt 2000") 34 | sys.exit(1) 35 | 36 | def get_geometry_and_descriptors(img, det, desc): 37 | with torch.no_grad(): 38 | tt = time() 39 | LAFs, resp = det(img) 40 | print(('det time = ', time() - tt)) 41 | tt = time() 42 | patches = det.extract_patches_from_pyr(LAFs, PS = 32) 43 | print(('extract time = ', time() - tt)) 44 | tt = time() 45 | descriptors = desc(patches) 46 | print(('desc time = ', time() - tt)) 47 | return LAFs, descriptors 48 | def load_grayscale_var(fname): 49 | img = Image.open(fname).convert('RGB') 50 | img = np.mean(np.array(img), axis = 2) 51 | var_image = torch.autograd.Variable(torch.from_numpy(img.astype(np.float32)), volatile = True) 52 | var_image_reshape = var_image.view(1, 1, var_image.size(0),var_image.size(1)) 53 | if USE_CUDA: 54 | var_image_reshape = var_image_reshape.cuda() 55 | return var_image_reshape 56 | 57 | 58 | img = load_grayscale_var(input_img_fname) 59 | AffNetPix = AffNetFastFullAff(PS = 32) 60 | weightd_fname = 'hesaffnet/pretrained/AffNet.pth' 61 | checkpoint = torch.load(weightd_fname) 62 | AffNetPix.load_state_dict(checkpoint['state_dict']) 63 | AffNetPix.eval() 64 | HA = OnePassSIR( mrSize = 5.192, num_features = nfeats, border = 15, num_Baum_iters = 1, AffNet = AffNetPix) 65 | descriptor = HardNet() 66 | model_weights = 'hesaffnet/pretrained/HardNet++.pth' 67 | hncheckpoint = torch.load(model_weights) 68 | descriptor.load_state_dict(hncheckpoint['state_dict']) 69 | descriptor.eval() 70 | if USE_CUDA: 71 | HA = HA.cuda() 72 | descriptor = descriptor.cuda() 73 | with torch.no_grad(): 74 | t = time() 75 | LAFs, descriptors = get_geometry_and_descriptors(img, HA, descriptor) 76 | lt = time() 77 | ells = LAFs2ellT(LAFs.cpu()).cpu().numpy() 78 | print(('LAFs2ell time', time() - lt)) 79 | print(('Total time', time() - t)) 80 | np.savetxt(output_fname, ells, delimiter=' ', fmt='%10.10f') 81 | line_prepender(output_fname, str(len(ells))) 82 | line_prepender(output_fname, '1.0') 83 | -------------------------------------------------------------------------------- /hesaffnet/extract_geom_and_desc_upisupTh.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python2 -utt 2 | # -*- coding: utf-8 -*- 3 | from __future__ import print_function 4 | import torch 5 | import torch.nn as nn 6 | import numpy as np 7 | import sys 8 | import os 9 | import time 10 | 11 | from PIL import Image 12 | from torch.autograd import Variable 13 | import torch.backends.cudnn as cudnn 14 | import torch.optim as optim 15 | from tqdm import tqdm 16 | import math 17 | import torch.nn.functional as F 18 | 19 | from copy import deepcopy 20 | from HardNet import HardNet 21 | from OnePassSIR import OnePassSIR 22 | from LAF import denormalizeLAFs, LAFs2ell,LAFs2ellT, abc2A 23 | from Utils import line_prepender 24 | from architectures import AffNetFastFullAff 25 | from time import time 26 | USE_CUDA = True 27 | 28 | try: 29 | input_img_fname = sys.argv[1] 30 | output_fname = sys.argv[2] 31 | th = float(sys.argv[3]) 32 | except: 33 | print("Wrong input format. Try python hesaffnet.py imgs/cat.png cat.txt 5.3333") 34 | sys.exit(1) 35 | 36 | def get_geometry_and_descriptors(img, det, desc): 37 | with torch.no_grad(): 38 | tt = time() 39 | LAFs, resp = det(img) 40 | print(('det time = ', time() - tt)) 41 | tt = time() 42 | patches = det.extract_patches_from_pyr(LAFs, PS = 32) 43 | print(('extract time = ', time() - tt)) 44 | tt = time() 45 | descriptors = desc(patches) 46 | print(('desc time = ', time() - tt)) 47 | return LAFs, descriptors 48 | def load_grayscale_var(fname): 49 | img = Image.open(fname).convert('RGB') 50 | img = np.mean(np.array(img), axis = 2) 51 | var_image = torch.autograd.Variable(torch.from_numpy(img.astype(np.float32)), volatile = True) 52 | var_image_reshape = var_image.view(1, 1, var_image.size(0),var_image.size(1)) 53 | if USE_CUDA: 54 | var_image_reshape = var_image_reshape.cuda() 55 | return var_image_reshape 56 | 57 | 58 | img = load_grayscale_var(input_img_fname) 59 | AffNetPix = AffNetFastFullAff(PS = 32) 60 | weightd_fname = 'hesaffnet/pretrained/AffNet.pth' 61 | checkpoint = torch.load(weightd_fname) 62 | AffNetPix.load_state_dict(checkpoint['state_dict']) 63 | AffNetPix.eval() 64 | HA = OnePassSIR( mrSize = 5.192, num_features = -1, th = th, border = 15, num_Baum_iters = 1, AffNet = AffNetPix) 65 | descriptor = HardNet() 66 | model_weights = 'hesaffnet/pretrained/HardNet++.pth' 67 | hncheckpoint = torch.load(model_weights) 68 | descriptor.load_state_dict(hncheckpoint['state_dict']) 69 | descriptor.eval() 70 | if USE_CUDA: 71 | HA = HA.cuda() 72 | descriptor = descriptor.cuda() 73 | with torch.no_grad(): 74 | t = time() 75 | LAFs, descriptors = get_geometry_and_descriptors(img, HA, descriptor) 76 | lt = time() 77 | ells = LAFs2ellT(LAFs.cpu()).cpu().numpy() 78 | print(('LAFs2ell time', time() - lt)) 79 | print(('Total time', time() - t)) 80 | np.savetxt(output_fname, ells, delimiter=' ', fmt='%10.10f') 81 | line_prepender(output_fname, str(len(ells))) 82 | line_prepender(output_fname, '1.0') 83 | -------------------------------------------------------------------------------- /hesaffnet/hesaffBaum.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python2 -utt 2 | # -*- coding: utf-8 -*- 3 | from __future__ import print_function 4 | import torch 5 | import torch.nn as nn 6 | import numpy as np 7 | import sys 8 | import os 9 | import time 10 | 11 | from PIL import Image 12 | from torch.autograd import Variable 13 | import torch.backends.cudnn as cudnn 14 | import torch.optim as optim 15 | from tqdm import tqdm 16 | import math 17 | import torch.nn.functional as F 18 | 19 | from copy import deepcopy 20 | 21 | from SparseImgRepresenter import ScaleSpaceAffinePatchExtractor 22 | from LAF import denormalizeLAFs, LAFs2ellT, abc2A 23 | from Utils import line_prepender 24 | from architectures import AffNetFast 25 | from HandCraftedModules import AffineShapeEstimator 26 | USE_CUDA = False 27 | try: 28 | input_img_fname = sys.argv[1] 29 | output_fname = sys.argv[2] 30 | nfeats = int(sys.argv[3]) 31 | except: 32 | print("Wrong input format. Try python hesaffBaum.py imgs/cat.png cat.txt 2000") 33 | sys.exit(1) 34 | 35 | img = Image.open(input_img_fname).convert('RGB') 36 | img = np.mean(np.array(img), axis = 2) 37 | 38 | var_image = torch.autograd.Variable(torch.from_numpy(img.astype(np.float32)), volatile = True) 39 | var_image_reshape = var_image.view(1, 1, var_image.size(0),var_image.size(1)) 40 | 41 | HA = ScaleSpaceAffinePatchExtractor( mrSize = 5.192, num_features = nfeats, border = 5, num_Baum_iters = 16, AffNet = AffineShapeEstimator(patch_size=19)) 42 | if USE_CUDA: 43 | HA = HA.cuda() 44 | var_image_reshape = var_image_reshape.cuda() 45 | 46 | LAFs, resp = HA(var_image_reshape) 47 | ells = LAFs2ellT(LAFs.cpu()).cpu().numpy() 48 | 49 | np.savetxt(output_fname, ells, delimiter=' ', fmt='%10.10f') 50 | line_prepender(output_fname, str(len(ells))) 51 | line_prepender(output_fname, '1.0') 52 | -------------------------------------------------------------------------------- /hesaffnet/pretrained/AffNet.pth: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rdguez-mariano/locate/599e9e1400b74c07091e29c932b625c3c0237000/hesaffnet/pretrained/AffNet.pth -------------------------------------------------------------------------------- /hesaffnet/pretrained/AffNetFast.caffemodel: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rdguez-mariano/locate/599e9e1400b74c07091e29c932b625c3c0237000/hesaffnet/pretrained/AffNetFast.caffemodel -------------------------------------------------------------------------------- /hesaffnet/pretrained/HardNet++.pth: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rdguez-mariano/locate/599e9e1400b74c07091e29c932b625c3c0237000/hesaffnet/pretrained/HardNet++.pth -------------------------------------------------------------------------------- /hesaffnet/pretrained/HardTFeat.pth: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rdguez-mariano/locate/599e9e1400b74c07091e29c932b625c3c0237000/hesaffnet/pretrained/HardTFeat.pth -------------------------------------------------------------------------------- /hesaffnet/pretrained/OriNet.pth: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rdguez-mariano/locate/599e9e1400b74c07091e29c932b625c3c0237000/hesaffnet/pretrained/OriNet.pth -------------------------------------------------------------------------------- /model-data/model.AID_simCos_BigDesc_dropout_75.hdf5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rdguez-mariano/locate/599e9e1400b74c07091e29c932b625c3c0237000/model-data/model.AID_simCos_BigDesc_dropout_75.hdf5 -------------------------------------------------------------------------------- /model-data/model.DA_Pts_dropout_L1_75.hdf5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rdguez-mariano/locate/599e9e1400b74c07091e29c932b625c3c0237000/model-data/model.DA_Pts_dropout_L1_75.hdf5 -------------------------------------------------------------------------------- /py-tools/gen-GuidedMatching-Teaserimages-WACV20.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import sys 3 | sys.path.append(".") 4 | from library import * 5 | from libLocalDesc import * 6 | from acc_test_library import * 7 | from matplotlib import pyplot as plt 8 | plt.switch_backend('agg') 9 | 10 | 11 | ds = LoadDatasets() 12 | 13 | def CorrectMatches(matches,kplistq, kplistt, H, thres = 10): 14 | goodM = [] 15 | AvDist = 0 16 | for m in matches: 17 | x = kplistq[m.queryIdx].pt + tuple([1]) 18 | x = np.array(x).reshape(3,1) 19 | Hx = np.matmul(H, x) 20 | Hx = Hx/Hx[2] 21 | 22 | y =kplistt[m.trainIdx].pt 23 | thisdist = cv2.norm(Hx[0:2],y) 24 | if thisdist <= thres: 25 | goodM.append(m) 26 | AvDist += thisdist 27 | if len(goodM)>0: 28 | AvDist = AvDist/len(goodM) 29 | else: 30 | AvDist = -1 31 | return goodM, AvDist 32 | 33 | 34 | 35 | # p = ds[0].datapairs[11] 36 | p = ds[0].datapairs[0] 37 | 38 | total, good_HC, kplistq, kplistt, H, ET_KP, ET_M = siftAID(p.query,p.target, GetAllMatches = True, MatchingThres = 4000, Simi = 'SignProx', GFilter='USAC_H') 39 | cmHC, _ = CorrectMatches(good_HC,kplistq, kplistt, p.Tmatrix ) 40 | cmT, _ = CorrectMatches(total,kplistq, kplistt, p.Tmatrix ) 41 | 42 | 43 | img1 = cv2.drawMatches(p.query, kplistq,p.target, kplistt, total, None,flags=2,matchColor=(0, 255, 0)) 44 | cv2.imwrite('./temp/siftaid_total_matches.png',img1) 45 | img1 = cv2.drawMatches(p.query, kplistq,p.target, kplistt, cmHC, None,flags=2,matchColor=(0, 255, 0)) 46 | cv2.imwrite('./temp/siftaid_cmHC_matches.png',img1) 47 | img1 = cv2.drawMatches(p.query, kplistq,p.target, kplistt, cmT, None,flags=2,matchColor=(0, 255, 0)) 48 | cv2.imwrite('./temp/siftaid_cmT_matches.png',img1) 49 | 50 | 51 | total, good_HC, kplistq, kplistt, H, ET_KP, ET_M = siftAID(p.query,p.target, MatchingThres = 4000, Simi='SignProx', knn_num = 1, GFilter='USAC_H', RegionGrowingIters=4) 52 | cmHC, _ = CorrectMatches(good_HC,kplistq, kplistt, p.Tmatrix ) 53 | cmT, _ = CorrectMatches(total,kplistq, kplistt, p.Tmatrix ) 54 | 55 | img1 = cv2.drawMatches(p.query, kplistq,p.target, kplistt, total, None,flags=2,matchColor=(0, 255, 0)) 56 | cv2.imwrite('./temp/Guided_siftaid_total_matches.png',img1) 57 | img1 = cv2.drawMatches(p.query, kplistq,p.target, kplistt, cmHC, None,flags=2,matchColor=(0, 255, 0)) 58 | cv2.imwrite('./temp/Guided_siftaid_cmHC_matches.png',img1) 59 | img1 = cv2.drawMatches(p.query, kplistq,p.target, kplistt, cmT, None,flags=2,matchColor=(0, 255, 0)) 60 | cv2.imwrite('./temp/Guided_siftaid_cmT_matches.png',img1) -------------------------------------------------------------------------------- /py-tools/in2blocks.py: -------------------------------------------------------------------------------- 1 | import sys 2 | sys.path.append(".") 3 | 4 | from library import * 5 | import time 6 | 7 | 8 | while True: 9 | print("GAtrain") 10 | GAtrain = GenAffine("./imgs-train/", save_path = "./db-gen-train/") 11 | GAtrain.LastTimeDataChecked = 0 12 | GAtrain.ScatteredGenData_2_BlockData() 13 | 14 | print("GAval") 15 | GAval = GenAffine("./imgs-val/", save_path = "./db-gen-val/") 16 | GAval.LastTimeDataChecked = 0 17 | GAval.ScatteredGenData_2_BlockData() 18 | 19 | # print("GAtest") 20 | # GAval = GenAffine("./imgs-test/", save_path = "./db-gen-test/") 21 | # GAval.LastTimeDataChecked = 0 22 | # GAval.ScatteredGenData_2_BlockData() 23 | 24 | # Sleep 30 minutes 25 | time.sleep(60*30) 26 | 27 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | ipykernel==4.8.0 2 | ipython==6.2.1 3 | ipython-genutils==0.2.0 4 | jupyter==1.0.0 5 | jupyter-client==5.2.2 6 | jupyter-console==5.2.0 7 | jupyter-core==4.4.0 8 | keras==2.10.0 9 | matplotlib==2.1.2 10 | nbconvert==5.3.1 11 | nbformat==4.4.0 12 | notebook==5.7.8 13 | numpy==1.23.3 14 | opencv-python==3.4.18.65 15 | opencv-contrib-python==3.4.18.65 16 | scikit-learn==1.1.2 17 | scipy==1.9.1 18 | bleach==1.5.0 19 | tensorboard==2.10.0 20 | tensorflow-estimator==2.10.0 21 | tensorflow-gpu==2.10.0 22 | psutil==5.9.2 23 | tqdm==4.48.2 24 | torch==1.12.1 25 | torchvision==0.13.1 26 | Pillow==9.2.0 27 | seaborn==0.9.0 28 | --------------------------------------------------------------------------------