Commit d6b19edd737dc359f255ae7eb97a081d81e9d930

Authored by Charles Otto
2 parents 17b6c8f0 61a0c741

Merge branch 'master' of https://github.com/biometrics/openbr into specificity

CMakeLists.txt
... ... @@ -17,6 +17,10 @@ set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
17 17 set(CMAKE_MODULE_PATH "${BR_SHARE_DIR}/cmake" ${CMAKE_MODULE_PATH})
18 18 set(PACKAGE_YEAR 2013)
19 19  
  20 +if("${CMAKE_VERSION}" VERSION_GREATER 2.8.10)
  21 + cmake_policy(SET CMP0020 OLD)
  22 +endif()
  23 +
20 24 if(${CMAKE_SIZEOF_VOID_P} MATCHES 8)
21 25 set(BITNESS 64)
22 26 else()
... ... @@ -89,7 +93,7 @@ else()
89 93 set(CMAKE_EXE_LINKER_FLAGS "-Wl,--enable-auto-import") # Fixes a linker warning
90 94 set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--enable-auto-import")
91 95 elseif(MSVC)
92   - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3 /DNOMINMAX /D_CRT_SECURE_NO_WARNINGS /wd4018 /wd4244 /wd4267 /wd4305 /wd4308 /wd4307 /wd4554 /wd4996 /nologo")
  96 + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3 /DNOMINMAX /D_CRT_SECURE_NO_WARNINGS /wd4018 /wd4244 /wd4267 /wd4305 /wd4308 /wd4307 /wd4554 /wd4996 /nologo /MP")
