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

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

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

原方地址: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-09-27 18:22:56 longji 阅读数 1323
  • Python实战系列之Tornado开发人脸识别微信小程序

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

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

01 android studio 创建支持c++项目

打开android studio后,构建一个支持c++的项目,具体步骤如下:

01.01 Start a new Android Studio project

这里写图片描述

01.02 Configure your new project

Application name:dlib-android-build
Company domain:soft.example.com
勾选 Include C++ support
Project location:D:\git\dlib\build\dlib-android-build

这里写图片描述

01.03 Target Android Devices选择默认项

这里写图片描述

01.04 Add an Activity to Mobile 选择Basic Activity

这里写图片描述

01.05 Customize the Activity选择默认值

这里写图片描述

01.06 Customize C++ Support

C++ Standard 选择C++11
勾选 Exceptions Support(-fexceptions)
勾选 Runtime Type Information Support (-frtti)

这里写图片描述

02 导入dlib库,配置android属性

02.01 导入dlib库源码

把下载好的dlib目录中的dlib子目录,拷贝到D:\git\dlib\build\dlib-android-build\app\src\main\cpp中。

这里写图片描述

这里写图片描述

02.02 修改CMakeLists.txt配置项

修改D:\git\dlib\build\dlib-android-build\app\CMakeLists.txt配置项。
在add_library和find_library之间加入一句include(src/main/cpp/dlib/cmake)
在target_link_libraries中添加dlib
这里写图片描述

02.03 配置build.gradle

配置D:\git\dlib\build\dlib-android-build\app\build.gradle
在build.gradle的externalNativeBuild的cmake中添加arguments "-DANDROID_STL=c++_shared"
这里写图片描述

03 导入C++demo中的 matrix_ex

创建这个android项目,默认已经有native-lib.cpp文件,内容如下:

#include <jni.h>
#include <string>

extern "C"
JNIEXPORT jstring JNICALL
Java_com_example_soft_dlib_1android_1build_MainActivity_stringFromJNI(
        JNIEnv *env,
        jobject /* this */) {
    std::string hello = "Hello from C++";
    return env->NewStringUTF(hello.c_str());
}

dlib的github下载的源代码中,有dlib\examples\matrix_ex.cpp。因为stringFromJNI返回值是string类型,把matrix_ex 内容稍作修改,把默认输出改为字符串。拷贝到native-lib.cpp,最后native-lib.cpp的内容如下:

#include <jni.h>
#include <string>

#include <iostream>
#include <dlib/matrix.h>
#include <sstream>

using namespace dlib;
using namespace std;

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

