Skip to content

Commit ea1f3e6

Browse files
authored
[Android] Add PicoDet android jni demo (#405)
* [Android] Add picodet android jni demo * [Android] Add picodet android jni demo * [CMake] exclude jni files from examples exe srcs
1 parent e51b8fc commit ea1f3e6

File tree

104 files changed

+4385
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+4385
-2
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ repos:
3232
# entry: bash .clang_format.hook -i
3333
# language: system
3434
# files: \.(c|cc|cxx|cpp|cu|h|hpp|hxx|proto)$
35-
#
35+
3636
- repo: local
3737
hooks:
3838
- id: cpplint-cpp-source

examples/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ if(BUILD_EXAMPLES AND ENABLE_VISION)
7272
if(EXISTS ${PROJECT_SOURCE_DIR}/examples/vision)
7373
message(STATUS "")
7474
message(STATUS "*************FastDeploy Vision Examples Summary**********")
75-
file(GLOB_RECURSE ALL_VISION_EXAMPLE_SRCS ${PROJECT_SOURCE_DIR}/examples/vision/*.cc)
75+
file(GLOB_RECURSE ALL_VISION_EXAMPLE_SRCS ${PROJECT_SOURCE_DIR}/examples/vision/*/*/cpp/*.cc)
7676
foreach(_CC_FILE ${ALL_VISION_EXAMPLE_SRCS})
7777
add_fastdeploy_executable(vision ${_CC_FILE})
7878
endforeach()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.DS_Store
2+
.idea
3+
.gradle
4+
.cxx
5+
cache
6+
build
7+
app/cache
8+
app/libs/fastdeploy*
9+
app/.cxx
10+
app/build
11+
app/src/main/assets/models/*
12+
app/.gradle
13+
app/.idea
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 目标检测 Android Demo 使用文档
2+
3+
- TODO
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import java.security.MessageDigest
2+
3+
apply plugin: 'com.android.application'
4+
5+
android {
6+
compileSdk 28
7+
8+
defaultConfig {
9+
applicationId "com.baidu.paddle.fastdeploy"
10+
minSdkVersion 15
11+
//noinspection ExpiredTargetSdkVersion
12+
targetSdkVersion 28
13+
versionCode 1
14+
versionName "1.0"
15+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
16+
17+
externalNativeBuild {
18+
cmake {
19+
arguments '-DANDROID_PLATFORM=android-21', '-DANDROID_STL=c++_shared', "-DANDROID_TOOLCHAIN=clang"
20+
abiFilters 'armeabi-v7a', 'arm64-v8a'
21+
cppFlags "-std=c++11"
22+
}
23+
}
24+
}
25+
26+
buildTypes {
27+
release {
28+
minifyEnabled false
29+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
30+
}
31+
}
32+
33+
externalNativeBuild {
34+
cmake {
35+
path file('src/main/cpp/CMakeLists.txt')
36+
version '3.10.2'
37+
}
38+
}
39+
ndkVersion '20.1.5948944'
40+
}
41+
42+
dependencies {
43+
implementation fileTree(include: ['*.jar'], dir: 'libs')
44+
implementation 'com.android.support:appcompat-v7:28.0.0'
45+
//noinspection GradleDependency
46+
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
47+
implementation 'com.android.support:design:28.0.0'
48+
implementation 'org.jetbrains:annotations:15.0'
49+
//noinspection GradleDependency
50+
testImplementation 'junit:junit:4.12'
51+
androidTestImplementation 'com.android.support.test:runner:1.0.2'
52+
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
53+
}
54+
55+
def archives = [
56+
[
57+
'src' : 'https://bj.bcebos.com/fastdeploy/release/android/fastdeploy-android-0.4.0-shared.tgz',
58+
'dest': 'libs'
59+
],
60+
[
61+
'src': 'https://bj.bcebos.com/paddlehub/fastdeploy/picodet_s_320_coco_lcnet.tgz',
62+
'dest' : 'src/main/assets/models'
63+
],
64+
[
65+
'src': 'https://bj.bcebos.com/paddlehub/fastdeploy/picodet_l_320_coco_lcnet.tgz',
66+
'dest' : 'src/main/assets/models'
67+
]
68+
]
69+
70+
task downloadAndExtractArchives(type: DefaultTask) {
71+
doFirst {
72+
println "Downloading and extracting archives including libs and models"
73+
}
74+
doLast {
75+
// Prepare cache folder for archives
76+
String cachePath = "cache"
77+
if (!file("${cachePath}").exists()) {
78+
mkdir "${cachePath}"
79+
}
80+
archives.eachWithIndex { archive, index ->
81+
MessageDigest messageDigest = MessageDigest.getInstance('MD5')
82+
messageDigest.update(archive.src.bytes)
83+
String cacheName = new BigInteger(1, messageDigest.digest()).toString(32)
84+
// Download the target archive if not exists
85+
boolean copyFiles = !file("${archive.dest}").exists()
86+
if (!file("${cachePath}/${cacheName}.tgz").exists()) {
87+
ant.get(src: archive.src, dest: file("${cachePath}/${cacheName}.tgz"))
88+
copyFiles = true // force to copy files from the latest archive files
89+
}
90+
// Extract the target archive if its dest path does not exists
91+
if (copyFiles) {
92+
copy {
93+
from tarTree("${cachePath}/${cacheName}.tgz")
94+
into "${archive.dest}"
95+
}
96+
}
97+
}
98+
}
99+
}
100+
preBuild.dependsOn downloadAndExtractArchives
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fastdeploy-*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.baidu.paddle.fastdeploy;
2+
3+
import android.content.Context;
4+
5+
import androidx.test.platform.app.InstrumentationRegistry;
6+
import androidx.test.ext.junit.runners.AndroidJUnit4;
7+
8+
import org.junit.Test;
9+
import org.junit.runner.RunWith;
10+
11+
import static org.junit.Assert.*;
12+
13+
/**
14+
* Instrumented test, which will execute on an Android device.
15+
*
16+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
17+
*/
18+
@RunWith(AndroidJUnit4.class)
19+
public class ExampleInstrumentedTest {
20+
@Test
21+
public void useAppContext() {
22+
// Context of the app under test.
23+
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
24+
assertEquals("com.baidu.paddle.fastdeploy", appContext.getPackageName());
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.baidu.paddle.fastdeploy.examples">
4+
5+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
6+
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
7+
<uses-permission android:name="android.permission.CAMERA"/>
8+
<uses-feature android:name="android.hardware.camera" />
9+
<uses-feature android:name="android.hardware.camera.autofocus" />
10+
11+
<application
12+
android:allowBackup="true"
13+
android:icon="@mipmap/ic_launcher"
14+
android:label="@string/app_name"
15+
android:roundIcon="@mipmap/ic_launcher_round"
16+
android:supportsRtl="true"
17+
android:theme="@style/AppTheme">
18+
<activity android:name="com.baidu.paddle.fastdeploy.examples.MainActivity">
19+
<intent-filter>
20+
<action android:name="android.intent.action.MAIN"/>
21+
<category android:name="android.intent.category.LAUNCHER"/>
22+
</intent-filter>
23+
</activity>
24+
<activity
25+
android:name="com.baidu.paddle.fastdeploy.examples.SettingsActivity"
26+
android:label="Settings">
27+
</activity>
28+
</application>
29+
30+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
person
2+
bicycle
3+
car
4+
motorcycle
5+
airplane
6+
bus
7+
train
8+
truck
9+
boat
10+
traffic light
11+
fire hydrant
12+
stop sign
13+
parking meter
14+
bench
15+
bird
16+
cat
17+
dog
18+
horse
19+
sheep
20+
cow
21+
elephant
22+
bear
23+
zebra
24+
giraffe
25+
backpack
26+
umbrella
27+
handbag
28+
tie
29+
suitcase
30+
frisbee
31+
skis
32+
snowboard
33+
sports ball
34+
kite
35+
baseball bat
36+
baseball glove
37+
skateboard
38+
surfboard
39+
tennis racket
40+
bottle
41+
wine glass
42+
cup
43+
fork
44+
knife
45+
spoon
46+
bowl
47+
banana
48+
apple
49+
sandwich
50+
orange
51+
broccoli
52+
carrot
53+
hot dog
54+
pizza
55+
donut
56+
cake
57+
chair
58+
couch
59+
potted plant
60+
bed
61+
dining table
62+
toilet
63+
tv
64+
laptop
65+
mouse
66+
remote
67+
keyboard
68+
cell phone
69+
microwave
70+
oven
71+
toaster
72+
sink
73+
refrigerator
74+
book
75+
clock
76+
vase
77+
scissors
78+
teddy bear
79+
hair drier
80+
toothbrush
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
background
2+
aeroplane
3+
bicycle
4+
bird
5+
boat
6+
bottle
7+
bus
8+
car
9+
cat
10+
chair
11+
cow
12+
diningtable
13+
dog
14+
horse
15+
motorbike
16+
person
17+
pottedplant
18+
sheep
19+
sofa
20+
train
21+
tvmonitor
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# For more information about using CMake with Android Studio, read the
2+
# documentation: https://d.android.com/studio/projects/add-native-code.html
3+
4+
# Sets the minimum version of CMake required to build the native library.
5+
cmake_minimum_required(VERSION 3.10.2)
6+
7+
# Declares and names the project.
8+
project("fastdeploy_jni")
9+
10+
# Creates and names a library, sets it as either STATIC
11+
# or SHARED, and provides the relative paths to its source code.
12+
# You can define multiple libraries, and CMake builds them for you.
13+
# Gradle automatically packages shared libraries with your APK.
14+
15+
set(FastDeploy_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../libs/fastdeploy-android-0.4.0-shared")
16+
17+
find_package(FastDeploy REQUIRED)
18+
19+
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
20+
include_directories(${FastDeploy_INCLUDE_DIRS})
21+
22+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffast-math -Ofast -Os -DNDEBUG -fno-exceptions -fomit-frame-pointer -fno-asynchronous-unwind-tables -fno-unwind-tables")
23+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden -fdata-sections -ffunction-sections")
24+
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--gc-sections -Wl,-z,nocopyreloc")
25+
26+
add_library(
27+
fastdeploy_jni
28+
SHARED
29+
utils_jni.cc
30+
bitmap_jni.cc
31+
vision/results_jni.cc
32+
vision/visualize_jni.cc
33+
vision/detection/picodet_jni.cc
34+
vision/classification/paddleclas_model_jni.cc)
35+
36+
# Searches for a specified prebuilt library and stores the path as a
37+
# variable. Because CMake includes system libraries in the search path by
38+
# default, you only need to specify the name of the public NDK library
39+
# you want to add. CMake verifies that the library exists before
40+
# completing its build.
41+
42+
find_library( # Sets the name of the path variable.
43+
log-lib
44+
# Specifies the name of the NDK library that
45+
# you want CMake to locate.
46+
log)
47+
48+
# Specifies libraries CMake should link to your target library. You can link
49+
# multiple libraries, such as libraries you define in this build script,
50+
# prebuilt third-party libraries, or system libraries.
51+
52+
target_link_libraries(
53+
# Specifies the target library.
54+
fastdeploy_jni
55+
jnigraphics
56+
${FASTDEPLOY_LIBS}
57+
GLESv2
58+
EGL
59+
${log-lib}
60+
)

0 commit comments

Comments
 (0)