2016-08-17 00:43:42 hy17003 阅读数 2039
  • Python实战系列之Tornado开发人脸识别微信小程序

    项目将应用tornado、pymongo、ip2region、dlib、pillow、opencv等技术打造一个完整的人脸识别微信小程序。我将在实战过程中带大家快速掌握python mtv的设计模式、API接口设计、人脸特征|框选|截取|勾勒|化妆功能封装、微信授权登录、小程序组件开发、IP地址解析、UA访问跟踪、后台管理系统开发以及基于线程池的异步io非阻塞等技术。

    603 人正在学习 去看看 张金龙

原方地址:http://blog.csdn.net/brightming/article/details/50595977

1、文件目录 
/src/face_landmark_detection_test1_ex.cpp 
—-/jni/ 
———-Application.mk 
———-Android.mk

2、文件内容 
2.1 Application.mk

<code class="language-shell hljs avrasm has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">[zzz@localhost jni]$ cat Application<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.mk</span> 
<span class="hljs-label" style="box-sizing: border-box;">APP_STL:</span>=gnustl_static
<span class="hljs-label" style="box-sizing: border-box;">APP_CPPFLAGS:</span>=-frtti -fexceptions
<span class="hljs-label" style="box-sizing: border-box;">APP_ABI:</span>=armeabi-v7a
<span class="hljs-label" style="box-sizing: border-box;">APP_PLATFORM:</span>=android-<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">8</span>
<span class="hljs-label" style="box-sizing: border-box;">APP_BUILD_SCRIPT:</span>=Android<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.mk</span>
APP_CFLAGS+=-DDLIB_NO_GUI_SUPPORT=<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>
[zzz@localhost jni]$ 
</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li></ul>

上面的APP_CFLAGS+=-DDLIB_NO_GUI_SUPPORT=1是因为不需要使用gui相关的功能。

编译dlib的时候,还改了两个文件引用头文件的地方:

<code class="language-c++ hljs avrasm has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><png<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.h</span>>改为<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"../external/libpng/png.h"</span>
<jpeglib<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.h</span>>改为<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"../external/libjpeg/jpeglib.h"</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li></ul>

2.2 Android.mk

<code class="language-shell hljs avrasm has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">[zzz@localhost jni]$ cat Android<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.mk</span>


<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">#include $(CLEAR_VARS)</span>