93 97 endif()
94 98 endif()
95 99  
... ... @@ -125,27 +129,7 @@ install(DIRECTORY share DESTINATION .)
125 129 install(DIRECTORY ${BR_THIRDPARTY_SHARE} DESTINATION share)
126 130  
127 131 # Package
128   -set(CPACK_BINARY_BUNDLE OFF)
129   -set(CPACK_BINARY_DEB OFF)
130   -set(CPACK_BINARY_DRAGNDROP OFF)
131   -set(CPACK_BINARY_NSIS OFF)
132   -set(CPACK_BINARY_OSXX11 OFF)
133   -set(CPACK_BINARY_PACKAGEMAKER OFF)
134   -set(CPACK_BINARY_RPM OFF)
135   -set(CPACK_BINARY_STGZ OFF)
136   -set(CPACK_BINARY_TBZ2 OFF)
137   -set(CPACK_BINARY_TGZ OFF)
138   -set(CPACK_BINARY_TZ OFF)
139   -set(CPACK_BINARY_ZIP OFF)
140   -set(CPACK_SOURCE_TGZ OFF)
141   -set(CPACK_SOURCE_TZ OFF)
142   -set(CPACK_SOURCE_ZIP OFF)
143   -
144 132 if(CMAKE_HOST_WIN32)
145   - set(CPACK_BINARY_ZIP ON)
146   - set(CPACK_BINARY_NSIS ON)
147   -
148   - # NSIS
149 133 set(CPACK_NSIS_MODIFY_PATH ON)
150 134 set(CPACK_NSIS_MUI_ICON ${NATIVE_ICON})
151 135 set(CPACK_NSIS_MUI_UNIICON ${NATIVE_ICON})
... ... @@ -154,22 +138,14 @@ if(CMAKE_HOST_WIN32)
154 138 set(CPACK_NSIS_INSTALL_ROOT "$PROGRAMFILES64")
155 139 endif()
156 140 elseif(CMAKE_HOST_APPLE)
157   - set(CPACK_BINARY_TBZ2 ON)
158   - set(CPACK_BINARY_BUNDLE ON)
159   -
160 141 configure_file("${CMAKE_CURRENT_SOURCE_DIR}/README.md" "README.txt" COPYONLY)
161 142 set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_BINARY_DIR}/README.txt")
162   -
163 143 set(CPACK_BUNDLE_NAME ${CPACK_PACKAGE_NAME})
164 144 set(CPACK_BUNDLE_ICON ${NATIVE_ICON})
165 145 set(CPACK_BUNDLE_PLIST ${CMAKE_CURRENT_BINARY_DIR}/Info.plist)
166 146 set(CPACK_BUNDLE_STARTUP_COMMAND ${BR_SHARE_DIR}/bundle.sh)
167 147 configure_file(${BR_SHARE_DIR}/Info.plist.in Info.plist)
168 148 else()
169   - set(CPACK_BINARY_TBZ2 ON)
170   - set(CPACK_BINARY_DEB ON)
171   -
172   - # DEB
173 149 set(CPACK_DEBIAN_PACKAGE_MAINTAINER "josh.klontz@gmail.com")
174 150 endif()
175 151  
... ...
openbr/plugins/landmarks.cpp 0 → 100644
  1 +#include <opencv2/opencv.hpp>
  2 +#include "openbr_internal.h"
  3 +#include "openbr/core/qtutils.h"
  4 +#include "openbr/core/opencvutils.h"
  5 +#include "openbr/core/eigenutils.h"
  6 +#include <QString>
  7 +#include <Eigen/SVD>
  8 +
  9 +using namespace std;
  10 +using namespace cv;
  11 +
  12 +namespace br
  13 +{
  14 +
  15 +/*!
  16 + * \ingroup transforms
  17 + * \brief Procrustes alignment of points
  18 + * \author Scott Klum \cite sklum
  19 + */
  20 +class ProcrustesTransform : public Transform
  21 +{
  22 + Q_OBJECT
  23 +
  24 + Eigen::MatrixXf meanShape;
  25 +
  26 + void train(const TemplateList &data)
  27 + {
  28 + QList< QList<QPointF> > normalizedPoints;
  29 +
  30 + // Normalize all sets of points
  31 + foreach (br::Template datum, data) {
  32 + QList<QPointF> points = datum.file.points();
  33 +
  34 + if (points.empty()) continue;
  35 +
  36 + cv::Scalar mean = cv::mean(OpenCVUtils::toPoints(points).toVector().toStdVector());
  37 + for (int i = 0; i < points.size(); i++) points[i] -= QPointF(mean[0],mean[1]);
  38 +
  39 + float norm = cv::norm(OpenCVUtils::toPoints(points).toVector().toStdVector());
  40 + for (int i = 0; i < points.size(); i++) points[i] /= norm;
  41 +
  42 + normalizedPoints.append(points);
  43 + }
  44 +
  45 + // Determine mean shape
  46 + Eigen::MatrixXf shapeBuffer(normalizedPoints[0].size(), 2);
  47 +
  48 + for (int i = 0; i < normalizedPoints[0].size(); i++) {
  49 +
  50 + double x = 0;
  51 + double y = 0;
  52 +
  53 + for (int j = 0; j < normalizedPoints.size(); j++) {
  54 + x += normalizedPoints[j][i].x();
  55 + y += normalizedPoints[j][i].y();
  56 + }
  57 +
  58 + x /= (double)normalizedPoints.size();
  59 + y /= (double)normalizedPoints.size();
  60 +
  61 + shapeBuffer(i,0) = x;
  62 + shapeBuffer(i,1) = y;
  63 + }
  64 +
  65 + meanShape = shapeBuffer;
  66 + }
  67 +
  68 + void project(const Template &src, Template &dst) const
  69 + {
  70 + QList<QPointF> points = src.file.points();
  71 +
  72 + cv::Scalar mean = cv::mean(OpenCVUtils::toPoints(points).toVector().toStdVector());
  73 + for (int i = 0; i < points.size(); i++) points[i] -= QPointF(mean[0],mean[1]);
  74 +
  75 + float norm = cv::norm(OpenCVUtils::toPoints(points).toVector().toStdVector());
  76 + Eigen::MatrixXf srcPoints(points.size(), 2);
  77 +
  78 + for (int i = 0; i < points.size(); i++) {
  79 + srcPoints(i,0) = points[i].x()/(norm/150.)+50;
  80 + srcPoints(i,1) = points[i].y()/(norm/150.)+50;
  81 + }
  82 +
  83 + Eigen::JacobiSVD<Eigen::MatrixXf> svd(srcPoints.transpose()*meanShape, Eigen::ComputeThinU | Eigen::ComputeThinV);
  84 +
  85 + Eigen::MatrixXf R = svd.matrixU()*svd.matrixV().transpose();
  86 +
  87 + Eigen::MatrixXf dstPoints = srcPoints*R;
  88 +
  89 + points.clear();
  90 +
  91 + for (int i = 0; i < dstPoints.rows(); i++) points.append(QPointF(dstPoints(i,0),dstPoints(i,1)));
  92 +
  93 + dst.file.appendPoints(points);
  94 + }
  95 +
  96 + void store(QDataStream &stream) const
  97 + {
  98 + stream << meanShape;
  99 + }
  100 +
  101 + void load(QDataStream &stream)
  102 + {
  103 + stream >> meanShape;
  104 + }
  105 +
  106 +};
  107 +
  108 +BR_REGISTER(Transform, ProcrustesTransform)
  109 +
  110 +/*!
  111 + * \ingroup transforms
  112 + * \brief Wraps STASM key point detector
  113 + * \author Scott Klum \cite sklum
  114 + */
  115 +class DelauneyTransform : public UntrainableTransform
  116 +{
  117 + Q_OBJECT
  118 +
  119 + Q_PROPERTY(bool draw READ get_draw WRITE set_draw RESET reset_draw STORED false)
  120 + BR_PROPERTY(bool, draw, false)
  121 +
  122 + void project(const Template &src, Template &dst) const
  123 + {
  124 + dst = src;
  125 +
  126 + Subdiv2D subdiv(Rect(0,0,src.m().cols,src.m().rows));
  127 +
  128 + foreach(const cv::Point2f& point, OpenCVUtils::toPoints(src.file.points())) subdiv.insert(point);
  129 +
  130 + vector<Vec6f> triangleList;
  131 + subdiv.getTriangleList(triangleList);
  132 + vector<Point> pt(3);
  133 +
  134 + Scalar delaunay_color(0, 0, 0);
  135 +
  136 + if (draw) {
  137 + int count = 0;
  138 + for(size_t i = 0; i < triangleList.size(); ++i) {
  139 + Vec6f t = triangleList[i];
  140 +
  141 + pt[0] = Point(cvRound(t[0]), cvRound(t[1]));
  142 + pt[1] = Point(cvRound(t[2]), cvRound(t[3]));
  143 + pt[2] = Point(cvRound(t[4]), cvRound(t[5]));
  144 +
  145 + bool inside = true;
  146 + for (int i = 0; i < 3; i++) {
  147 + if(pt[i].x > dst.m().cols || pt[i].y > dst.m().rows || pt[i].x <= 0 || pt[i].y <= 0) {
  148 + inside = false;
  149 + }
  150 +
  151 + }
  152 + if (inside) {
  153 + count++;
  154 + //qDebug() << count << pt[0] << pt[1] << pt[2] << "Area" << contourArea(pt);
  155 + line(dst.m(), pt[0], pt[1], delaunay_color, 1);
  156 + line(dst.m(), pt[1], pt[2], delaunay_color, 1);
  157 + line(dst.m(), pt[2], pt[0], delaunay_color, 1);
  158 + }
  159 + }
  160 + }
  161 + }
  162 +
  163 +};
  164 +
  165 +BR_REGISTER(Transform, DelauneyTransform)
  166 +
  167 +} // namespace br
  168 +
  169 +#include "landmarks.moc"
