Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

안드로이드 간단한 예제 추가 #5

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
/captures
.externalNativeBuild
.cxx
.idea
35 changes: 0 additions & 35 deletions .idea/$CACHE_FILE$

This file was deleted.

1 change: 0 additions & 1 deletion .idea/.name

This file was deleted.

122 changes: 0 additions & 122 deletions .idea/codeStyles/Project.xml

This file was deleted.

5 changes: 0 additions & 5 deletions .idea/codeStyles/codeStyleConfig.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/dictionaries

This file was deleted.

23 changes: 0 additions & 23 deletions .idea/gradle.xml

This file was deleted.

25 changes: 0 additions & 25 deletions .idea/jarRepositories.xml

This file was deleted.

9 changes: 0 additions & 9 deletions .idea/misc.xml

This file was deleted.

12 changes: 0 additions & 12 deletions .idea/runConfigurations.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Juhyun Song <[email protected]>
2 changes: 1 addition & 1 deletion LISENCE → LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2019 The TensorFlow Authors. All rights reserved.
Copyright 2020 The TLdroid Authors. All rights reserved.

Apache License
Version 2.0, January 2004
Expand Down
12 changes: 12 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ android {
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
ndk {
abiFilters 'armeabi-v7a', 'arm64-v8a'
}
}

buildTypes {
Expand All @@ -22,9 +25,18 @@ android {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

aaptOptions {
noCompress "tflite"
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
}

dependencies {
implementation project(path: ':classification')
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.0'
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mercy.tl_droid">

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
Expand Down
Binary file not shown.
7 changes: 7 additions & 0 deletions app/src/main/assets/mercy_vision_v1_1.0_48_info.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
anger
disgust/contempt
afraid
happiness
sadness
surprise
neutral
22 changes: 21 additions & 1 deletion app/src/main/java/com/mercy/tl_droid/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
package com.mercy.tl_droid

import androidx.appcompat.app.AppCompatActivity
import android.graphics.drawable.BitmapDrawable
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.mercy.classification.Classifier
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {

private var mClassifier: Classifier? = null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onCreate 메소드에서 초기화되는 property이므로 lateinit var 로 선언해도 괜찮을 것 같은데 어떻게 생각하시나요?


override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

mClassifier = Classifier.create(this, Classifier.Device.CPU, 1)

val drawable = resources.getDrawable(R.drawable.lenna, null)
val bitmap = (drawable as BitmapDrawable).bitmap

val results = mClassifier?.recognizeImage(bitmap)
tv_result.text = results.toString()
}

override fun onStop() {
super.onStop()

mClassifier?.close()
}
}
Binary file added app/src/main/res/drawable/lenna.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 12 additions & 2 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,23 @@
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
<ImageView
android:id="@+id/iv_sample"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:src="@drawable/lenna"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/tv_result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/iv_sample" />

</androidx.constraintlayout.widget.ConstraintLayout>
Loading