forked from PaddlePaddle/PaddleOCR
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Android] Add mask detection demo (PaddlePaddle#49)
test=develop
- Loading branch information
1 parent
a8a8ab5
commit 7cf3f70
Showing
64 changed files
with
3,580 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/caches | ||
/.idea/libraries | ||
/.idea/modules.xml | ||
/.idea/workspace.xml | ||
/.idea/navEditor.xml | ||
/.idea/assetWizardSettings.xml | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild |
4 changes: 4 additions & 0 deletions
4
PaddleLite-android-demo/mask_detection_demo/.idea/encodings.xml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
15 changes: 15 additions & 0 deletions
15
PaddleLite-android-demo/mask_detection_demo/.idea/gradle.xml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
PaddleLite-android-demo/mask_detection_demo/.idea/runConfigurations.xml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
95 changes: 95 additions & 0 deletions
95
PaddleLite-android-demo/mask_detection_demo/app/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import java.security.MessageDigest | ||
|
||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 28 | ||
defaultConfig { | ||
applicationId "com.baidu.paddle.lite.demo.mask_detection" | ||
minSdkVersion 15 | ||
targetSdkVersion 28 | ||
versionCode 1 | ||
versionName "1.0" | ||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
externalNativeBuild { | ||
cmake { | ||
arguments '-DANDROID_PLATFORM=android-23', '-DANDROID_STL=c++_shared', "-DANDROID_TOOLCHAIN=" | ||
abiFilters 'armeabi-v7a', 'arm64-v8a' | ||
cppFlags "-std=c++11" | ||
} | ||
} | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
externalNativeBuild { | ||
cmake { | ||
path "src/main/cpp/CMakeLists.txt" | ||
version "3.10.2" | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation fileTree(include: ['*.jar'], dir: 'libs') | ||
implementation 'com.android.support:appcompat-v7:28.0.0' | ||
implementation 'com.android.support.constraint:constraint-layout:1.1.3' | ||
implementation 'com.android.support:design:28.0.0' | ||
testImplementation 'junit:junit:4.12' | ||
androidTestImplementation 'com.android.support.test:runner:1.0.2' | ||
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' | ||
} | ||
|
||
def archives = [ | ||
[ | ||
'src' : 'https://paddlelite-demo.bj.bcebos.com/libs/android/paddle_lite_libs_v2_3_0.tar.gz', | ||
'dest': 'PaddleLite' | ||
], | ||
[ | ||
'src' : 'https://paddlelite-demo.bj.bcebos.com/libs/android/opencv-4.2.0-android-sdk.tar.gz', | ||
'dest': 'OpenCV' | ||
], | ||
[ | ||
'src' : 'https://paddlelite-demo.bj.bcebos.com/models/pyramidbox_lite_fp32_for_cpu_v2_3_0.tar.gz', | ||
'dest' : 'src/main/assets/models/pyramidbox_lite_for_cpu' | ||
], | ||
[ | ||
'src' : 'https://paddlelite-demo.bj.bcebos.com/models/mask_detector_fp32_128_128_for_cpu_v2_3_0.tar.gz', | ||
'dest' : 'src/main/assets/models/mask_detector_for_cpu' | ||
] | ||
] | ||
|
||
task downloadAndExtractArchives(type: DefaultTask) { | ||
doFirst { | ||
println "Downloading and extracting archives including libs and models" | ||
} | ||
doLast { | ||
// Prepare cache folder for archives | ||
String cachePath = "cache" | ||
if (!file("${cachePath}").exists()) { | ||
mkdir "${cachePath}" | ||
} | ||
archives.eachWithIndex { archive, index -> | ||
MessageDigest messageDigest = MessageDigest.getInstance('MD5') | ||
messageDigest.update(archive.src.bytes) | ||
String cacheName = new BigInteger(1, messageDigest.digest()).toString(32) | ||
// Download the target archive if not exists | ||
boolean copyFiles = !file("${archive.dest}").exists() | ||
if (!file("${cachePath}/${cacheName}.tar.gz").exists()) { | ||
ant.get(src: archive.src, dest: file("${cachePath}/${cacheName}.tar.gz")) | ||
copyFiles = true; // force to copy files from the latest archive files | ||
} | ||
// Extract the target archive if its dest path does not exists | ||
if (copyFiles) { | ||
copy { | ||
from tarTree("${cachePath}/${cacheName}.tar.gz") | ||
into "${archive.dest}" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
preBuild.dependsOn downloadAndExtractArchives |
21 changes: 21 additions & 0 deletions
21
PaddleLite-android-demo/mask_detection_demo/app/proguard-rules.pro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
26 changes: 26 additions & 0 deletions
26
...c/androidTest/java/com/baidu/paddle/lite/demo/mask_detection/ExampleInstrumentedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.baidu.paddle.lite.demo.mask_detection; | ||
|
||
import android.content.Context; | ||
import android.support.test.InstrumentationRegistry; | ||
import android.support.test.runner.AndroidJUnit4; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> | ||
*/ | ||
@RunWith(AndroidJUnit4.class) | ||
public class ExampleInstrumentedTest { | ||
@Test | ||
public void useAppContext() { | ||
// Context of the app under test. | ||
Context appContext = InstrumentationRegistry.getTargetContext(); | ||
|
||
assertEquals("com.baidu.paddle.lite.demo", appContext.getPackageName()); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
PaddleLite-android-demo/mask_detection_demo/app/src/main/AndroidManifest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.baidu.paddle.lite.demo.mask_detection"> | ||
|
||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> | ||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> | ||
<uses-permission android:name="android.permission.CAMERA"/> | ||
<uses-feature android:name="android.hardware.camera" /> | ||
<uses-feature android:name="android.hardware.camera.autofocus" /> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
<activity android:name=".MainActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN"/> | ||
|
||
<category android:name="android.intent.category.LAUNCHER"/> | ||
</intent-filter> | ||
</activity> | ||
<activity | ||
android:name=".SettingsActivity" | ||
android:label="Settings"> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
Oops, something went wrong.