... ...
openbr/plugins/regions.cpp
... ... @@ -201,9 +201,11 @@ class RectFromPointsTransform : public UntrainableTransform
201 201 Q_PROPERTY(QList<int> indices READ get_indices WRITE set_indices RESET reset_indices STORED false)
202 202 Q_PROPERTY(double padding READ get_padding WRITE set_padding RESET reset_padding STORED false)
203 203 Q_PROPERTY(double aspectRatio READ get_aspectRatio WRITE set_aspectRatio RESET reset_aspectRatio STORED false)
  204 + Q_PROPERTY(bool crop READ get_crop WRITE set_crop RESET reset_crop STORED false)
204 205 BR_PROPERTY(QList<int>, indices, QList<int>())
205 206 BR_PROPERTY(double, padding, 0)
206 207 BR_PROPERTY(double, aspectRatio, 1.0)
  208 + BR_PROPERTY(bool, crop, true)
207 209  
208 210 void project(const Template &src, Template &dst) const
209 211 {
... ... @@ -218,13 +220,15 @@ class RectFromPointsTransform : public UntrainableTransform
218 220 int maxX, maxY;
219 221 maxX = maxY = -std::numeric_limits<int>::max();
220 222  
  223 + QList<QPointF> points;
  224 +
221 225 foreach(int index, indices) {
222 226 if (src.file.points().size() > index) {
223 227 if (src.file.points()[index].x() < minX) minX = src.file.points()[index].x();
224 228 if (src.file.points()[index].x() > maxX) maxX = src.file.points()[index].x();
225 229 if (src.file.points()[index].y() < minY) minY = src.file.points()[index].y();
226 230 if (src.file.points()[index].y() > maxY) maxY = src.file.points()[index].y();
227   - dst.file.appendPoint(src.file.points()[index]);
  231 + points.append(src.file.points()[index]);
228 232 }
229 233 }
230 234  
... ... @@ -236,7 +240,10 @@ class RectFromPointsTransform : public UntrainableTransform
236 240 double deltaHeight = width/aspectRatio - height;
237 241 height += deltaHeight;
238 242  
239   - dst.m() = src.m()(Rect(std::max(0.0, minX - deltaWidth/2.0), std::max(0.0, minY - deltaHeight/2.0), std::min((double)src.m().cols, width), std::min((double)src.m().rows, height)));
  243 + dst.file.setPoints(points);
  244 +
  245 + if (crop) dst.m() = src.m()(Rect(std::max(0.0, minX - deltaWidth/2.0), std::max(0.0, minY - deltaHeight/2.0), std::min((double)src.m().cols, width), std::min((double)src.m().rows, height)));
  246 + else dst.m() = src.m();
240 247 }
241 248 };
242 249  
... ...
openbr/plugins/stasm4.cpp
1 1 #include <stasm_lib.h>
2 2 #include <stasmcascadeclassifier.h>
3   -#include <opencv2/objdetect/objdetect.hpp>
  3 +#include <opencv2/opencv.hpp>
