forked from tensorflow/examples
-
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.
posenet text exposed to open source public git repo.
PiperOrigin-RevId: 258860902
- Loading branch information
1 parent
a89cc88
commit 20465aa
Showing
52 changed files
with
2,206 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,15 @@ | ||
# Tensorflow Lite PoseNet Android Demo | ||
### Overview | ||
This is an on-device camera app that detects the key points of a person in real- | ||
time with the camera activity using the PoseNet model. This app uses the PoseNet | ||
library that handles image processing, invoking the model, and processing output | ||
from the model. | ||
|
||
## Build the demo using Android Studio | ||
### Building | ||
* Type the following command in the terminal to build: | ||
bazel build :posenet_app | ||
* Run the app on an android phone. If the application does not open | ||
automatically, use adb to start the application on device. | ||
Following command can be used from adb command line to start the application: | ||
am start org.tensorflow.lite.examples.posenet/.CameraActivity |
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,37 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
apply plugin: 'kotlin-android' | ||
|
||
apply plugin: 'kotlin-android-extensions' | ||
|
||
android { | ||
compileSdkVersion 29 | ||
buildToolsVersion "29.0.0" | ||
defaultConfig { | ||
applicationId "org.tensorflow.lite.examples.posenet" | ||
minSdkVersion 27 | ||
targetSdkVersion 29 | ||
versionCode 1 | ||
versionName "1.0" | ||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation fileTree(dir: 'libs', include: ['*.jar']) | ||
implementation project(":posenet") | ||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" | ||
implementation 'androidx.appcompat:appcompat:1.0.2' | ||
implementation 'androidx.core:core-ktx:1.0.2' | ||
implementation 'androidx.constraintlayout:constraintlayout:1.1.3' | ||
compile 'org.tensorflow:tensorflow-lite:+' | ||
testImplementation 'junit:junit:4.12' | ||
androidTestImplementation 'androidx.test:runner:1.2.0' | ||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' | ||
} |
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 |
38 changes: 38 additions & 0 deletions
38
.../app/src/androidTest/java/org/tensorflow/lite/examples/posenet/ExampleInstrumentedTest.kt
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,38 @@ | ||
/* | ||
* Copyright 2019 The TensorFlow Authors. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* 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 org.tensorflow.lite.examples.posenet | ||
|
||
import androidx.test.InstrumentationRegistry | ||
import androidx.test.runner.AndroidJUnit4 | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* See [testing documentation](http://d.android.com/tools/testing). | ||
*/ | ||
@RunWith(AndroidJUnit4::class) | ||
class ExampleInstrumentedTest { | ||
@Test | ||
fun useAppContext() { | ||
// Context of the app under test. | ||
val appContext = InstrumentationRegistry.getTargetContext() | ||
assertEquals("org.tensorflow.lite.examples.posenet", appContext.packageName) | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
lite/examples/posenet/android/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,39 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="org.tensorflow.lite.examples.posenet"> | ||
|
||
<uses-permission android:name="android.permission.CAMERA" /> | ||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> | ||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> | ||
|
||
<uses-feature android:name="android.hardware.camera" /> | ||
<uses-feature android:name="android.hardware.camera.autofocus" /> | ||
|
||
<uses-sdk | ||
android:minSdkVersion="21" | ||
android:targetSdkVersion="23" /> | ||
|
||
<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/MaterialTheme"> | ||
|
||
<activity | ||
android:name=".MainActivity" | ||
android:label="@string/app_name" | ||
android:exported="true"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN"/> | ||
<category android:name="android.intent.category.LAUNCHER"/> | ||
</intent-filter> | ||
</activity> | ||
|
||
<activity android:name=".CameraActivity" android:exported="true"> | ||
</activity> | ||
|
||
</application> | ||
|
||
</manifest> |
67 changes: 67 additions & 0 deletions
67
...enet/android/app/src/main/java/org/tensorflow/lite/examples/posenet/AutoFitTextureView.kt
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,67 @@ | ||
/* | ||
* Copyright 2019 The TensorFlow Authors. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* 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 org.tensorflow.lite.examples.posenet | ||
|
||
import android.content.Context | ||
import android.util.AttributeSet | ||
import android.view.TextureView | ||
import android.view.View | ||
|
||
/** | ||
* A [TextureView] that can be adjusted to a specified aspect ratio. | ||
*/ | ||
class AutoFitTextureView @JvmOverloads constructor( | ||
context: Context, | ||
attrs: AttributeSet? = null, | ||
defStyle: Int = 0 | ||
) : TextureView(context, attrs, defStyle) { | ||
|
||
private var ratioWidth = 0 | ||
private var ratioHeight = 0 | ||
|
||
/** | ||
* Sets the aspect ratio for this view. The size of the view will be measured based on the ratio | ||
* calculated from the parameters. Note that the actual sizes of parameters don't matter, that | ||
* is, calling setAspectRatio(2, 3) and setAspectRatio(4, 6) make the same result. | ||
* | ||
* @param width Relative horizontal size | ||
* @param height Relative vertical size | ||
*/ | ||
fun setAspectRatio(width: Int, height: Int) { | ||
if (width < 0 || height < 0) { | ||
throw IllegalArgumentException("Size cannot be negative.") | ||
} | ||
ratioWidth = width | ||
ratioHeight = height | ||
requestLayout() | ||
} | ||
|
||
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { | ||
super.onMeasure(widthMeasureSpec, heightMeasureSpec) | ||
val width = View.MeasureSpec.getSize(widthMeasureSpec) | ||
val height = View.MeasureSpec.getSize(heightMeasureSpec) | ||
if (ratioWidth == 0 || ratioHeight == 0) { | ||
setMeasuredDimension(width, height) | ||
} else { | ||
if (width < height * ratioWidth / ratioHeight) { | ||
setMeasuredDimension(width, width * ratioHeight / ratioWidth) | ||
} else { | ||
setMeasuredDimension(height * ratioWidth / ratioHeight, height) | ||
} | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
.../posenet/android/app/src/main/java/org/tensorflow/lite/examples/posenet/CameraActivity.kt
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 @@ | ||
/* | ||
* Copyright 2019 The TensorFlow Authors. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* 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 org.tensorflow.lite.examples.posenet | ||
|
||
import android.os.Bundle | ||
import android.support.v7.app.AppCompatActivity | ||
|
||
class CameraActivity : AppCompatActivity() { | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_camera) | ||
savedInstanceState ?: supportFragmentManager.beginTransaction() | ||
.replace(R.id.container, CameraConnectionFragment.newInstance()) | ||
.commit() | ||
} | ||
} |
Oops, something went wrong.