最近、Androidアプリの開発に興味を持ち始めた初心者です。
入門書を一通り読み終えた程度の理解です。
TensorFlowLighのサンプルプログラムを見ていたところ、プログラムの流れが全く理解できず、よろしければ解説をお願いできないでしょうか。
URL : https://github.com/tensorflow/examples.git
このアプリの機能としては、アプリを立ち上げるとカメラが起動し、オブジェクト検出を行い、ラベル付けされたオブジェクトが枠で囲われて表示されるというものです。
MainActivityと同じディレクトリに"...fragment.kt"と名前のあるファイルが2つあり、その中でオブジェクト検出等の処理を行っている訳ですが、そのプログラムとMainActivityがどのように関連付いているのかが理解できません。
解説をお願いできないでしょうか。
宜しくお願いいたします。
MainActivity.kt
/* package org.tensorflow.lite.examples.objectdetection import android.os.Build import android.os.Bundle import android.widget.TextView import androidx.appcompat.app.AppCompatActivity import org.opencv.android.OpenCVLoader import org.tensorflow.lite.examples.objectdetection.databinding.ActivityMainBinding class MainActivity : AppCompatActivity() { private lateinit var activityMainBinding: ActivityMainBinding override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) activityMainBinding = ActivityMainBinding.inflate(layoutInflater) setContentView(activityMainBinding.root) } override fun onBackPressed() { if (Build.VERSION.SDK_INT == Build.VERSION_CODES.Q) { // Workaround for Android Q memory leak issue in IRequestFinishCallback$Stub. // (https://issuetracker.google.com/issues/139738913) finishAfterTransition() } else { super.onBackPressed() } } }
activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto" android:background="@android:color/transparent" android:layout_width="match_parent" android:layout_height="match_parent"> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <androidx.fragment.app.FragmentContainerView android:id="@+id/fragment_container" android:name="androidx.navigation.fragment.NavHostFragment" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/transparent" android:keepScreenOn="true" app:defaultNavHost="true" app:navGraph="@navigation/nav_graph" android:layout_marginTop="?android:attr/actionBarSize" tools:context=".MainActivity"/> <androidx.appcompat.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:layout_alignParentTop="true" android:background="@color/toolbar_background"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/tfl_logo" /> </androidx.appcompat.widget.Toolbar> </RelativeLayout> </androidx.coordinatorlayout.widget.CoordinatorLayout>
navigation
<?xml version="1.0" encoding="utf-8"?> <navigation xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/nav_graph" app:startDestination="@id/permissions_fragment"> <fragment android:id="@+id/permissions_fragment" android:name="org.tensorflow.lite.examples.objectdetection.fragments.PermissionsFragment" android:label="PermissionsFragment" > <action android:id="@+id/action_permissions_to_camera" app:destination="@id/camera_fragment" app:popUpTo="@id/permissions_fragment" app:popUpToInclusive="true" /> </fragment> <fragment android:id="@+id/camera_fragment" android:name="org.tensorflow.lite.examples.objectdetection.fragments.CameraFragment" android:label="CameraFragment" > <action android:id="@+id/action_camera_to_permissions" app:destination="@id/permissions_fragment" app:popUpTo="@id/camera_fragment" app:popUpToInclusive="true"/> </fragment> </navigation>

0 コメント