From 3118053b5b576b1b91cdfafefa9898a915c3f45f Mon Sep 17 00:00:00 2001 From: Josh Klontz Date: Fri, 22 Feb 2013 17:37:42 -0500 Subject: [PATCH] NEC Latent wrapper --- .gitignore | 1 + CMakeLists.txt | 6 ++++++ sdk/plugins/neclatent1.cmake | 8 ++++++++ sdk/plugins/neclatent1.cpp | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ share/openbr/cmake/FindNECLatent1.cmake | 14 ++++++++++++++ share/openbr/cmake/InstallDependencies.cmake | 6 +----- 6 files changed, 111 insertions(+), 5 deletions(-) create mode 100644 sdk/plugins/neclatent1.cmake create mode 100644 sdk/plugins/neclatent1.cpp create mode 100644 share/openbr/cmake/FindNECLatent1.cmake diff --git a/.gitignore b/.gitignore index c1b9abf..7977fc1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ ### Repository Specific ### build* +3rdparty/LatentSDK* 3rdparty/pittpatt* ### Generic ### diff --git a/CMakeLists.txt b/CMakeLists.txt index 14a211c..3d9f6f0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,12 @@ set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md") set(CMAKE_MODULE_PATH "${BR_SHARE_DIR}/cmake" ${CMAKE_MODULE_PATH}) set(PACKAGE_YEAR 2012) +if(${CMAKE_SIZEOF_VOID_P} MATCHES 8) + set(BITNESS 64) +else() + set(BITNESS 32) +endif() + # Define resources if(WIN32) set(CPACK_PACKAGE_ICON "${BR_SHARE_DIR}\\\\openbr-small.png") diff --git a/sdk/plugins/neclatent1.cmake b/sdk/plugins/neclatent1.cmake new file mode 100644 index 0000000..c77bd11 --- /dev/null +++ b/sdk/plugins/neclatent1.cmake @@ -0,0 +1,8 @@ +set(BR_WITH_NECLATENT1 OFF CACHE BOOL "Build with NEC Latent SDK 1") + +if(${BR_WITH_NECLATENT1}) + find_package(NECLATENT1 REQUIRED) + set(BR_THIRDPARTY_SRC ${BR_THIRDPARTY_SRC} plugins/neclatent1.cpp) + set(BR_THIRDPARTY_LIBS ${BR_THIRDPARTY_LIBS} ${NECLATENT1_LIBS}) + install(DIRECTORY ${NECLATENT1_BIN_DIR}/ DESTINATION bin) +endif() diff --git a/sdk/plugins/neclatent1.cpp b/sdk/plugins/neclatent1.cpp new file mode 100644 index 0000000..3fb877b --- /dev/null +++ b/sdk/plugins/neclatent1.cpp @@ -0,0 +1,81 @@ +#include +#include + +// necessary to allocate a large memory though the actual template size +// may be much smaller +#define MAX_TEMPLATE_SIZE 400000 + +namespace br +{ + +/*! + * \ingroup initializers + * \brief Initialize the NEC Latent SDK wrapper. + * \author Josh Klontz \cite jklontz + */ +class NECLatent1Initialier : public Initializer +{ + Q_OBJECT + + void initialize() const + { + Globals->abbreviations.insert("NECLatent1", "Open+Cvt(Gray)+NECLatent1Enroll:NECLatent1Compare"); + } +}; + +BR_REGISTER(Initializer, NECLatent1Initialier) + +/*! + * \ingroup transforms + * \brief Enroll an NEC latent fingerprint. + * \author Josh Klontz \cite jklontz + */ +class NECLatent1EnrollTransform : public UntrainableTransform +{ + Q_OBJECT + + void project(const Template &src, Template &dst) const + { + if (src.m().type() != CV_8UC1) qFatal("Requires 8UC1 data!"); + unsigned char *data = new unsigned char[MAX_TEMPLATE_SIZE]; + int size = 0; + int error = NEC_LFML_ExtractLatent(src.m().data, src.m().rows, src.m().cols, 500, data, &size); + if (!error) { + cv::Mat n(1, size, CV_8UC1); + memcpy(n.data, data, size); + dst.m() = n; + } else { + qWarning("NECLatent1EnrollTransform error %d for file %s.", error, qPrintable(src.file.flat())); + dst.m() = cv::Mat(); + dst.file.set("FTE", true); + } + + delete[] data; + } +}; + +BR_REGISTER(Transform, NECLatent1EnrollTransform) + +/*! + * \ingroup distances + * \brief Compare two NEC latent fingerprints + * \author Josh Klontz \cite jklontz + */ +class NECLatent1CompareDistance : public Distance +{ + Q_OBJECT + + float compare(const Template &a, const Template &b) const + { + if (!a.m().data || !b.m().data) return -std::numeric_limits::max(); + int score; + NEC_LFML_Verify(b.m().data, b.m().total(), a.m().data, a.m().total(), &score); + return score; + } +}; + +BR_REGISTER(Distance, NECLatent1CompareDistance) + +} // namespace br + +#include "neclatent1.moc" diff --git a/share/openbr/cmake/FindNECLatent1.cmake b/share/openbr/cmake/FindNECLatent1.cmake new file mode 100644 index 0000000..9942104 --- /dev/null +++ b/share/openbr/cmake/FindNECLatent1.cmake @@ -0,0 +1,14 @@ +find_path(NECLATENT1_DIR include/LatentEFS.h ${CMAKE_SOURCE_DIR}/3rdparty/*) + +set(NECLATENT1_SUBDIR /win/${BITNESS}) +set(NECLATENT1_LIB_DIR ${NECLATENT1_DIR}/lib${NECLATENT1_SUBDIR}) +set(NECLATENT1_BIN_DIR ${NECLATENT1_DIR}/bin${NECLATENT1_SUBDIR}) + +include_directories(${NECLATENT1_DIR}/include) +link_directories(${NECLATENT1_LIB_DIR}) + +if(MSVC) + file(GLOB NECLATENT1_LIBS ${NECLATENT1_LIB_DIR}/*.lib) +else() + file(GLOB NECLATENT1_LIBS ${NECLATENT1_BIN_DIR}/*.dll) +endif() diff --git a/share/openbr/cmake/InstallDependencies.cmake b/share/openbr/cmake/InstallDependencies.cmake index 56edc23..ec03aa3 100644 --- a/share/openbr/cmake/InstallDependencies.cmake +++ b/share/openbr/cmake/InstallDependencies.cmake @@ -75,11 +75,7 @@ function(install_compiler_libraries) if(${BR_INSTALL_DEPENDENCIES} AND MINGW) set(MINGW_DIR "MINGW_DIR-NOTFOUND" CACHE PATH "MinGW Path") get_filename_component(MINGW_DIR ${CMAKE_CXX_COMPILER} PATH) - if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8") - install(FILES ${MINGW_DIR}/libgcc_s_sjlj-1.dll ${MINGW_DIR}/libstdc++-6.dll DESTINATION bin) - else() - install(FILES ${MINGW_DIR}/libgcc_s_dw2-1.dll ${MINGW_DIR}/libstdc++-6.dll DESTINATION bin) - endif() + install(FILES ${MINGW_DIR}/libgcc_s_sjlj-1.dll ${MINGW_DIR}/libstdc++-6.dll DESTINATION bin) endif() endfunction() -- libgit2 0.21.4