4 4 #include "openbr_internal.h"
  5 +#include "openbr/core/qtutils.h"
  6 +#include "openbr/core/opencvutils.h"
  7 +#include <QString>
  8 +#include <Eigen/SVD>
5 9  
  10 +using namespace std;
6 11 using namespace cv;
7 12  
8 13 namespace br
... ...
share/openbr/cmake/InstallDependencies.cmake
... ... @@ -72,11 +72,11 @@ function(install_qt_misc)
72 72 endif()
73 73 install(FILES ${_qt5Core_install_prefix}/bin/libGLESv2${BR_INSTALL_DEPENDENCIES_SUFFIX}.dll DESTINATION bin)
74 74 install(FILES ${_qt5Core_install_prefix}/bin/libEGL${BR_INSTALL_DEPENDENCIES_SUFFIX}.dll DESTINATION bin)
75   - install(FILES ${_qt5Core_install_prefix}/bin/icuin49${BR_INSTALL_DEPENDENCIES_SUFFIX}.dll DESTINATION bin)
76   - install(FILES ${_qt5Core_install_prefix}/bin/icuuc49${BR_INSTALL_DEPENDENCIES_SUFFIX}.dll DESTINATION bin)
77   - install(FILES ${_qt5Core_install_prefix}/bin/icudt49.dll DESTINATION bin)
78   - install(FILES ${_qt5Core_install_prefix}/bin/d3dcompiler_46.dll DESTINATION bin)
79   - install(FILES ${_qt5Core_install_prefix}/plugins/platforms/qwindows${BR_INSTALL_DEPENDENCIES_SUFFIX}.dll DESTINATION bin/platforms)
  75 + file(GLOB icudlls ${_qt5Core_install_prefix}/bin/icu*.dll)
  76 + install(FILES ${icudlls} DESTINATION bin)
  77 + file(GLOB d3dcomp ${_qt5Core_install_prefix}/bin/d3dcompiler_*.dll)
  78 + install(FILES ${d3dcomp} DESTINATION bin)
  79 + install(FILES ${_qt5Core_install_prefix}/plugins/platforms/qwindows${BR_INSTALL_DEPENDENCIES_SUFFIX}.dll DESTINATION bin/platforms)
80 80 endif()
81 81 endfunction()
82 82  
... ...