string matrix_ex()
{
    stringstream ssout;
    // Let's begin this example by using the library to solve a simple
    // linear system.
    //
    // We will find the value of x such that y = M*x where
    //
    //      3.5
    // y =  1.2
    //      7.8
    //
    // and M is
    //
    //      54.2   7.4   12.1
    // M =  1      2     3
    //      5.9    0.05  1


    // First let's declare these 3 matrices.
    // This declares a matrix that contains doubles and has 3 rows and 1 column.
    // Moreover, it's size is a compile time constant since we put it inside the <>.
    matrix<double,3,1> y;
    // Make a 3 by 3 matrix of doubles for the M matrix.  In this case, M is
    // sized at runtime and can therefore be resized later by calling M.set_size().
    matrix<double> M(3,3);

    // You may be wondering why someone would want to specify the size of a
    // matrix at compile time when you don't have to.  The reason is two fold.
    // First, there is often a substantial performance improvement, especially
    // for small matrices, because it enables a number of optimizations that
    // otherwise would be impossible.  Second, the dlib::matrix object checks
    // these compile time sizes to ensure that the matrices are being used
    // correctly.  For example, if you attempt to compile the expression y*y you
    // will get a compiler error since that is not a legal matrix operation (the
    // matrix dimensions don't make sense as a matrix multiplication).  So if
    // you know the size of a matrix at compile time then it is always a good
    // idea to let the compiler know about it.




    // Now we need to initialize the y and M matrices and we can do so like this:
    M = 54.2,  7.4,  12.1,
            1,     2,    3,
            5.9,   0.05, 1;

    y = 3.5,
            1.2,
            7.8;


    // The solution to y = M*x can be obtained by multiplying the inverse of M
    // with y.  As an aside, you should *NEVER* use the auto keyword to capture
    // the output from a matrix expression.  So don't do this: auto x = inv(M)*y;
    // To understand why, read the matrix_expressions_ex.cpp example program.
    matrix<double> x = inv(M)*y;

    cout << "x: \n" << x << endl;
    ssout << "x: \n" << x << endl;

    // We can check that it really worked by plugging x back into the original equation
    // and subtracting y to see if we get a column vector with values all very close
    // to zero (Which is what happens.  Also, the values may not be exactly zero because
    // there may be some numerical error and round off).
    cout << "M*x - y: \n" << M*x - y << endl;
    ssout << "M*x - y: \n" << M*x - y << endl;


    // Also note that we can create run-time sized column or row vectors like so
    matrix<double,0,1> runtime_sized_column_vector;
    matrix<double,1,0> runtime_sized_row_vector;
    // and then they are sized by saying
    runtime_sized_column_vector.set_size(3);

    // Similarly, the x matrix can be resized by calling set_size(num rows, num columns).  For example
    x.set_size(3,4);  // x now has 3 rows and 4 columns.



    // The elements of a matrix are accessed using the () operator like so:
    cout << M(0,1) << endl;
    ssout << M(0,1) << endl;
    // The above expression prints out the value 7.4.  That is, the value of
    // the element at row 0 and column 1.

    // If we have a matrix that is a row or column vector.  That is, it contains either
    // a single row or a single column then we know that any access is always either
    // to row 0 or column 0 so we can omit that 0 and use the following syntax.
    cout << y(1) << endl;
    ssout << y(1) << endl;
    // The above expression prints out the value 1.2


    // Let's compute the sum of elements in the M matrix.
    double M_sum = 0;
    // loop over all the rows
    for (long r = 0; r < M.nr(); ++r)
    {
        // loop over all the columns
        for (long c = 0; c < M.nc(); ++c)
        {
            M_sum += M(r,c);
        }
    }
    cout << "sum of all elements in M is " << M_sum << endl;
    ssout << "sum of all elements in M is " << M_sum << endl;

    // The above code is just to show you how to loop over the elements of a matrix.  An
    // easier way to find this sum is to do the following:
    cout << "sum of all elements in M is " << sum(M) << endl;
    ssout << "sum of all elements in M is " << sum(M) << endl;



    // Note that you can always print a matrix to an output stream by saying:
    cout << M << endl;
    ssout << M << endl;
    // which will print:
    //   54.2  7.4 12.1
    //      1    2    3
    //    5.9 0.05    1

    // However, if you want to print using comma separators instead of spaces you can say:
    cout << csv << M << endl;
    ssout << csv << M << endl;
    // and you will instead get this as output:
    //   54.2, 7.4, 12.1
    //   1, 2, 3
    //   5.9, 0.05, 1

    // Conversely, you can also read in a matrix that uses either space, tab, or comma
    // separated values by uncommenting the following:
    // cin >> M;



    // -----------------------------  Comparison with MATLAB ------------------------------
    // Here I list a set of Matlab commands and their equivalent expressions using the dlib
    // matrix.  Note that there are a lot more functions defined for the dlib::matrix.  See
    // the HTML documentation for a full listing.

    matrix<double> A, B, C, D, E;
    matrix<int> Aint;
    matrix<long> Blong;

    // MATLAB: A = eye(3)
    A = identity_matrix<double>(3);

    // MATLAB: B = ones(3,4)
    B = ones_matrix<double>(3,4);

    // MATLAB: B = rand(3,4)
    B = randm(3,4);

    // MATLAB: C = 1.4*A
    C = 1.4*A;

    // MATLAB: D = A.*C
    D = pointwise_multiply(A,C);

    // MATLAB: E = A * B
    E = A*B;

    // MATLAB: E = A + B
    E = A + C;

    // MATLAB: E = A + 5
    E = A + 5;

    // MATLAB: E = E'
    E = trans(E);  // Note that if you want a conjugate transpose then you need to say conj(trans(E))

    // MATLAB: E = B' * B
    E = trans(B)*B;

    double var;
    // MATLAB: var = A(1,2)
    var = A(0,1); // dlib::matrix is 0 indexed rather than starting at 1 like Matlab.

    // MATLAB: C = round(C)
    C = round(C);

    // MATLAB: C = floor(C)
    C = floor(C);

    // MATLAB: C = ceil(C)
    C = ceil(C);

    // MATLAB: C = diag(B)
    C = diag(B);

    // MATLAB: B = cast(A, "int32")
    Aint = matrix_cast<int>(A);

    // MATLAB: A = B(1,:)
    A = rowm(B,0);

    // MATLAB: A = B([1:2],:)
    A = rowm(B,range(0,1));

    // MATLAB: A = B(:,1)
    A = colm(B,0);

    // MATLAB: A = [1:5]
    Blong = range(1,5);

    // MATLAB: A = [1:2:5]
    Blong = range(1,2,5);

    // MATLAB: A = B([1:3], [1:2])
    A = subm(B, range(0,2), range(0,1));
    // or equivalently
    A = subm(B, rectangle(0,0,1,2));


    // MATLAB: A = B([1:3], [1:2:4])
    A = subm(B, range(0,2), range(0,2,3));

    // MATLAB: B(:,:) = 5
    B = 5;
    // or equivalently
    set_all_elements(B,5);


    // MATLAB: B([1:2],[1,2]) = 7
    set_subm(B,range(0,1), range(0,1)) = 7;

    // MATLAB: B([1:3],[2:3]) = A
    set_subm(B,range(0,2), range(1,2)) = A;

    // MATLAB: B(:,1) = 4
    set_colm(B,0) = 4;

    // MATLAB: B(:,[1:2]) = 4
    set_colm(B,range(0,1)) = 4;

    // MATLAB: B(:,1) = B(:,2)
    set_colm(B,0) = colm(B,1);

    // MATLAB: B(1,:) = 4
    set_rowm(B,0) = 4;

    // MATLAB: B(1,:) = B(2,:)
    set_rowm(B,0) = rowm(B,1);

    // MATLAB: var = det(E' * E)
    var = det(trans(E)*E);

    // MATLAB: C = pinv(E)
    C = pinv(E);

    // MATLAB: C = inv(E)
    C = inv(E);

    // MATLAB: [A,B,C] = svd(E)
    svd(E,A,B,C);

    // MATLAB: A = chol(E,'lower')
    A = chol(E);

    // MATLAB: var = min(min(A))
    var = min(A);

    return ssout.str();
}

