diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..16dcd12 --- /dev/null +++ b/.gitignore @@ -0,0 +1,33 @@ +# Gradle files +.gradle/ +build/ + +# Local configuration file (sdk path, etc) +local.properties + +# Log/OS Files +*.log + +# Android Studio generated files and folders +captures/ +.externalNativeBuild/ +.cxx/ +*.apk +output.json + +# IntelliJ +*.iml +.idea/ +misc.xml +deploymentTargetDropDown.xml +render.experimental.xml + +# Keystore files +*.jks +*.keystore + +# Google Services (e.g. APIs or Firebase) +google-services.json + +# Android Profiling +*.hprof \ No newline at end of file diff --git a/multipose/.gitignore b/multipose/.gitignore new file mode 100644 index 0000000..16dcd12 --- /dev/null +++ b/multipose/.gitignore @@ -0,0 +1,33 @@ +# Gradle files +.gradle/ +build/ + +# Local configuration file (sdk path, etc) +local.properties + +# Log/OS Files +*.log + +# Android Studio generated files and folders +captures/ +.externalNativeBuild/ +.cxx/ +*.apk +output.json + +# IntelliJ +*.iml +.idea/ +misc.xml +deploymentTargetDropDown.xml +render.experimental.xml + +# Keystore files +*.jks +*.keystore + +# Google Services (e.g. APIs or Firebase) +google-services.json + +# Android Profiling +*.hprof \ No newline at end of file diff --git a/multipose/README.md b/multipose/README.md index 502c02f..8211c98 100644 --- a/multipose/README.md +++ b/multipose/README.md @@ -23,7 +23,7 @@ https://github.com/nihui/opencv-mobile ### step3 * Open this project with Android Studio, build it and enjoy! ## result -![](result.gif) +![](../multipose.gif) ## reference: https://github.com/nihui/ncnn-android-nanodet https://tfhub.dev/google/movenet/multipose/lightning/1 diff --git a/multipose/app/build.gradle b/multipose/app/build.gradle index 1e629fe..67949f4 100644 --- a/multipose/app/build.gradle +++ b/multipose/app/build.gradle @@ -1,24 +1,42 @@ -apply plugin: 'com.android.application' +plugins { + id "com.android.application" + id "org.jetbrains.kotlin.android" +} android { - compileSdkVersion 24 - buildToolsVersion "29.0.2" + + compileSdk 34 + + base { + archivesName = "com.tencent.ncnnbodypose" + } defaultConfig { applicationId "com.tencent.ncnnbodypose" - archivesBaseName = "$applicationId" - + targetSdk = 34 minSdkVersion 24 } + buildFeatures { + buildConfig = true + } + externalNativeBuild { cmake { - version "3.10.2" + version "3.22.1" path file('src/main/jni/CMakeLists.txt') } } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + } dependencies { - implementation 'com.android.support:support-v4:24.0.0' + implementation 'com.android.support:support-v4:28.0.0' + } + kotlinOptions { + jvmTarget = '1.8' } + namespace 'com.tencent.ncnnbodypose' } diff --git a/multipose/app/src/main/AndroidManifest.xml b/multipose/app/src/main/AndroidManifest.xml index 37a360e..dcc0614 100644 --- a/multipose/app/src/main/AndroidManifest.xml +++ b/multipose/app/src/main/AndroidManifest.xml @@ -1,15 +1,21 @@ + android:versionCode="1" + android:versionName="1.1"> + + + - - + + diff --git a/multipose/app/src/main/java/com/tencent/ncnnbodypose/MainActivity.java b/multipose/app/src/main/java/com/tencent/ncnnbodypose/MainActivity.java deleted file mode 100644 index 21b139c..0000000 --- a/multipose/app/src/main/java/com/tencent/ncnnbodypose/MainActivity.java +++ /dev/null @@ -1,162 +0,0 @@ -// Tencent is pleased to support the open source community by making ncnn available. -// -// Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. -// -// Licensed under the BSD 3-Clause License (the "License"); you may not use this file except -// in compliance with the License. You may obtain a copy of the License at -// -// https://opensource.org/licenses/BSD-3-Clause -// -// Unless required by applicable law or agreed to in writing, software distributed -// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR -// CONDITIONS OF ANY KIND, either express or implied. See the License for the -// specific language governing permissions and limitations under the License. - -package com.tencent.ncnnbodypose; - -import android.Manifest; -import android.app.Activity; -import android.content.pm.PackageManager; -import android.graphics.PixelFormat; -import android.os.Bundle; -import android.util.Log; -import android.view.Surface; -import android.view.SurfaceHolder; -import android.view.SurfaceView; -import android.view.View; -import android.view.WindowManager; -import android.widget.AdapterView; -import android.widget.Button; -import android.widget.Spinner; - -import android.support.v4.app.ActivityCompat; -import android.support.v4.content.ContextCompat; - -public class MainActivity extends Activity implements SurfaceHolder.Callback -{ - public static final int REQUEST_CAMERA = 100; - - private NcnnBodypose ncnnbodypose = new NcnnBodypose(); - private int facing = 0; - - private Spinner spinnerModel; - private Spinner spinnerCPUGPU; - private int current_model = 0; - private int current_cpugpu = 0; - - private SurfaceView cameraView; - - /** Called when the activity is first created. */ - @Override - public void onCreate(Bundle savedInstanceState) - { - super.onCreate(savedInstanceState); - setContentView(R.layout.main); - - getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); - - cameraView = (SurfaceView) findViewById(R.id.cameraview); - - cameraView.getHolder().setFormat(PixelFormat.RGBA_8888); - cameraView.getHolder().addCallback(this); - - Button buttonSwitchCamera = (Button) findViewById(R.id.buttonSwitchCamera); - buttonSwitchCamera.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View arg0) { - - int new_facing = 1 - facing; - - ncnnbodypose.closeCamera(); - - ncnnbodypose.openCamera(new_facing); - - facing = new_facing; - } - }); - - spinnerModel = (Spinner) findViewById(R.id.spinnerModel); - spinnerModel.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { - @Override - public void onItemSelected(AdapterView arg0, View arg1, int position, long id) - { - if (position != current_model) - { - current_model = position; - reload(); - } - } - - @Override - public void onNothingSelected(AdapterView arg0) - { - } - }); - - spinnerCPUGPU = (Spinner) findViewById(R.id.spinnerCPUGPU); - spinnerCPUGPU.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { - @Override - public void onItemSelected(AdapterView arg0, View arg1, int position, long id) - { - if (position != current_cpugpu) - { - current_cpugpu = position; - reload(); - } - } - - @Override - public void onNothingSelected(AdapterView arg0) - { - } - }); - - reload(); - } - - private void reload() - { - boolean ret_init = ncnnbodypose.loadModel(getAssets(), current_model, current_cpugpu); - if (!ret_init) - { - Log.e("MainActivity", "ncnnbodypose loadModel failed"); - } - } - - @Override - public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) - { - ncnnbodypose.setOutputWindow(holder.getSurface()); - } - - @Override - public void surfaceCreated(SurfaceHolder holder) - { - } - - @Override - public void surfaceDestroyed(SurfaceHolder holder) - { - } - - @Override - public void onResume() - { - super.onResume(); - - if (ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.CAMERA) == PackageManager.PERMISSION_DENIED) - { - ActivityCompat.requestPermissions(this, new String[] {Manifest.permission.CAMERA}, REQUEST_CAMERA); - } - - ncnnbodypose.openCamera(facing); - } - - @Override - public void onPause() - { - super.onPause(); - - ncnnbodypose.closeCamera(); - } -} diff --git a/multipose/app/src/main/java/com/tencent/ncnnbodypose/MainActivity.kt b/multipose/app/src/main/java/com/tencent/ncnnbodypose/MainActivity.kt new file mode 100644 index 0000000..7a6d8fa --- /dev/null +++ b/multipose/app/src/main/java/com/tencent/ncnnbodypose/MainActivity.kt @@ -0,0 +1,139 @@ +// Tencent is pleased to support the open source community by making ncnn available. +// +// Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. +// +// Licensed under the BSD 3-Clause License (the "License"); you may not use this file except +// in compliance with the License. You may obtain a copy of the License at +// +// https://opensource.org/licenses/BSD-3-Clause +// +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// specific language governing permissions and limitations under the License. +package com.tencent.ncnnbodypose + +import android.Manifest +import android.app.Activity +import android.content.pm.PackageManager +import android.graphics.PixelFormat +import android.os.Bundle +import android.support.v4.app.ActivityCompat +import android.support.v4.content.ContextCompat +import android.util.Log +import android.view.SurfaceHolder +import android.view.SurfaceView +import android.view.View +import android.view.WindowManager +import android.widget.AdapterView +import android.widget.AdapterView.OnItemSelectedListener +import android.widget.Button +import android.widget.Spinner + +class MainActivity : Activity(), SurfaceHolder.Callback { + private val ncnnbodypose = NcnnBodypose() + private var facing = 0 + + private var spinnerModel: Spinner? = null + private var spinnerCPUGPU: Spinner? = null + private var current_model = 0 + private var current_cpugpu = 0 + + private var cameraView: SurfaceView? = null + + /** Called when the activity is first created. */ + public override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.main) + + window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) + + cameraView = findViewById(R.id.cameraview) as SurfaceView + + cameraView!!.holder.setFormat(PixelFormat.RGBA_8888) + cameraView!!.holder.addCallback(this) + + val buttonSwitchCamera = findViewById(R.id.buttonSwitchCamera) as Button + buttonSwitchCamera.setOnClickListener { + val new_facing = 1 - facing + ncnnbodypose.closeCamera() + + ncnnbodypose.openCamera(new_facing) + facing = new_facing + } + + spinnerModel = findViewById(R.id.spinnerModel) as Spinner + spinnerModel!!.onItemSelectedListener = object : OnItemSelectedListener { + override fun onItemSelected( + arg0: AdapterView<*>?, arg1: View, position: Int, id: Long + ) { + if (position != current_model) { + current_model = position + reload() + } + } + + override fun onNothingSelected(arg0: AdapterView<*>?) { + } + } + + spinnerCPUGPU = findViewById(R.id.spinnerCPUGPU) as Spinner + spinnerCPUGPU!!.onItemSelectedListener = object : OnItemSelectedListener { + override fun onItemSelected( + arg0: AdapterView<*>?, arg1: View, position: Int, id: Long + ) { + if (position != current_cpugpu) { + current_cpugpu = position + reload() + } + } + + override fun onNothingSelected(arg0: AdapterView<*>?) { + } + } + + reload() + } + + private fun reload() { + val ret_init = ncnnbodypose.loadModel(assets, current_model, current_cpugpu) + if (!ret_init) { + Log.e("MainActivity", "ncnnbodypose loadModel failed") + } + } + + override fun surfaceChanged(holder: SurfaceHolder, format: Int, width: Int, height: Int) { + ncnnbodypose.setOutputWindow(holder.surface) + } + + override fun surfaceCreated(holder: SurfaceHolder) { + } + + override fun surfaceDestroyed(holder: SurfaceHolder) { + } + + public override fun onResume() { + super.onResume() + + if (ContextCompat.checkSelfPermission( + applicationContext, Manifest.permission.CAMERA + ) == PackageManager.PERMISSION_DENIED + ) { + ActivityCompat.requestPermissions( + this, arrayOf(Manifest.permission.CAMERA), REQUEST_CAMERA + ) + } + + ncnnbodypose.openCamera(facing) + } + + public override fun onPause() { + super.onPause() + + ncnnbodypose.closeCamera() + } + + companion object { + const val REQUEST_CAMERA: Int = 100 + } +} diff --git a/singlepose/app/src/main/java/com/tencent/ncnnbodypose/NcnnBodypose.java b/multipose/app/src/main/java/com/tencent/ncnnbodypose/NcnnBodypose.kt similarity index 61% rename from singlepose/app/src/main/java/com/tencent/ncnnbodypose/NcnnBodypose.java rename to multipose/app/src/main/java/com/tencent/ncnnbodypose/NcnnBodypose.kt index eaa287e..4ff14d7 100644 --- a/singlepose/app/src/main/java/com/tencent/ncnnbodypose/NcnnBodypose.java +++ b/multipose/app/src/main/java/com/tencent/ncnnbodypose/NcnnBodypose.kt @@ -11,20 +11,20 @@ // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR // CONDITIONS OF ANY KIND, either express or implied. See the License for the // specific language governing permissions and limitations under the License. +package com.tencent.ncnnbodypose -package com.tencent.ncnnbodypose; +import android.content.res.AssetManager +import android.view.Surface -import android.content.res.AssetManager; -import android.view.Surface; +class NcnnBodypose { + external fun loadModel(mgr: AssetManager?, modelid: Int, cpugpu: Int): Boolean + external fun openCamera(facing: Int): Boolean + external fun closeCamera(): Boolean + external fun setOutputWindow(surface: Surface?): Boolean -public class NcnnBodypose -{ - public native boolean loadModel(AssetManager mgr, int modelid, int cpugpu); - public native boolean openCamera(int facing); - public native boolean closeCamera(); - public native boolean setOutputWindow(Surface surface); - - static { - System.loadLibrary("ncnnbodypose"); + companion object { + init { + System.loadLibrary("ncnnbodypose") + } } } diff --git a/multipose/app/src/main/jni/CMakeLists.txt b/multipose/app/src/main/jni/CMakeLists.txt index fb28047..2460d09 100644 --- a/multipose/app/src/main/jni/CMakeLists.txt +++ b/multipose/app/src/main/jni/CMakeLists.txt @@ -1,10 +1,10 @@ project(ncnnbodypose) cmake_minimum_required(VERSION 3.10) -set(OpenCV_DIR ${CMAKE_SOURCE_DIR}/opencv-mobile-4.5.1-android/sdk/native/jni) +set(OpenCV_DIR ${CMAKE_SOURCE_DIR}/opencv-mobile-4.9.0-android/sdk/native/jni) find_package(OpenCV REQUIRED core imgproc) -set(ncnn_DIR ${CMAKE_SOURCE_DIR}/ncnn-20220216-android-vulkan/${ANDROID_ABI}/lib/cmake/ncnn) +set(ncnn_DIR ${CMAKE_SOURCE_DIR}/ncnn-20240410-android-vulkan/${ANDROID_ABI}/lib/cmake/ncnn) find_package(ncnn REQUIRED) add_library(ncnnbodypose SHARED nanodetncnn.cpp nanodet.cpp ndkcamera.cpp) diff --git a/multipose/app/src/main/res/drawable/ic_launcher_background.xml b/multipose/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..ca3826a --- /dev/null +++ b/multipose/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/multipose/app/src/main/res/drawable/ic_launcher_foreground.xml b/multipose/app/src/main/res/drawable/ic_launcher_foreground.xml new file mode 100644 index 0000000..da1dcd9 --- /dev/null +++ b/multipose/app/src/main/res/drawable/ic_launcher_foreground.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/multipose/app/src/main/res/ic_launcher-playstore.png b/multipose/app/src/main/res/ic_launcher-playstore.png new file mode 100644 index 0000000..cc6ccfc Binary files /dev/null and b/multipose/app/src/main/res/ic_launcher-playstore.png differ diff --git a/multipose/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/multipose/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml new file mode 100644 index 0000000..bbd3e02 --- /dev/null +++ b/multipose/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/multipose/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/multipose/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml new file mode 100644 index 0000000..bbd3e02 --- /dev/null +++ b/multipose/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/multipose/app/src/main/res/mipmap-hdpi/ic_launcher.webp b/multipose/app/src/main/res/mipmap-hdpi/ic_launcher.webp new file mode 100644 index 0000000..3f5eda1 Binary files /dev/null and b/multipose/app/src/main/res/mipmap-hdpi/ic_launcher.webp differ diff --git a/multipose/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp b/multipose/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp new file mode 100644 index 0000000..8dc82c4 Binary files /dev/null and b/multipose/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp differ diff --git a/multipose/app/src/main/res/mipmap-mdpi/ic_launcher.webp b/multipose/app/src/main/res/mipmap-mdpi/ic_launcher.webp new file mode 100644 index 0000000..f7ce23b Binary files /dev/null and b/multipose/app/src/main/res/mipmap-mdpi/ic_launcher.webp differ diff --git a/multipose/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp b/multipose/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp new file mode 100644 index 0000000..127260b Binary files /dev/null and b/multipose/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp differ diff --git a/multipose/app/src/main/res/mipmap-xhdpi/ic_launcher.webp b/multipose/app/src/main/res/mipmap-xhdpi/ic_launcher.webp new file mode 100644 index 0000000..ba8686b Binary files /dev/null and b/multipose/app/src/main/res/mipmap-xhdpi/ic_launcher.webp differ diff --git a/multipose/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp b/multipose/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp new file mode 100644 index 0000000..d90914f Binary files /dev/null and b/multipose/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp differ diff --git a/multipose/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp b/multipose/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp new file mode 100644 index 0000000..aa2ef11 Binary files /dev/null and b/multipose/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp differ diff --git a/multipose/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp b/multipose/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp new file mode 100644 index 0000000..c14aec7 Binary files /dev/null and b/multipose/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp differ diff --git a/multipose/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp b/multipose/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp new file mode 100644 index 0000000..351aba5 Binary files /dev/null and b/multipose/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp differ diff --git a/multipose/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp b/multipose/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp new file mode 100644 index 0000000..2b07225 Binary files /dev/null and b/multipose/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp differ diff --git a/multipose/build.gradle b/multipose/build.gradle index 88031d6..e9d8fa6 100644 --- a/multipose/build.gradle +++ b/multipose/build.gradle @@ -1,17 +1,21 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { + ext { + kotlin_version = '1.9.24' + } repositories { - jcenter() + mavenCentral() google() } dependencies { - classpath 'com.android.tools.build:gradle:3.5.0' + classpath 'com.android.tools.build:gradle:8.4.0' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } allprojects { repositories { - jcenter() + mavenCentral() google() } } diff --git a/multipose/gradle.properties b/multipose/gradle.properties new file mode 100644 index 0000000..13489a9 --- /dev/null +++ b/multipose/gradle.properties @@ -0,0 +1,3 @@ +android.nonFinalResIds=false +android.nonTransitiveRClass=false +org.gradle.configuration-cache=true \ No newline at end of file diff --git a/multipose/gradle/wrapper/gradle-wrapper.jar b/multipose/gradle/wrapper/gradle-wrapper.jar index f6b961f..7454180 100644 Binary files a/multipose/gradle/wrapper/gradle-wrapper.jar and b/multipose/gradle/wrapper/gradle-wrapper.jar differ diff --git a/multipose/gradle/wrapper/gradle-wrapper.properties b/multipose/gradle/wrapper/gradle-wrapper.properties index b59b08f..11fce01 100644 --- a/multipose/gradle/wrapper/gradle-wrapper.properties +++ b/multipose/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Sun Sep 08 23:09:42 CST 2019 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip diff --git a/multipose/local.properties b/multipose/local.properties deleted file mode 100644 index 07cb350..0000000 --- a/multipose/local.properties +++ /dev/null @@ -1,8 +0,0 @@ -## This file must *NOT* be checked into Version Control Systems, -# as it contains information specific to your local configuration. -# -# Location of the SDK. This is only used by Gradle. -# For customization when using a Version Control System, please read the -# header note. -#Mon Mar 29 09:07:23 CST 2021 -sdk.dir=D\:\\Android diff --git a/singlepose/.gitignore b/singlepose/.gitignore new file mode 100644 index 0000000..16dcd12 --- /dev/null +++ b/singlepose/.gitignore @@ -0,0 +1,33 @@ +# Gradle files +.gradle/ +build/ + +# Local configuration file (sdk path, etc) +local.properties + +# Log/OS Files +*.log + +# Android Studio generated files and folders +captures/ +.externalNativeBuild/ +.cxx/ +*.apk +output.json + +# IntelliJ +*.iml +.idea/ +misc.xml +deploymentTargetDropDown.xml +render.experimental.xml + +# Keystore files +*.jks +*.keystore + +# Google Services (e.g. APIs or Firebase) +google-services.json + +# Android Profiling +*.hprof \ No newline at end of file diff --git a/singlepose/README.md b/singlepose/README.md index e4d2e20..be721dc 100644 --- a/singlepose/README.md +++ b/singlepose/README.md @@ -24,7 +24,7 @@ https://github.com/nihui/opencv-mobile ### step3 * Open this project with Android Studio, build it and enjoy! ## result -![](result.gif) +![](../singlepose.gif) ## reference: https://github.com/nihui/ncnn-android-nanodet https://tfhub.dev/google/movenet/singlepose/lightning/4 diff --git a/singlepose/app/build.gradle b/singlepose/app/build.gradle index 1e629fe..68ca2a6 100644 --- a/singlepose/app/build.gradle +++ b/singlepose/app/build.gradle @@ -1,24 +1,42 @@ -apply plugin: 'com.android.application' +plugins { + id "com.android.application" + id "org.jetbrains.kotlin.android" +} android { - compileSdkVersion 24 - buildToolsVersion "29.0.2" + + compileSdk 34 + + base { + archivesName = "com.tencent.ncnnbodypose" + } defaultConfig { applicationId "com.tencent.ncnnbodypose" - archivesBaseName = "$applicationId" - + targetSdk = 34 minSdkVersion 24 } + buildFeatures { + buildConfig = true + } + externalNativeBuild { cmake { - version "3.10.2" + version "3.22.1" path file('src/main/jni/CMakeLists.txt') } } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + } dependencies { - implementation 'com.android.support:support-v4:24.0.0' + implementation 'com.android.support:support-v4:28.0.0' + } + kotlinOptions { + jvmTarget = '1.8' } + namespace 'com.tencent.ncnnbodypose' } diff --git a/singlepose/app/src/main/AndroidManifest.xml b/singlepose/app/src/main/AndroidManifest.xml index 37a360e..d7e5cb6 100644 --- a/singlepose/app/src/main/AndroidManifest.xml +++ b/singlepose/app/src/main/AndroidManifest.xml @@ -1,15 +1,18 @@ + android:versionCode="1" + android:versionName="1.1"> + - + + android:exported="true"> diff --git a/singlepose/app/src/main/ic_launcher-playstore.png b/singlepose/app/src/main/ic_launcher-playstore.png new file mode 100644 index 0000000..cc6ccfc Binary files /dev/null and b/singlepose/app/src/main/ic_launcher-playstore.png differ diff --git a/singlepose/app/src/main/java/com/tencent/ncnnbodypose/MainActivity.java b/singlepose/app/src/main/java/com/tencent/ncnnbodypose/MainActivity.java deleted file mode 100644 index 21b139c..0000000 --- a/singlepose/app/src/main/java/com/tencent/ncnnbodypose/MainActivity.java +++ /dev/null @@ -1,162 +0,0 @@ -// Tencent is pleased to support the open source community by making ncnn available. -// -// Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. -// -// Licensed under the BSD 3-Clause License (the "License"); you may not use this file except -// in compliance with the License. You may obtain a copy of the License at -// -// https://opensource.org/licenses/BSD-3-Clause -// -// Unless required by applicable law or agreed to in writing, software distributed -// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR -// CONDITIONS OF ANY KIND, either express or implied. See the License for the -// specific language governing permissions and limitations under the License. - -package com.tencent.ncnnbodypose; - -import android.Manifest; -import android.app.Activity; -import android.content.pm.PackageManager; -import android.graphics.PixelFormat; -import android.os.Bundle; -import android.util.Log; -import android.view.Surface; -import android.view.SurfaceHolder; -import android.view.SurfaceView; -import android.view.View; -import android.view.WindowManager; -import android.widget.AdapterView; -import android.widget.Button; -import android.widget.Spinner; - -import android.support.v4.app.ActivityCompat; -import android.support.v4.content.ContextCompat; - -public class MainActivity extends Activity implements SurfaceHolder.Callback -{ - public static final int REQUEST_CAMERA = 100; - - private NcnnBodypose ncnnbodypose = new NcnnBodypose(); - private int facing = 0; - - private Spinner spinnerModel; - private Spinner spinnerCPUGPU; - private int current_model = 0; - private int current_cpugpu = 0; - - private SurfaceView cameraView; - - /** Called when the activity is first created. */ - @Override - public void onCreate(Bundle savedInstanceState) - { - super.onCreate(savedInstanceState); - setContentView(R.layout.main); - - getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); - - cameraView = (SurfaceView) findViewById(R.id.cameraview); - - cameraView.getHolder().setFormat(PixelFormat.RGBA_8888); - cameraView.getHolder().addCallback(this); - - Button buttonSwitchCamera = (Button) findViewById(R.id.buttonSwitchCamera); - buttonSwitchCamera.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View arg0) { - - int new_facing = 1 - facing; - - ncnnbodypose.closeCamera(); - - ncnnbodypose.openCamera(new_facing); - - facing = new_facing; - } - }); - - spinnerModel = (Spinner) findViewById(R.id.spinnerModel); - spinnerModel.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { - @Override - public void onItemSelected(AdapterView arg0, View arg1, int position, long id) - { - if (position != current_model) - { - current_model = position; - reload(); - } - } - - @Override - public void onNothingSelected(AdapterView arg0) - { - } - }); - - spinnerCPUGPU = (Spinner) findViewById(R.id.spinnerCPUGPU); - spinnerCPUGPU.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { - @Override - public void onItemSelected(AdapterView arg0, View arg1, int position, long id) - { - if (position != current_cpugpu) - { - current_cpugpu = position; - reload(); - } - } - - @Override - public void onNothingSelected(AdapterView arg0) - { - } - }); - - reload(); - } - - private void reload() - { - boolean ret_init = ncnnbodypose.loadModel(getAssets(), current_model, current_cpugpu); - if (!ret_init) - { - Log.e("MainActivity", "ncnnbodypose loadModel failed"); - } - } - - @Override - public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) - { - ncnnbodypose.setOutputWindow(holder.getSurface()); - } - - @Override - public void surfaceCreated(SurfaceHolder holder) - { - } - - @Override - public void surfaceDestroyed(SurfaceHolder holder) - { - } - - @Override - public void onResume() - { - super.onResume(); - - if (ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.CAMERA) == PackageManager.PERMISSION_DENIED) - { - ActivityCompat.requestPermissions(this, new String[] {Manifest.permission.CAMERA}, REQUEST_CAMERA); - } - - ncnnbodypose.openCamera(facing); - } - - @Override - public void onPause() - { - super.onPause(); - - ncnnbodypose.closeCamera(); - } -} diff --git a/singlepose/app/src/main/java/com/tencent/ncnnbodypose/MainActivity.kt b/singlepose/app/src/main/java/com/tencent/ncnnbodypose/MainActivity.kt new file mode 100644 index 0000000..5a785d7 --- /dev/null +++ b/singlepose/app/src/main/java/com/tencent/ncnnbodypose/MainActivity.kt @@ -0,0 +1,148 @@ +// Tencent is pleased to support the open source community by making ncnn available. +// +// Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. +// +// Licensed under the BSD 3-Clause License (the "License"); you may not use this file except +// in compliance with the License. You may obtain a copy of the License at +// +// https://opensource.org/licenses/BSD-3-Clause +// +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// specific language governing permissions and limitations under the License. +package com.tencent.ncnnbodypose + +import android.Manifest +import android.app.Activity +import android.content.pm.PackageManager +import android.graphics.PixelFormat +import android.os.Bundle +import android.support.v4.app.ActivityCompat +import android.support.v4.content.ContextCompat +import android.util.Log +import android.view.SurfaceHolder +import android.view.SurfaceView +import android.view.View +import android.view.WindowManager +import android.widget.AdapterView +import android.widget.AdapterView.OnItemSelectedListener +import android.widget.Button +import android.widget.Spinner + +class MainActivity : Activity(), SurfaceHolder.Callback { + private val ncnnbodypose = NcnnBodypose() + private var facing = 0 + + private var spinnerModel: Spinner? = null + private var spinnerCPUGPU: Spinner? = null + private var current_model = 0 + private var current_cpugpu = 0 + + private var cameraView: SurfaceView? = null + + /** Called when the activity is first created. */ + public override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.main) + + window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) + + cameraView = findViewById(R.id.cameraview) as SurfaceView + + cameraView!!.holder.setFormat(PixelFormat.RGBA_8888) + cameraView!!.holder.addCallback(this) + + val buttonSwitchCamera = findViewById(R.id.buttonSwitchCamera) as Button + buttonSwitchCamera.setOnClickListener { + val new_facing = 1 - facing + ncnnbodypose.closeCamera() + + ncnnbodypose.openCamera(new_facing) + facing = new_facing + } + + spinnerModel = findViewById(R.id.spinnerModel) as Spinner + spinnerModel!!.onItemSelectedListener = object : OnItemSelectedListener { + override fun onItemSelected( + arg0: AdapterView<*>?, + arg1: View, + position: Int, + id: Long + ) { + if (position != current_model) { + current_model = position + reload() + } + } + + override fun onNothingSelected(arg0: AdapterView<*>?) { + } + } + + spinnerCPUGPU = findViewById(R.id.spinnerCPUGPU) as Spinner + spinnerCPUGPU!!.onItemSelectedListener = object : OnItemSelectedListener { + override fun onItemSelected( + arg0: AdapterView<*>?, + arg1: View, + position: Int, + id: Long + ) { + if (position != current_cpugpu) { + current_cpugpu = position + reload() + } + } + + override fun onNothingSelected(arg0: AdapterView<*>?) { + } + } + + reload() + } + + private fun reload() { + val ret_init = ncnnbodypose.loadModel(assets, current_model, current_cpugpu) + if (!ret_init) { + Log.e("MainActivity", "ncnnbodypose loadModel failed") + } + } + + override fun surfaceChanged(holder: SurfaceHolder, format: Int, width: Int, height: Int) { + ncnnbodypose.setOutputWindow(holder.surface) + } + + override fun surfaceCreated(holder: SurfaceHolder) { + } + + override fun surfaceDestroyed(holder: SurfaceHolder) { + } + + public override fun onResume() { + super.onResume() + + if (ContextCompat.checkSelfPermission( + applicationContext, + Manifest.permission.CAMERA + ) == PackageManager.PERMISSION_DENIED + ) { + ActivityCompat.requestPermissions( + this, + arrayOf(Manifest.permission.CAMERA), + REQUEST_CAMERA + ) + } + + ncnnbodypose.openCamera(facing) + } + + public override fun onPause() { + super.onPause() + + ncnnbodypose.closeCamera() + } + + companion object { + const val REQUEST_CAMERA: Int = 100 + } +} diff --git a/multipose/app/src/main/java/com/tencent/ncnnbodypose/NcnnBodypose.java b/singlepose/app/src/main/java/com/tencent/ncnnbodypose/NcnnBodypose.kt similarity index 61% rename from multipose/app/src/main/java/com/tencent/ncnnbodypose/NcnnBodypose.java rename to singlepose/app/src/main/java/com/tencent/ncnnbodypose/NcnnBodypose.kt index eaa287e..4ff14d7 100644 --- a/multipose/app/src/main/java/com/tencent/ncnnbodypose/NcnnBodypose.java +++ b/singlepose/app/src/main/java/com/tencent/ncnnbodypose/NcnnBodypose.kt @@ -11,20 +11,20 @@ // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR // CONDITIONS OF ANY KIND, either express or implied. See the License for the // specific language governing permissions and limitations under the License. +package com.tencent.ncnnbodypose -package com.tencent.ncnnbodypose; +import android.content.res.AssetManager +import android.view.Surface -import android.content.res.AssetManager; -import android.view.Surface; +class NcnnBodypose { + external fun loadModel(mgr: AssetManager?, modelid: Int, cpugpu: Int): Boolean + external fun openCamera(facing: Int): Boolean + external fun closeCamera(): Boolean + external fun setOutputWindow(surface: Surface?): Boolean -public class NcnnBodypose -{ - public native boolean loadModel(AssetManager mgr, int modelid, int cpugpu); - public native boolean openCamera(int facing); - public native boolean closeCamera(); - public native boolean setOutputWindow(Surface surface); - - static { - System.loadLibrary("ncnnbodypose"); + companion object { + init { + System.loadLibrary("ncnnbodypose") + } } } diff --git a/singlepose/app/src/main/jni/CMakeLists.txt b/singlepose/app/src/main/jni/CMakeLists.txt index f64255c..4222675 100644 --- a/singlepose/app/src/main/jni/CMakeLists.txt +++ b/singlepose/app/src/main/jni/CMakeLists.txt @@ -2,10 +2,10 @@ project(ncnnbodypose) cmake_minimum_required(VERSION 3.10) -set(OpenCV_DIR ${CMAKE_SOURCE_DIR}/opencv-mobile-4.5.1-android/sdk/native/jni) +set(OpenCV_DIR ${CMAKE_SOURCE_DIR}/opencv-mobile-4.9.0-android/sdk/native/jni) find_package(OpenCV REQUIRED core imgproc) -set(ncnn_DIR ${CMAKE_SOURCE_DIR}/ncnn-20210720-android-vulkan/${ANDROID_ABI}/lib/cmake/ncnn) +set(ncnn_DIR ${CMAKE_SOURCE_DIR}/ncnn-20240410-android-vulkan/${ANDROID_ABI}/lib/cmake/ncnn) find_package(ncnn REQUIRED) add_library(ncnnbodypose SHARED nanodetncnn.cpp nanodet.cpp ndkcamera.cpp) diff --git a/singlepose/app/src/main/res/drawable/ic_launcher_background.xml b/singlepose/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..ca3826a --- /dev/null +++ b/singlepose/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/singlepose/app/src/main/res/drawable/ic_launcher_foreground.xml b/singlepose/app/src/main/res/drawable/ic_launcher_foreground.xml new file mode 100644 index 0000000..da1dcd9 --- /dev/null +++ b/singlepose/app/src/main/res/drawable/ic_launcher_foreground.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/singlepose/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/singlepose/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml new file mode 100644 index 0000000..bbd3e02 --- /dev/null +++ b/singlepose/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/singlepose/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/singlepose/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml new file mode 100644 index 0000000..bbd3e02 --- /dev/null +++ b/singlepose/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/singlepose/app/src/main/res/mipmap-hdpi/ic_launcher.webp b/singlepose/app/src/main/res/mipmap-hdpi/ic_launcher.webp new file mode 100644 index 0000000..3f5eda1 Binary files /dev/null and b/singlepose/app/src/main/res/mipmap-hdpi/ic_launcher.webp differ diff --git a/singlepose/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp b/singlepose/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp new file mode 100644 index 0000000..8dc82c4 Binary files /dev/null and b/singlepose/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp differ diff --git a/singlepose/app/src/main/res/mipmap-mdpi/ic_launcher.webp b/singlepose/app/src/main/res/mipmap-mdpi/ic_launcher.webp new file mode 100644 index 0000000..f7ce23b Binary files /dev/null and b/singlepose/app/src/main/res/mipmap-mdpi/ic_launcher.webp differ diff --git a/singlepose/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp b/singlepose/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp new file mode 100644 index 0000000..127260b Binary files /dev/null and b/singlepose/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp differ diff --git a/singlepose/app/src/main/res/mipmap-xhdpi/ic_launcher.webp b/singlepose/app/src/main/res/mipmap-xhdpi/ic_launcher.webp new file mode 100644 index 0000000..ba8686b Binary files /dev/null and b/singlepose/app/src/main/res/mipmap-xhdpi/ic_launcher.webp differ diff --git a/singlepose/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp b/singlepose/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp new file mode 100644 index 0000000..d90914f Binary files /dev/null and b/singlepose/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp differ diff --git a/singlepose/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp b/singlepose/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp new file mode 100644 index 0000000..aa2ef11 Binary files /dev/null and b/singlepose/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp differ diff --git a/singlepose/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp b/singlepose/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp new file mode 100644 index 0000000..c14aec7 Binary files /dev/null and b/singlepose/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp differ diff --git a/singlepose/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp b/singlepose/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp new file mode 100644 index 0000000..351aba5 Binary files /dev/null and b/singlepose/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp differ diff --git a/singlepose/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp b/singlepose/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp new file mode 100644 index 0000000..2b07225 Binary files /dev/null and b/singlepose/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp differ diff --git a/singlepose/build.gradle b/singlepose/build.gradle index 88031d6..e9d8fa6 100644 --- a/singlepose/build.gradle +++ b/singlepose/build.gradle @@ -1,17 +1,21 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { + ext { + kotlin_version = '1.9.24' + } repositories { - jcenter() + mavenCentral() google() } dependencies { - classpath 'com.android.tools.build:gradle:3.5.0' + classpath 'com.android.tools.build:gradle:8.4.0' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } allprojects { repositories { - jcenter() + mavenCentral() google() } } diff --git a/singlepose/gradle.properties b/singlepose/gradle.properties new file mode 100644 index 0000000..13489a9 --- /dev/null +++ b/singlepose/gradle.properties @@ -0,0 +1,3 @@ +android.nonFinalResIds=false +android.nonTransitiveRClass=false +org.gradle.configuration-cache=true \ No newline at end of file diff --git a/singlepose/gradle/wrapper/gradle-wrapper.jar b/singlepose/gradle/wrapper/gradle-wrapper.jar index f6b961f..7454180 100644 Binary files a/singlepose/gradle/wrapper/gradle-wrapper.jar and b/singlepose/gradle/wrapper/gradle-wrapper.jar differ diff --git a/singlepose/gradle/wrapper/gradle-wrapper.properties b/singlepose/gradle/wrapper/gradle-wrapper.properties index b59b08f..11fce01 100644 --- a/singlepose/gradle/wrapper/gradle-wrapper.properties +++ b/singlepose/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Sun Sep 08 23:09:42 CST 2019 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip diff --git a/singlepose/local.properties b/singlepose/local.properties deleted file mode 100644 index 07cb350..0000000 --- a/singlepose/local.properties +++ /dev/null @@ -1,8 +0,0 @@ -## This file must *NOT* be checked into Version Control Systems, -# as it contains information specific to your local configuration. -# -# Location of the SDK. This is only used by Gradle. -# For customization when using a Version Control System, please read the -# header note. -#Mon Mar 29 09:07:23 CST 2021 -sdk.dir=D\:\\Android diff --git a/singlepose/result.gif b/singlepose/result.gif deleted file mode 100644 index 45052ac..0000000 Binary files a/singlepose/result.gif and /dev/null differ