<span class="hljs-label" style="box-sizing: border-box;">LOCAL_PATH:</span>=$(<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">call</span> my-dir)
<span class="hljs-label" style="box-sizing: border-box;">LOCAL_MODULE:</span>=face_landmark_detection_test1_ex
<span class="hljs-label" style="box-sizing: border-box;">LOCAL_PATH:</span>=$(<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">call</span> my-dir)
<span class="hljs-label" style="box-sizing: border-box;">LOCAL_MODULE_FILENAME:</span>=face_landmark_detection_test1_ex
<span class="hljs-label" style="box-sizing: border-box;">LOCAL_SRC_FILES:</span>=../../face_landmark_detection_test1_ex<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.cpp</span>  /home/zzz/software/dlib-<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">18.18</span>/dlib/all/source<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.cpp</span>
<span class="hljs-label" style="box-sizing: border-box;">LOCAL_C_INCLUDES:</span>=/home/zzz/software/dlib-<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">18.18</span>/
<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">#LOCAL_EXPORT_C_INCLUDES:=/home/zzz/software/dlib-18.18/</span>
include $(BUILD_EXECUTABLE)</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li></ul>

在LOCAL_SRC_FILES中,直接把dlib的源文件作为源文件之一,向之前在dlib移植到arm上说的一样,简单的不能再简单。 
注意头文件路径。

这里有个问题:如果我在上面打开了: 
include $(CLEAR_VARS) 
会报以下的错误:

<code class="language-shell hljs asciidoc has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">[zzz@localhost jni]$ ndk-build NDK<span class="hljs-emphasis" style="box-sizing: border-box;">_APPLICATION_</span>MK=Application.mk
make: *** No rule to make target <span class="hljs-smartquote" style="box-sizing: border-box;">`/home/zzz/software/android-ndk-r9d/build/core/../../face_landmark_detection_test1_ex.cpp'</span>, needed by <span class="hljs-smartquote" style="box-sizing: border-box;">`/home/zzz/software/dlib-18.18/examples/build_android/obj/local/armeabi-v7a/objs/face_landmark_detection_test1_ex/__/__/face_landmark_detection_test1_ex.o'</span>.  Stop.
[zzz@localhost jni]$ 
</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li></ul>

2.3 执行

<code class="language-shell hljs ruby has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">zzz<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">@localhost</span> jni]<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$ </span>ndk-build <span class="hljs-constant" style="box-sizing: border-box;">NDK_APPLICATION_MK</span>=<span class="hljs-constant" style="box-sizing: border-box;">Application</span>.mk
[armeabi-v7a] <span class="hljs-constant" style="box-sizing: border-box;">Compile</span>++ <span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">thumb:</span> face_landmark_detection_test1_ex <= face_landmark_detection_test1_ex.cpp
[armeabi-v7a] <span class="hljs-constant" style="box-sizing: border-box;">Compile</span>++ <span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">thumb:</span> face_landmark_detection_test1_ex <= source.cpp
[armeabi-v7a] <span class="hljs-constant" style="box-sizing: border-box;">Executable</span>     <span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">:</span> face_landmark_detection_test1_ex
[armeabi-v7a] <span class="hljs-constant" style="box-sizing: border-box;">Install</span>        <span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">:</span> face_landmark_detection_test1_ex => libs/armeabi-v7a/face_landmark_detection_test1_ex
[zzz<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">@localhost</span> jni]<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$ </span>ndk-build
</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li></ul>

因为我这个是有jin目录的,所以,不需要再额外指定NDK_APPLICATION_MK也可以。

问题记录: 
1、 
jni/: error: iostream: No such file or directory 
或者其他头文件找不到。 
解决办法: 
在Application.mk中加入: 
APP_STL:=gnustl_static 或 gnustl_shared , c++_static , c++_shared 
但是用system,stlport_static stlport_shared会有头文件找不到。 
参考: 
http://stackoverflow.com/questions/9130429/android-ndk-build-iostream-no-such-file-or-directory

APP_STL的取值可以为: 
system stlport_static stlport_shared gnustl_static gnustl_shared gabi++_static gabi++_shared c++_static c++_shared none

2、 
/build-binary.mk:393: * target pattern contains no `%’

3、 
如果我把Android.mk修改为如下(先编译出dlib的静态库,再与测试程序链接),就会报如下错误:

<code class="language-shell hljs asciidoc has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">[zzz@localhost jni]$ ndk-build
[armeabi-v7a] Compile++ thumb: dlib <= source.cpp
[armeabi-v7a] StaticLibrary  : dlib.a
make: *** No rule to make target <span class="hljs-smartquote" style="box-sizing: border-box;">`/home/zzz/software/android-ndk-r9d/build/core/../../face_landmark_detection_test1_ex.cpp'</span>, needed by <span class="hljs-smartquote" style="box-sizing: border-box;">`/home/zzz/software/dlib-18.18/examples/build_android/obj/local/armeabi-v7a/objs/face_landmark_detection_test1_ex/__/__/face_landmark_detection_test1_ex.o'</span>.  Stop.</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li></ul>

Android.mk的内容为:

<code class="language-shell hljs avrasm has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">[zzz@localhost jni]$ cat Android<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.mk</span>


<span class="hljs-label" style="box-sizing: border-box;">LOCAL_PATH:</span>=$(<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">call</span> my-dir)
<span class="hljs-label" style="box-sizing: border-box;">LOCAL_MODULE:</span>=dlib
<span class="hljs-label" style="box-sizing: border-box;">LOCAL_MODULE_FILENAME:</span>=dlib
<span class="hljs-label" style="box-sizing: border-box;">LOCAL_SRC_FILES:</span>=/home/zzz/software/dlib-<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">18.18</span>/dlib/all/source<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.cpp</span>
<span class="hljs-label" style="box-sizing: border-box;">LOCAL_C_INCLUDES:</span>=/home/zzz/software/dlib-<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">18.18</span>/


<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">#LOCAL_EXPORT_C_INCLUDES:=/home/zzz/software/dlib-18.18/</span>
<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">#include $(BUILD_EXECUTABLE)</span>
include $(BUILD_STATIC_LIBRARY)

<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">####################################################</span>
<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">#include $(CLEAR_VARS)</span>
<span class="hljs-label" style="box-sizing: border-box;">LOCAL_PATH:</span>=$(<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">call</span> my-dir)
<span class="hljs-label" style="box-sizing: border-box;">LOCAL_MODULE:</span>=face_landmark_detection_test1_ex
<span class="hljs-label" style="box-sizing: border-box;">LOCAL_MODULE_FILENAME:</span>=face_landmark_detection_test1_ex
<span class="hljs-label" style="box-sizing: border-box;">LOCAL_SRC_FILES:</span>=../../face_landmark_detection_test1_ex<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.cpp</span> <span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;"># /home/zzz/software/dlib-18.18/dlib/all/source.cpp</span>
<span class="hljs-label" style="box-sizing: border-box;">LOCAL_C_INCLUDES:</span>=/home/zzz/software/dlib-<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">18.18</span>/


<span class="hljs-label" style="box-sizing: border-box;">LOCAL_SHARED_LIBRARIES:</span>=dlib

<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">#LOCAL_EXPORT_C_INCLUDES:=/home/gumh/software/dlib-18.18/</span>
<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">#include $(BUILD_EXECUTABLE)</span>
include $(BUILD_STATIC_LIBRARY)</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li><li style="box-sizing: border-box; padding: 0px 5px;">16</li><li style="box-sizing: border-box; padding: 0px 5px;">17</li><li style="box-sizing: border-box; padding: 0px 5px;">18</li><li style="box-sizing: border-box; padding: 0px 5px;">19</li><li style="box-sizing: border-box; padding: 0px 5px;">20</li><li style="box-sizing: border-box; padding: 0px 5px;">21</li><li style="box-sizing: border-box; padding: 0px 5px;">22</li><li style="box-sizing: border-box; padding: 0px 5px;">23</li><li style="box-sizing: border-box; padding: 0px 5px;">24</li><li style="box-sizing: border-box; padding: 0px 5px;">25</li><li style="box-sizing: border-box; padding: 0px 5px;">26</li><li style="box-sizing: border-box; padding: 0px 5px;">27</li><li style="box-sizing: border-box; padding: 0px 5px;">28</li></ul>

原因还不明白。。。

补充(2016-1-30): 
由于上面编译的时候,没有将jpeg,png的库编译进去,因此,在真正运行程序的时候,会报错。重新将相关的代码组织进mk文件进行编译,文件结构没变,各文件的情况如下:

1、Application.mk

<code class="language-shell hljs handlebars has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="xml" style="box-sizing: border-box;"><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box;"><span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">APP_STL:</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">gnustl_static</span>  ##<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">ok</span>
#<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">APP_STL:</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">stlport_static</span> ##<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">not</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">work</span>!
#<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">APP_STL:</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">system</span>  ##<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">not</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">work</span>!
#<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">APP_STL:</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">c++_static</span>  ##<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">ok</span>
#<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">APP_STL:</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">c++_shared</span>  ##<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">ok</span>
#<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">APP_STL:</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">gnustl_shared</span> ##<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">ok</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">APP_CPPFLAGS:</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">-frtti</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">-fexceptions</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">APP_ABI:</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">armeabi-v7a</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">APP_PLATFORM:</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">android-8</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">APP_BUILD_SCRIPT:</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">Android.mk</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">APP_CFLAGS</span>+=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">-DDLIB_NO_GUI_SUPPORT=on</span>
#<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">APP_CFLAGS</span>+=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">-DDLIB_PNG_SUPPORT=off</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">APP_CFLAGS</span>+=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">-DDLIB_JPEG_SUPPORT=on</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">APP_CFLAGS</span>+=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">-DDLIB_JPEG_STATIC=on</span></span></span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li></ul>

2、Android.mk

<code class="language-shell hljs ruby has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">
all_cpp_files_recursively = \
 <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span>eval src_files = <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span>wildcard <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$1</span>/*.cpp)) \
 <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span>eval src_files = <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span><span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">src_files:</span><span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span><span class="hljs-constant" style="box-sizing: border-box;">LOCAL_PATH</span>)/%=%))<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span>src_files) \
 <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span>eval item_all = <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span>wildcard <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$1</span>/*)) \
 <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span>foreach item, <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span>item_all) <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span>),\
  <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span>eval item <span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">:</span>= <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span><span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">item:</span>%.cpp=%)) \
  <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span>call all_cpp_files_recursively, <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span>item))\
 )


<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#3 自定义了一个all_c_files_recursively 函数,递归遍历返回给定目录下所有C源文件。</span>
all_c_files_recursively = \
 <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span>eval src_files = <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span>wildcard <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$1</span>/*.c)) \
 <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span>eval src_files = <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span><span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">src_files:</span><span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span><span class="hljs-constant" style="box-sizing: border-box;">LOCAL_PATH</span>)/%=%))<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span>src_files) \
 <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span>eval item_all = <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span>wildcard <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$1</span>/*)) \
 <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span>foreach item, <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span>item_all) <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span>),\
  <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span>eval item <span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">:</span>= <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span><span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">item:</span>%.c=%)) \
  <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span>call all_c_files_recursively, <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span>item))\
 )


<span class="hljs-constant" style="box-sizing: border-box;">LOCAL_PATH</span><span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">:</span>=<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span>call my-dir)
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">include</span> <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span><span class="hljs-constant" style="box-sizing: border-box;">CLEAR_VARS</span>)
<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#####################程序################</span>
<span class="hljs-constant" style="box-sizing: border-box;">LOCAL_SRC_FILES</span> <span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">:</span>= <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span>call all_cpp_files_recursively,<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span><span class="hljs-constant" style="box-sizing: border-box;">LOCAL_PATH</span>)/../../../dlib/external/libjpeg/) <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#将jpeg相关代码加入</span>
<span class="hljs-constant" style="box-sizing: border-box;">LOCAL_SRC_FILES</span> += <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span><span class="hljs-constant" style="box-sizing: border-box;">LOCAL_PATH</span>)/../../../dlib/all/source.cpp
<span class="hljs-constant" style="box-sizing: border-box;">LOCAL_C_INCLUDES</span><span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">:</span>=<span class="hljs-regexp" style="color: rgb(0, 136, 0); box-sizing: border-box;">/home/gumh</span><span class="hljs-regexp" style="color: rgb(0, 136, 0); box-sizing: border-box;">/software/dlib</span>-<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">18.18</span>/ <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span><span class="hljs-constant" style="box-sizing: border-box;">LOCAL_PATH</span>)/../../../dlib/entropy_decoder/
<span class="hljs-constant" style="box-sizing: border-box;">LOCAL_CPP_INCLUDES</span><span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">:</span>=<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">${</span><span class="hljs-constant" style="box-sizing: border-box;">LOCAL_C_INCLUDES</span>}
<span class="hljs-constant" style="box-sizing: border-box;">LOCAL_CXX_INCLUDES</span><span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">:</span>=<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">${</span><span class="hljs-constant" style="box-sizing: border-box;">LOCAL_C_INCLUDES</span>}

<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span>warning <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"-------------the value of LOCAL_SRC_FILES is $(LOCAL_SRC_FILES)--------------------"</span>)

<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">##neon start</span>
<span class="hljs-constant" style="box-sizing: border-box;">TARGET_ARCH_ABI</span> <span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">:</span>=armeabi-v7a
<span class="hljs-constant" style="box-sizing: border-box;">LOCAL_ARM_MODE</span> <span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">:</span>= arm 
<span class="hljs-constant" style="box-sizing: border-box;">LOCAL_ARM_NEON</span> <span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">:</span>= <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">true</span>

ifeq (<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span><span class="hljs-constant" style="box-sizing: border-box;">TARGET_ARCH_ABI</span>),armeabi-v7a)
    <span class="hljs-constant" style="box-sizing: border-box;">LOCAL_CFLAGS</span> <span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">:</span>= -<span class="hljs-constant" style="box-sizing: border-box;">DHAVE_NEON</span>=<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>
    <span class="hljs-constant" style="box-sizing: border-box;">LOCAL_CXXFLAGS</span> <span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">:</span>= -<span class="hljs-constant" style="box-sizing: border-box;">DHAVE_NEON</span>=<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>
endif
<span class="hljs-constant" style="box-sizing: border-box;">LOCAL_CFLAGS</span> += -mfloat-abi=softfp -mfpu=vfpv4
<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">###neon end</span>


<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">##放在一起编译</span>
<span class="hljs-constant" style="box-sizing: border-box;">LOCAL_MODULE</span><span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">:</span>=face_landmark_detection_test1_ex
<span class="hljs-constant" style="box-sizing: border-box;">LOCAL_MODULE_FILENAME</span><span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">:</span>=face_landmark_detection_test1_ex
<span class="hljs-constant" style="box-sizing: border-box;">LOCAL_SRC_FILES</span>+=../../face_landmark_detection_test1_ex.cpp 

<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">include</span> <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span><span class="hljs-constant" style="box-sizing: border-box;">BUILD_EXECUTABLE</span>)
</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li><li style="box-sizing: border-box; padding: 0px 5px;">16</li><li style="box-sizing: border-box; padding: 0px 5px;">17</li><li style="box-sizing: border-box; padding: 0px 5px;">18</li><li style="box-sizing: border-box; padding: 0px 5px;">19</li><li style="box-sizing: border-box; padding: 0px 5px;">20</li><li style="box-sizing: border-box; padding: 0px 5px;">21</li><li style="box-sizing: border-box; padding: 0px 5px;">22</li><li style="box-sizing: border-box; padding: 0px 5px;">23</li><li style="box-sizing: border-box; padding: 0px 5px;">24</li><li style="box-sizing: border-box; padding: 0px 5px;">25</li><li style="box-sizing: border-box; padding: 0px 5px;">26</li><li style="box-sizing: border-box; padding: 0px 5px;">27</li><li style="box-sizing: border-box; padding: 0px 5px;">28</li><li style="box-sizing: border-box; padding: 0px 5px;">29</li><li style="box-sizing: border-box; padding: 0px 5px;">30</li><li style="box-sizing: border-box; padding: 0px 5px;">31</li><li style="box-sizing: border-box; padding: 0px 5px;">32</li><li style="box-sizing: border-box; padding: 0px 5px;">33</li><li style="box-sizing: border-box; padding: 0px 5px;">34</li><li style="box-sizing: border-box; padding: 0px 5px;">35</li><li style="box-sizing: border-box; padding: 0px 5px;">36</li><li style="box-sizing: border-box; padding: 0px 5px;">37</li><li style="box-sizing: border-box; padding: 0px 5px;">38</li><li style="box-sizing: border-box; padding: 0px 5px;">39</li><li style="box-sizing: border-box; padding: 0px 5px;">40</li><li style="box-sizing: border-box; padding: 0px 5px;">41</li><li style="box-sizing: border-box; padding: 0px 5px;">42</li><li style="box-sizing: border-box; padding: 0px 5px;">43</li><li style="box-sizing: border-box; padding: 0px 5px;">44</li><li style="box-sizing: border-box; padding: 0px 5px;">45</li><li style="box-sizing: border-box; padding: 0px 5px;">46</li><li style="box-sizing: border-box; padding: 0px 5px;">47</li><li style="box-sizing: border-box; padding: 0px 5px;">48</li><li style="box-sizing: border-box; padding: 0px 5px;">49</li><li style="box-sizing: border-box; padding: 0px 5px;">50</li><li style="box-sizing: border-box; padding: 0px 5px;">51</li><li style="box-sizing: border-box; padding: 0px 5px;">52</li><li style="box-sizing: border-box; padding: 0px 5px;">53</li></ul>

从上面的文件可以看到,其实就是配合source.cpp定义的宏,把相关的jpeg的源代码加入一起编译。

是否可以先编译出dlib的静态库,给后面的应用程序编译使用呢? 
新加一个Android-prebuild.mk:

<code class="language-shell hljs http has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">

<span class="ruby" style="box-sizing: border-box;">all_cpp_files_recursively = \
 <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span>eval src_files = <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span>wildcard <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$1</span>/*.cpp)) \
 <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span>eval src_files = <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span><span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">src_files:</span><span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span><span class="hljs-constant" style="box-sizing: border-box;">LOCAL_PATH</span>)/%=%))<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span>src_files) \
 <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span>eval item_all = <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span>wildcard <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$1</span>/*)) \
 <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span>foreach item, <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span>item_all) <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span>),\
  <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span>eval item <span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">:</span>= <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span><span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">item:</span>%.cpp=%)) \
  <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span>call all_cpp_files_recursively, <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span>item))\
 )


<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#3 自定义了一个all_c_files_recursively 函数,递归遍历返回给定目录下所有C源文件。</span>
all_c_files_recursively = \
 <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span>eval src_files = <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span>wildcard <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$1</span>/*.c)) \
 <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span>eval src_files = <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span><span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">src_files:</span><span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span><span class="hljs-constant" style="box-sizing: border-box;">LOCAL_PATH</span>)/%=%))<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span>src_files) \
 <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span>eval item_all = <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span>wildcard <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$1</span>/*)) \
 <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span>foreach item, <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span>item_all) <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span>),\
  <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span>eval item <span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">:</span>= <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span><span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">item:</span>%.c=%)) \
  <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span>call all_c_files_recursively, <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span>item))\
 )




<span class="hljs-constant" style="box-sizing: border-box;">LOCAL_PATH</span><span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">:</span>=<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span>call my-dir)

<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">############1##################</span>
<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#####################libdlib.a################</span>
    <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span>warning <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"--------build dlib ---------"</span>)
    <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">include</span> <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span><span class="hljs-constant" style="box-sizing: border-box;">CLEAR_VARS</span>)
    <span class="hljs-constant" style="box-sizing: border-box;">LOCAL_MODULE</span><span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">:</span>=dlib
    <span class="hljs-constant" style="box-sizing: border-box;">LOCAL_SRC_FILES</span> <span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">:</span>= <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span>call all_cpp_files_recursively,<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span><span class="hljs-constant" style="box-sizing: border-box;">LOCAL_PATH</span>)/../../../dlib/external/libjpeg/)
    <span class="hljs-constant" style="box-sizing: border-box;">LOCAL_SRC_FILES</span> += <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span><span class="hljs-constant" style="box-sizing: border-box;">LOCAL_PATH</span>)/../../../dlib/all/source.cpp
    <span class="hljs-constant" style="box-sizing: border-box;">LOCAL_C_INCLUDES</span><span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">:</span>=<span class="hljs-regexp" style="color: rgb(0, 136, 0); box-sizing: border-box;">/home/gumh</span><span class="hljs-regexp" style="color: rgb(0, 136, 0); box-sizing: border-box;">/software/dlib</span>-<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">18.18</span>/ <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span><span class="hljs-constant" style="box-sizing: border-box;">LOCAL_PATH</span>)/../../../dlib/entropy_decoder/
    <span class="hljs-constant" style="box-sizing: border-box;">LOCAL_CPP_INCLUDES</span><span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">:</span>=<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">${</span><span class="hljs-constant" style="box-sizing: border-box;">LOCAL_C_INCLUDES</span>}
    <span class="hljs-constant" style="box-sizing: border-box;">LOCAL_CXX_INCLUDES</span><span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">:</span>=<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">${</span><span class="hljs-constant" style="box-sizing: border-box;">LOCAL_C_INCLUDES</span>}

    <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span>warning <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"-------------the value of LOCAL_SRC_FILES is $(LOCAL_SRC_FILES)--------------------"</span>)

    <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">##neon start</span>
    <span class="hljs-constant" style="box-sizing: border-box;">TARGET_ARCH_ABI</span> <span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">:</span>=armeabi-v7a
    <span class="hljs-constant" style="box-sizing: border-box;">LOCAL_ARM_MODE</span> <span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">:</span>= arm 
    <span class="hljs-constant" style="box-sizing: border-box;">LOCAL_ARM_NEON</span> <span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">:</span>= <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">true</span>

    ifeq (<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span><span class="hljs-constant" style="box-sizing: border-box;">TARGET_ARCH_ABI</span>),armeabi-v7a)
        <span class="hljs-constant" style="box-sizing: border-box;">LOCAL_CFLAGS</span> <span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">:</span>= -<span class="hljs-constant" style="box-sizing: border-box;">DHAVE_NEON</span>=<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>
        <span class="hljs-constant" style="box-sizing: border-box;">LOCAL_CXXFLAGS</span> <span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">:</span>= -<span class="hljs-constant" style="box-sizing: border-box;">DHAVE_NEON</span>=<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>
    endif

    <span class="hljs-constant" style="box-sizing: border-box;">LOCAL_CFLAGS</span> += -mfloat-abi=softfp -mfpu=vfpv4

    <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">########海思的设置:set(CMAKE_CXX_FLAGS           "-mthumb -mcpu=cortex-a7 -mfloat-abi=softfp -mfpu=neon-vfpv4 -mno-unaligned-access -fno-aggressive-loop-optimizations"     CACHE STRING "c++ flags")</span>

    <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">###neon end</span>

    <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">include</span> <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span><span class="hljs-constant" style="box-sizing: border-box;">BUILD_STATIC_LIBRARY</span>)

<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">########2##################</span>
<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">##########build app##############</span>
<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span>warning <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"--------build app---------"</span>)

<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#use prebuild dlib</span>
<span class="hljs-constant" style="box-sizing: border-box;">LOCAL_MODULE</span><span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">:</span>=mydlib
<span class="hljs-constant" style="box-sizing: border-box;">LOCAL_SRC_FILES</span><span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">:</span>=libdlib.a
<span class="hljs-constant" style="box-sizing: border-box;">LOCAL_EXPORT_C_INCLUDES</span><span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">:</span>=<span class="hljs-regexp" style="color: rgb(0, 136, 0); box-sizing: border-box;">/home/gumh</span><span class="hljs-regexp" style="color: rgb(0, 136, 0); box-sizing: border-box;">/software/dlib</span>-<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">18.18</span>/ <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span><span class="hljs-constant" style="box-sizing: border-box;">LOCAL_PATH</span>)/../../../dlib/entropy_decoder/
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">include</span> <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span><span class="hljs-constant" style="box-sizing: border-box;">PREBUILT_STATIC_LIBRARY</span>)

<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">###app#######</span>
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">include</span> <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span><span class="hljs-constant" style="box-sizing: border-box;">CLEAR_VARS</span>)
<span class="hljs-constant" style="box-sizing: border-box;">LOCAL_MODULE</span><span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">:</span>=face_landmark_detection_test1_ex
<span class="hljs-constant" style="box-sizing: border-box;">LOCAL_SRC_FILES</span><span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">:</span>=../../face_landmark_detection_test1_ex.cpp 
<span class="hljs-constant" style="box-sizing: border-box;">LOCAL_STATIC_LIBRARIES</span><span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">:</span>=mydlib
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">include</span> <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$(</span><span class="hljs-constant" style="box-sizing: border-box;">BUILD_EXECUTABLE</span>)

<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">##############</span>
</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li><li style="box-sizing: border-box; padding: 0px 5px;">16</li><li style="box-sizing: border-box; padding: 0px 5px;">17</li><li style="box-sizing: border-box; padding: 0px 5px;">18</li><li style="box-sizing: border-box; padding: 0px 5px;">19</li><li style="box-sizing: border-box; padding: 0px 5px;">20</li><li style="box-sizing: border-box; padding: 0px 5px;">21</li><li style="box-sizing: border-box; padding: 0px 5px;">22</li><li style="box-sizing: border-box; padding: 0px 5px;">23</li><li style="box-sizing: border-box; padding: 0px 5px;">24</li><li style="box-sizing: border-box; padding: 0px 5px;">25</li><li style="box-sizing: border-box; padding: 0px 5px;">26</li><li style="box-sizing: border-box; padding: 0px 5px;">27</li><li style="box-sizing: border-box; padding: 0px 5px;">28</li><li style="box-sizing: border-box; padding: 0px 5px;">29</li><li style="box-sizing: border-box; padding: 0px 5px;">30</li><li style="box-sizing: border-box; padding: 0px 5px;">31</li><li style="box-sizing: border-box; padding: 0px 5px;">32</li><li style="box-sizing: border-box; padding: 0px 5px;">33</li><li style="box-sizing: border-box; padding: 0px 5px;">34</li><li style="box-sizing: border-box; padding: 0px 5px;">35</li><li style="box-sizing: border-box; padding: 0px 5px;">36</li><li style="box-sizing: border-box; padding: 0px 5px;">37</li><li style="box-sizing: border-box; padding: 0px 5px;">38</li><li style="box-sizing: border-box; padding: 0px 5px;">39</li><li style="box-sizing: border-box; padding: 0px 5px;">40</li><li style="box-sizing: border-box; padding: 0px 5px;">41</li><li style="box-sizing: border-box; padding: 0px 5px;">42</li><li style="box-sizing: border-box; padding: 0px 5px;">43</li><li style="box-sizing: border-box; padding: 0px 5px;">44</li><li style="box-sizing: border-box; padding: 0px 5px;">45</li><li style="box-sizing: border-box; padding: 0px 5px;">46</li><li style="box-sizing: border-box; padding: 0px 5px;">47</li><li style="box-sizing: border-box; padding: 0px 5px;">48</li><li style="box-sizing: border-box; padding: 0px 5px;">49</li><li style="box-sizing: border-box; padding: 0px 5px;">50</li><li style="box-sizing: border-box; padding: 0px 5px;">51</li><li style="box-sizing: border-box; padding: 0px 5px;">52</li><li style="box-sizing: border-box; padding: 0px 5px;">53</li><li style="box-sizing: border-box; padding: 0px 5px;">54</li><li style="box-sizing: border-box; padding: 0px 5px;">55</li><li style="box-sizing: border-box; padding: 0px 5px;">56</li><li style="box-sizing: border-box; padding: 0px 5px;">57</li><li style="box-sizing: border-box; padding: 0px 5px;">58</li><li style="box-sizing: border-box; padding: 0px 5px;">59</li><li style="box-sizing: border-box; padding: 0px 5px;">60</li><li style="box-sizing: border-box; padding: 0px 5px;">61</li><li style="box-sizing: border-box; padding: 0px 5px;">62</li><li style="box-sizing: border-box; padding: 0px 5px;">63</li><li style="box-sizing: border-box; padding: 0px 5px;">64</li><li style="box-sizing: border-box; padding: 0px 5px;">65</li><li style="box-sizing: border-box; padding: 0px 5px;">66</li><li style="box-sizing: border-box; padding: 0px 5px;">67</li><li style="box-sizing: border-box; padding: 0px 5px;">68</li><li style="box-sizing: border-box; padding: 0px 5px;">69</li><li style="box-sizing: border-box; padding: 0px 5px;">70</li><li style="box-sizing: border-box; padding: 0px 5px;">71</li><li style="box-sizing: border-box; padding: 0px 5px;">72</li><li style="box-sizing: border-box; padding: 0px 5px;">73</li><li style="box-sizing: border-box; padding: 0px 5px;">74</li><li style="box-sizing: border-box; padding: 0px 5px;">75</li><li style="box-sizing: border-box; padding: 0px 5px;">76</li><li style="box-sizing: border-box; padding: 0px 5px;">77</li></ul>

在把Application.mk里的APP_BUILD_SCRIPT改为:Android-prebuilt.mk 
APP_BUILD_SCRIPT:=Android-prebuilt.mk

一个简单的make.sh

<code class="language-shell hljs bash has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">[zzz@localhost jni]$ cat make.sh 
<span class="hljs-shebang" style="color: rgb(0, 102, 102); box-sizing: border-box;">#!/bin/sh
</span>
ndk-build NDK_PROJECT_PATH=. NDK_APPLICATION_MK=Application.mk 
</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li></ul>

(如何传递参数,在Android.mk里可以根据参数来编译不同的部分?如 
ifeq ($(my_target),”dlib”)就编译dlib库,否则编译其他程序。 

执行: 
1、先构建libdlib.a 
2、将编译出来的libdlib.a拷贝到Android.mk的同目录下, 
2、再构建app

2017-07-29 08:57:58 qi_w_ip 阅读数 4802
  • Python实战系列之Tornado开发人脸识别微信小程序

    项目将应用tornado、pymongo、ip2region、dlib、pillow、opencv等技术打造一个完整的人脸识别微信小程序。我将在实战过程中带大家快速掌握python mtv的设计模式、API接口设计、人脸特征|框选|截取|勾勒|化妆功能封装、微信授权登录、小程序组件开发、IP地址解析、UA访问跟踪、后台管理系统开发以及基于线程池的异步io非阻塞等技术。

    603 人正在学习 去看看 张金龙

最近因为需要,尝试着将Dlib移植到android上。android小白一枚,做之前没接触过android,所以就用了别人说比较好的android studio 最新稳定版(windows下)。在android studio2.3.3版本中使用cmake+clang来编译C/C++。我直接将之前在Ubuntu17.04的跑通了的代码拿过来,之前用的cmake+gcc,所以CMakeList.txt也是直接复制过来稍加修改。因为用dlib一般少不了要用opencv的库,网上很多教程,我配置的时候一些问题基本都能从网上找到解决办法,就不在这里多说了。

其实弄好opencv之后,再把这个库加到项目里基本就没啥问题了,修改CmakeList.txt如下(这里是最基本的样子):

set(pathToProject D:/AndroidStudioProjects/MyProject)
set(pathToOpenCv D:/AndroidStudioProjects/OpenCV-android-sdk)
set(pathToDlib D:/AndroidStudioProjects/MyProject/app/src/main/dlib)
cmake_minimum_required(VERSION 3.4.1)
include(${pathToDlib}/dlib/cmake)
add_library( lib_opencv SHARED IMPORTED )
include_directories(lib_opencv ${pathToOpenCv}/sdk/native/jni/include )
set_target_properties( lib_opencv PROPERTIES IMPORTED_LOCATION ${pathToProject}/app/src/main/jniLibs/${ANDROID_ABI}/libopencv_java3.so)
add_library( native-lib SHARED src/main/cpp/native-lib.cpp )
find_library( log-lib log )
target_link_libraries( native-lib ${log-lib} lib_opencv dlib::dlib )

内容和dlib给的examples没啥太大差别。android studio 会自动把dlib加进项目中,然后编译就行啦。

问题及解决:

(1)

error :no member named ‘round’ in namespace ‘std’; did you mean simply ‘round’?

一开始看到这个报错在网上翻了好多帖子,都没找到解决办法,无奈只能自己从头文件开始找起。把clang报错的内容拿出来看了,头文件包含路径没有问题,编译的参数没有问题(这个函数是从c++11之后才有的,所以有人会说在build.gradle里的cppFlags加上“-std=c++11”,这个在建项目的时候选C++11就已经加进去了啊,没啥用啊),最后就去看头文件cmath,在cmath中找到了这个函数的声明:

namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION

  // types
  using ::double_t;
  using ::float_t;

  // functions
  ……
  using ::round;
  ……

_GLIBCXX_END_NAMESPACE_VERSION
} // namespace

咋一看也没问题啊,可是上面这一段是包含在下面这两句里面的,-std=c++11已经加了,所以就是那个宏的问题了。然后就去找,在别的头文件中确实有这个宏定义,但是那个头文件的引用顺序应该在cmath之后,所以才会出这个问题。

#if __cplusplus >= 201103L
#ifdef _GLIBCXX_USE_C99_MATH_TR1

知道问题之后解决起来就是各种办法了,一开始我直接在cmath中加了一句

#define _GLIBCXX_USE_C99_MATH_TR1 1

编译,没错。不过后来用这个关键词去检索,查到了stackoverflow上的一个类似的问题,按照里面的方法改了一下,也没问题。不过,

$ndk\sources\cxx-stl\gnu-libstdc++\libs\armeabi\include\bits\c++config.h

这个路径再自己看一下,好多个c++config.h,应该改哪个就根据实际来咯。
(2)

error: no type named ‘exception_ptr’ in namespace ‘std’; did you mean ‘exception’?

这个问题和上面的如出一辙,先去找对应的头文件<exception>,在该文件的最后

#if (__cplusplus >= 201103L) && (ATOMIC_INT_LOCK_FREE > 1)
#include <bits/exception_ptr.h>
#include <bits/nested_exception.h>
#endif

std::exception_ptr就是在<bits/exception_ptr.h>里面定义的,那就往回找ATOMIC_INT_LOCK_FREE 这个宏,在atomic_lockfree_defines.h里面有如下宏定义:

#if __cplusplus >= 201103L
……
#define ATOMIC_INT_LOCK_FREE __GCC_ATOMIC_INT_LOCK_FREE
……
#endif

参考预定义宏,用clang++.exe -E -dM - < nul可以看到这个宏在clang里也是有的并且值为2(那为啥还会报错???黑人问号脸.jpg)。这里暂时先不管了,我直接把#define ATOMIC_INT_LOCK_FREE __GCC_ATOMIC_INT_LOCK_FREE改成了#define ATOMIC_INT_LOCK_FREE 2 ,编译妥妥的,至于这两个宏,自己去查资料吧……

(3)

error: “DLIB_NO_GUI_SUPPORT is defined so you can’t use the GUI code. Turn DLIB_NO_GUI_SUPPORT off if you want to use it.”

这是移植过来又一个问题,因为之前在Ubuntu下面已经捯饬过dlib,所以大概知道问题出现在dlib的cmake文件中,DLIB_NO_GUI_SUPPORT这个宏相关的在dlib/dlib/CMakeLists.txt里面,可以自己看一下,下图是问题所在CMakeLists.txt
在windows下面编译我怎么去给你弄这些包啊?那干脆注释掉好了。

(8月3日修改)在写程序测试的时候也遇到过一些问题,参考了github上的这个,Java的bitmap转换成mat,还有如何在Java里使用C++类等。
打算把dlib的人脸特征点提取使用在android程序上,但是dlib和opencv库的存储开销对一个小程序来说就有点大,如果大家有啥减少存储开销的好办法请留言我。

2016-12-27 19:12:44 Taily_Duan 阅读数 4344
  • Python实战系列之Tornado开发人脸识别微信小程序

    项目将应用tornado、pymongo、ip2region、dlib、pillow、opencv等技术打造一个完整的人脸识别微信小程序。我将在实战过程中带大家快速掌握python mtv的设计模式、API接口设计、人脸特征|框选|截取|勾勒|化妆功能封装、微信授权登录、小程序组件开发、IP地址解析、UA访问跟踪、后台管理系统开发以及基于线程池的异步io非阻塞等技术。

    603 人正在学习 去看看 张金龙

 

Dlib官网地址:http://dlib.net/

Dlib移植到Android:http://blog.csdn.net/brightming/article/details/50595977

Dlib人脸对齐(特征点检测):http://blog.csdn.net/sunshine_in_moon/article/details/50150435

 

1、解压Dlib;

E:\Dlib\dlib-19.1

E:\Dlib\dlib-19.1-debug

2、CMake;

3、VS2013+Dlib;

 

 

 

 

 

 

 

 

 

 

#include "stdafx.h"

#include <iostream>
#include <dlib/image_processing/frontal_face_detector.h>
#include <dlib/gui_widgets.h>
#include <dlib/image_io.h>
#include <iostream>
#include <fstream>

using namespace dlib;
using namespace std;

// ----------------------------------------------------------------------------------------

int main(int argc, char** argv)
{
	try
	{
		frontal_face_detector detector = get_frontal_face_detector();//定义一个frontal_face_detctor类的实例detector,用get_frontal_face_detector函数初始化该实例
		image_window win;//一个显示窗口

		array2d<unsigned char> img;
		load_image(img, "33.jpg");// 加载一张图片,从argv[i](图片路劲)加载到变量img

		pyramid_up(img);//对图像进行上采用,检测更小的人脸

		// Now tell the face detector to give us a list of bounding boxes
		// around all the faces it can find in the image.
		//开始检测,返回一系列的边界框
		std::vector<rectangle> dets = detector(img);//detector()函数检测人脸,返回一系列边界盒子

		cout << "Number of faces detected: " << dets.size() << endl;//dets.size 人脸数量
		// 在原图片上显示结果
		win.clear_overlay();
		win.set_image(img);
		win.add_overlay(dets, rgb_pixel(255, 0, 0));

		cout << "Hit enter to process the next image..." << endl;
		cin.get();
	}
	catch (exception& e)
	{
		cout << "\nexception thrown!" << endl;
		cout << e.what() << endl;
	}
}


 

 

 

 

 

#include "stdafx.h"

#include <iostream>
#include <dlib/image_processing/frontal_face_detector.h>
#include <dlib/image_processing/render_face_detections.h> 
#include <dlib/image_processing.h>
#include <dlib/gui_widgets.h>
#include <dlib/image_io.h>
#include <iostream>
#include <fstream>

using namespace dlib;
using namespace std;

// ----------------------------------------------------------------------------------------

int main(int argc, char** argv)
{
	try
	{
		frontal_face_detector detector = get_frontal_face_detector();//定义一个frontal_face_detctor类的实例detector,用get_frontal_face_detector函数初始化该实例
		image_window win, win_faces;//一个显示窗口

		shape_predictor sp;//定义个shape_predictor类的实例  
		deserialize("shape_predictor_68_face_landmarks.dat") >> sp;

		// Loop over all the images provided on the command line.
		// 循环所有的图片
	
			array2d<unsigned char> img;
			load_image(img, "02.jpg");// 加载一张图片,从argv[i](图片路劲)加载到变量img
			
			pyramid_up(img);//对图像进行上采用,检测更小的人脸

			// Now tell the face detector to give us a list of bounding boxes  
			// around all the faces in the image.  
			std::vector<rectangle> dets = detector(img);//检测人脸,获得边界框  
			cout << "Number of faces detected: " << dets.size() << endl;//检测到人脸的数量  

			// Now we will go ask the shape_predictor to tell us the pose of  
			// each face we detected.  
			//****调用shape_predictor类函数,返回每张人脸的姿势  
			std::vector<full_object_detection> shapes;//注意形状变量的类型,full_object_detection  
			for (unsigned long j = 0; j < dets.size(); ++j)
			{
				full_object_detection shape = sp(img, dets[j]);//预测姿势,注意输入是两个,一个是图片,另一个是从该图片检测到的边界框  
				cout << "number of parts: " << shape.num_parts() << endl;
				//cout << "pixel position of first part:  " << shape.part(0) << endl;//获得第一个点的坐标,注意第一个点是从0开始的  
				//cout << "pixel position of second part: " << shape.part(1) << endl;//获得第二个点的坐标  
				/*自己改写,打印出全部68个点*/
				for (int i = 1; i < 69; i++)
				{
					cout << "第 " << i << " 个点的坐标: " << shape.part(i - 1) << endl;
				}
				// You get the idea, you can get all the face part locations if  
				// you want them.  Here we just store them in shapes so we can  
				// put them on the screen.  
				shapes.push_back(shape);
			}

			// Now let's view our face poses on the screen.  
			//**** 显示结果  
			win.clear_overlay();
			win.set_image(img);
			win.add_overlay(render_face_detections(shapes));

			// We can also extract copies of each face that are cropped, rotated upright,  
			// and scaled to a standard size as shown here:  
			//****我们也能提取每张剪裁后的人脸的副本,旋转和缩放到一个标准尺寸  
			dlib::array<array2d<rgb_pixel> > face_chips;
			extract_image_chips(img, get_face_chip_details(shapes), face_chips);
			win_faces.set_image(tile_images(face_chips));

			cout << "Hit enter to process the next image..." << endl;
			cin.get();
		
	}
	catch (exception& e)
	{
		cout << "\nexception thrown!" << endl;
		cout << e.what() << endl;
	}
}

 

 

 

 

 

#include "stdafx.h"

#include <iostream>
#include <opencv2/opencv.hpp>

#include <dlib/image_processing/frontal_face_detector.h>
#include <dlib/image_processing/render_face_detections.h> 
#include <dlib/image_processing.h>
#include <dlib/gui_widgets.h>
#include <dlib/image_io.h>
#include <iostream>
#include <fstream>

using namespace dlib;
using namespace std;
using namespace cv;

// ----------------------------------------------------------------------------------------

int main(int argc, char** argv)
{
	char img_file[] = "02.jpg";
	char landmark_file[] = "shape_predictor_68_face_landmarks.dat";

	//  
	Mat img = imread(img_file);

	//  
	frontal_face_detector detector = get_frontal_face_detector();

	shape_predictor sp;
	deserialize(landmark_file) >> sp;

	array2d<rgb_pixel> arrImg;
	load_image(arrImg, img_file);

	std::vector<dlib::rectangle> dets = detector(arrImg);
	for (unsigned long j = 0; j < dets.size(); ++j)
	{
		full_object_detection shape = sp(arrImg, dets[j]);
		for (unsigned long i = 0; i<shape.num_parts(); i++)
		{
			point pt = shape.part(i);
			int x = pt.x();
			int y = pt.y();

			line(img, Point(pt.x(), pt.y()), Point(pt.x(), pt.y()), Scalar(0, 0, 255), 2);
		}
	}

	//  
	imshow("img", img);
	waitKey();
	return 0;
}

 


 

Dlib使用OpenCV的Mat格式

 

#include "stdafx.h"

#include <iostream>
#include <opencv2/opencv.hpp>

#include <dlib/image_processing/frontal_face_detector.h>
#include <dlib/image_processing/render_face_detections.h> 
#include <dlib/image_processing.h>
#include <dlib/gui_widgets.h>
#include <dlib/image_io.h>
#include <dlib/opencv.h>
#include <iostream>
#include <fstream>

using namespace dlib;
using namespace std;
using namespace cv;

// ----------------------------------------------------------------------------------------

int main(int argc, char** argv)
{
	try
	{
		char img_file[] = "02.jpg";
		char landmark_file[] = "shape_predictor_68_face_landmarks.dat";

		//  
		//Mat img = imread(img_file);
		namedWindow("img", 1);
		Mat img;

		VideoCapture cap("Duan2.mp4");
		int totalFrameNumber = cap.get(CV_CAP_PROP_FRAME_COUNT);
		cap >> img;
		int w = img.cols;
		int h = img.rows;
		cout << w << ", " << h << endl;

		//  
		frontal_face_detector detector = get_frontal_face_detector();

		shape_predictor sp;
		deserialize(landmark_file) >> sp;

		for (int nFrmNum = 0; nFrmNum < totalFrameNumber; nFrmNum++) {
			// get frame from the video
			cap >> img;
			cout << nFrmNum << " =======================" << endl;
			if (!img.empty())
			{
				cv_image<bgr_pixel> cimg(img);

				// Detect faces 
				std::vector<dlib::rectangle> dets = detector(cimg);

				for (unsigned long j = 0; j < dets.size(); ++j)
				{
					full_object_detection shape = sp(cimg, dets[j]);
					for (unsigned long i = 0; i < shape.num_parts(); i++)
					{
						point pt = shape.part(i);
						int x = pt.x();
						int y = pt.y();

						line(img, Point(pt.x(), pt.y()), Point(pt.x(), pt.y()), Scalar(0, 0, 255), 2);
						char ptr[20];
						sprintf(ptr, "%d", i);
						putText(img, ptr, Point(pt.x(), pt.y()), 1, 1.0, Scalar(0, 0, 255));
					}
				}
				imshow("img", img);
				waitKey(1);
			}
		}
	}
	catch (exception& e)
	{
		cout << e.what() << endl;
	}
	waitKey();
	return 0;
}

Taily老段的微信公众号,欢迎交流学习

https://blog.csdn.net/taily_duan/article/details/81214815


 

 

 

2018-11-12 10:59:38 blakebai 阅读数 488
  • Python实战系列之Tornado开发人脸识别微信小程序

    项目将应用tornado、pymongo、ip2region、dlib、pillow、opencv等技术打造一个完整的人脸识别微信小程序。我将在实战过程中带大家快速掌握python mtv的设计模式、API接口设计、人脸特征|框选|截取|勾勒|化妆功能封装、微信授权登录、小程序组件开发、IP地址解析、UA访问跟踪、后台管理系统开发以及基于线程池的异步io非阻塞等技术。

    603 人正在学习 去看看 张金龙

cmake  配置 

cmake_minimum_required(VERSION 3.4.1)

include(src/main/cpp/dlib/cmake)

set(CMAKE_VERBOSE_MAKEFILE on)

add_library( # Sets the name of the library.
             native-lib
             # Sets the library as a shared library.
             SHARED

             # Provides a relative path to your source file(s).
             src/main/cpp/dlib/all/source.cpp
             src/main/cpp/native-lib.cpp )

find_library( # Sets the name of the path variable.
              log-lib

              # Specifies the name of the NDK library that
              # you want CMake to locate.
              log )

target_link_libraries( # Specifies the target library.
                       native-lib
                        dlib
                       # Links the target library to the log library
                       # included in the NDK.
                       ${log-lib} )

gradle配置  

cppFlags "-frtti -fexceptions -std=c++11"
arguments "-DANDROID_STL =c++_shared"

 

另外  会报错  <png.h> 和 <jpeglib.h>  

<png.h>改为"../external/libpng/png.h"

<jpeglib.h>改为"../external/libjpeg/jpeglib.h"

2018-02-09 14:05:12 nia305 阅读数 4159
  • Python实战系列之Tornado开发人脸识别微信小程序

    项目将应用tornado、pymongo、ip2region、dlib、pillow、opencv等技术打造一个完整的人脸识别微信小程序。我将在实战过程中带大家快速掌握python mtv的设计模式、API接口设计、人脸特征|框选|截取|勾勒|化妆功能封装、微信授权登录、小程序组件开发、IP地址解析、UA访问跟踪、后台管理系统开发以及基于线程池的异步io非阻塞等技术。

    603 人正在学习 去看看 张金龙

上篇文章 里面配置好了Android + OpenCV2的环境。
下面介绍如何把Dlib也移植到Android端:

1.从官网上面下载相关的Dlib。
2.解压压缩包到拥有读写权限的文件夹下面。
3.把dlib(包含所有源代码)的文件夹拷贝到jni文件夹下面。

4.我们需要把source.cpp文件一并加入源文件进行编译:

Android.mk
#添加下面这行
LOCAL_SRC_FILES += ./dlib/all/source.cpp

5.修改Applicaiton.mk文件:

Application.mk
#禁用Dlib的GUI
APP_CPPFLAGS += -DDLIB_NO_GUI_SUPPORT=1
#使Dlib可以加载JPEG类型的图片
APP_CPPFLAGS += -DDLIB_JPEG_SUPPORT -DDLIB_JPEG_STATIC

6.现在就算是把dlib移植到Android上面了。

移植肯定不会这么简单的,上面是过程,下面是遇到的问题

1.两个库之间一些冲突:具体的现象:

Application.mk

APP_STL := gnustl_static
APP_STL := c++_static

前面一篇文章,使用gnustl_static作为标准库,没有任何问题,因为Opencv for Android 好像就是用gnu的标准库来编译的。但是一旦加入了dlib,那么就会出现类似下面的这种错误:

error :no member named ‘round’ in namespace ‘std’; did you mean simply ‘round’?
error :no member named ‘to_string’ in namespace ‘std’;

因为dlib使用的是libc++标准库,就是Applicaiton.mk里面的c++_static。
但是如果我们把gnustl_static替换成c++ _static的话,那么opencv就要报错了:一堆链接错误,也是关于标准库的错误。

解决办法:
自己实现to_string 和 round函数,并在相应的文件里面include。
to_string:

#include <string>
#include <sstream>

using namespace std;
namespace std {
    template <typename T> std::string to_string(const T& n) {
        std::ostringstream stm;
        stm << n;
        return stm.str();
    }
}

round:

using namespace std;

namespace std {
    template <typename T> T round(T v) {
        return (v > 0) ? (v + 0.5) : (v - 0.5);
    }
}

2.找不到类似于

undefined reference to 'jpeg_set_quality(jpeg_compress_struct*, int, int)'
/home/mercury/AndroidStudioProjects/app/src/main/jni/./dlib/all/../image_saver/save_jpeg.cpp:153: error: undefined reference to 'jpeg_start_compress(jpeg_compress_struct*, int)'
/home/mercury/AndroidStudioProjects/app/src/main/jni/./dlib/all/../image_saver/save_jpeg.cpp:158: error: undefined reference to 'jpeg_write_scanlines(jpeg_compress_struct*, unsigned char**, unsigned int)'
/home/mercury/AndroidStudioProjects/app/src/main/jni/./dlib/all/../image_saver/save_jpeg.cpp:161: error: undefined reference to 'jpeg_finish_compress(jpeg_compress_struct*)'

又是链接错误,这个问题可能是由于c++命名规则造成的,我们需要在jpeg_loader.cpp文件里面加上

extern “C”

好了,现在dlib就移植到了Android上面。

没有更多推荐了,返回首页