extern "C"
JNIEXPORT jstring JNICALL
Java_com_example_soft_dlib_1android_1build_MainActivity_stringFromJNI(
        JNIEnv *env,
        jobject /* this */) {
    //std::string hello = "Hello from C++";
    std::string hello = matrix_ex();
    return env->NewStringUTF(hello.c_str());
}

这里写图片描述

04 编译,调试

04.01 编译

选择Build==>Make Project菜单,或者Ctrl+F9键编译。
这里写图片描述

04.02 调试

选择Run==>Debug ‘app’菜单,或者Shift+F9键调试。
这里写图片描述

04.03 运行结果

这里写图片描述

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

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

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

最近因为需要,尝试着将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库的存储开销对一个小程序来说就有点大,如果大家有啥减少存储开销的好办法请留言我。

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

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

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

上篇文章 里面配置好了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上面。

2018-06-03 09:31:29 duanshao 阅读数 236
  • Python实战系列之Tornado开发人脸识别微信小程序

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

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

dlib-android-app原来是基于as3.0的,因个人安装的是as2.3,为了能在windows上运行起来,

进行了必要的修改。参见如下。

1、dlib-android-app的build.gradle的修改

主要是ndk,sdk的版本修改。尤其是gradle版本改成2.3.0

2、app的build.gradle的修改

为了编译过,需要把implementation改成compile。

同时,为避免重复包含的问题,做如下2处变动。

在defaultConfig 中增加multiDexEnabled true

在androidTestCompile中增加exclude group: 'com.android.support', module: 'support-v4'。

3、把content_main.xml中如下一行删除。

app:layout_behavior="@string/appbar_scrolling_view_behavior"

之后就可以build apk,以及run。

完整的代码及编译后的so库,参见个人的github:

https://github.com/renwoxing2016/dlib-android-app-self。


dlib android

阅读数 34

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