關(guān)于opencv的人臉識別的Demo配置(android端不需要Manager)

相信各位再開發(fā)中經(jīng)常會用到人臉識別的技術(shù),opencv是其中的一種實現(xiàn)方案,但是需要精通NDK,不然光是配置都搞死一堆人,不啰嗦了。

第一步:去官網(wǎng)下載:https://sourceforge.net/projects/opencvlibrary/files/opencv-android/3.2.0/opencv-3.2.0-android-sdk.zip/download

第二步:解壓后創(chuàng)建一個androidProject

接著下一步下一步,記得異常支持的兩個勾勾上

第三步:點擊File->importModule(選擇你下載的Opencv-android-sdk)目錄下sdk/java,點擊Ok


第四步:再把導(dǎo)入的類庫添加依賴,我導(dǎo)入的這里項目叫app


第五步:

5.1,samples目錄下的face-detection中的src復(fù)制到app這個項目的src下(把系統(tǒng)生成的刪除)

5.2,導(dǎo)入layout,和raw

5.3,把jni目錄下的DetectionBasedTracker_jni.cpp和DetectionBasedTracker_jni.h拷貝到cpp目錄下,

5.4,在main目錄下新建jniLibs目錄,在jniLibs下新建armeabi,再sdk/native/libs/armeabi目錄下的libopencv_java3.so,拷貝到新建的jniLibs目下的armeabi,

5.5,將sdk/native/jni/include文件下的所有東西,全部考入到j(luò)niLibs目錄下。

完成后的結(jié)構(gòu)如下圖


第六步:在CMakeList.txt文件中寫入(原來文件中的全部刪除,復(fù)制粘貼下面的即可,這是NDK的配置,在這里就不多解釋,老司機一看就明白)

# For more information about using CMake with Android Studio, read the

# documentation: https://d.android.com/studio/projects/add-native-code.html

# Sets the minimum version of CMake required to build the native library.

cmake_minimum_required(VERSION 3.4.1)

# Creates and names a library, sets it as either STATIC

# or SHARED, and provides the relative paths to its source code.

# You can define multiple libraries, and CMake builds them for you.

# Gradle automatically packages shared libraries with your APK.

add_library(

opencv_java3

SHARED

IMPORTED)

set_target_properties(

opencv_java3

PROPERTIES IMPORTED_LOCATION

../../../../src/main/jniLibs/armeabi/libopencv_java3.so)

#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")

if(CMAKE_COMPILER_IS_GNUCXX)

set(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")

message(STATUS "optional:-std=c++11")

endif(CMAKE_COMPILER_IS_GNUCXX)

include_directories(src/main/jniLibs/include)

add_library( # Sets the name of the library.

detection_based_tracker

# Sets the library as a shared library.

SHARED

# Provides a relative path to your source file(s).

src/main/cpp/DetectionBasedTracker_jni.cpp )

# Searches for a specified prebuilt library and stores the path as a

# variable. Because CMake includes system libraries in the search path by

# default, you only need to specify the name of the public NDK library

# you want to add. CMake verifies that the library exists before

# completing its build.

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 )

# Specifies libraries CMake should link to your target library. You

# can link multiple libraries, such as libraries you define in this

# build script, prebuilt third-party libraries, or system libraries.

target_link_libraries( # Specifies the target library.

detection_based_tracker opencv_java3

# Links the target library to the log library

# included in the NDK.

${log-lib} )

第七步:在build-gradle文件中加入,接著同步一下,檢查是否報錯(記得加相機權(quán)限喲)


第八步:記得運行成功后是需要添加Manager的,但是按照下面做就不需要了(最重要一步)。

8.1在加載類庫的前面加上


8.2并且注釋掉


在點擊運行,這次就不需要Manager了,記得沒有申請運行時權(quán)限的請在應(yīng)用管理中打開喲,至于,相機全屏的,請參考它的demo,確實不會就復(fù)制它的AndroidManifest.xml文件到覆蓋你自己的就行。

第一次寫文章,老司機和大神們多多關(guān)照。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容