diff --git a/MyApplication/app/src/main/assets/BiSeNetV2.tflite b/MyApplication/app/src/main/assets/BiSeNetV2.tflite new file mode 100644 index 0000000..dec62d8 Binary files /dev/null and b/MyApplication/app/src/main/assets/BiSeNetV2.tflite differ diff --git a/MyApplication/app/src/main/assets/BiSeNetV2_r1.0_256x160_matting_human+portrait+datatang_body_focal_hvd_step60258_mIOU_0.960076_wmwvwvvvzd1z.tflite b/MyApplication/app/src/main/assets/BiSeNetV2_r1.0_256x160_matting_human+portrait+datatang_body_focal_hvd_step60258_mIOU_0.960076_wmwvwvvvzd1z.tflite new file mode 100644 index 0000000..05f3853 Binary files /dev/null and b/MyApplication/app/src/main/assets/BiSeNetV2_r1.0_256x160_matting_human+portrait+datatang_body_focal_hvd_step60258_mIOU_0.960076_wmwvwvvvzd1z.tflite differ diff --git a/MyApplication/app/src/main/assets/mobile_gpu.binarypb b/MyApplication/app/src/main/assets/mobile_gpu.binarypb index c7a7b13..e38337c 100755 Binary files a/MyApplication/app/src/main/assets/mobile_gpu.binarypb and b/MyApplication/app/src/main/assets/mobile_gpu.binarypb differ diff --git a/MyApplication/app/src/main/java/com/example/myapplication/ui/mediapipe/MediaPipeActivity.kt b/MyApplication/app/src/main/java/com/example/myapplication/ui/mediapipe/MediaPipeActivity.kt index 92343c1..cc1872f 100644 --- a/MyApplication/app/src/main/java/com/example/myapplication/ui/mediapipe/MediaPipeActivity.kt +++ b/MyApplication/app/src/main/java/com/example/myapplication/ui/mediapipe/MediaPipeActivity.kt @@ -4,9 +4,9 @@ import android.content.Context import android.content.Intent import android.graphics.SurfaceTexture import android.os.Bundle -import android.util.Log import android.view.SurfaceHolder import android.view.View +import androidx.activity.viewModels import com.example.myapplication.R import com.example.myapplication.databinding.ActivityMediapipeBinding import com.example.myapplication.ui.base.BaseActivity @@ -40,39 +40,35 @@ class MediaPipeActivity : BaseActivity() { } private val converter: ExternalTextureConverter by lazy { ExternalTextureConverter(eglManager.context) } - private val timer = Timer() - private var interval = 0 - private var framesPerSecond = 0 + private val mediaPipeViewModel: MediaPipeViewModel by viewModels() init { System.loadLibrary("mediapipe_jni") System.loadLibrary("opencv_java3") - checkFPS() } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) + setupPreviewDisplayView() + binding.fps.bringToFront() + mediaPipeViewModel.checkFPS() + mediaPipeViewModel.getFPS().observe(this) { + binding.fps.text = it.toString() + } + AndroidAssetUtil.initializeNativeAssetManager(this) + processor.videoSurfaceOutput.setFlipY(FLIP_FRAMES_VERTICALLY) processor.graph.addPacketCallback(OUTPUT_VIDEO_STREAM_NAME) { - interval++ - Log.i("fps : ", framesPerSecond.toString()) + mediaPipeViewModel.increaseInterval() } + PermissionHelper.checkAndRequestCameraPermissions(this) } - private fun checkFPS() { - timer.scheduleAtFixedRate(object : TimerTask() { - override fun run() { - framesPerSecond = interval - interval = 0 - } - - }, 0, 1000) - } override fun onResume() { super.onResume() diff --git a/MyApplication/app/src/main/java/com/example/myapplication/ui/mediapipe/MediaPipeViewModel.kt b/MyApplication/app/src/main/java/com/example/myapplication/ui/mediapipe/MediaPipeViewModel.kt index 9e67b23..5755fd3 100644 --- a/MyApplication/app/src/main/java/com/example/myapplication/ui/mediapipe/MediaPipeViewModel.kt +++ b/MyApplication/app/src/main/java/com/example/myapplication/ui/mediapipe/MediaPipeViewModel.kt @@ -1,7 +1,36 @@ package com.example.myapplication.ui.mediapipe +import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel +import java.util.* -class MediaPipeViewModel:ViewModel() { +class MediaPipeViewModel : ViewModel() { + private var framesPerSecond = 0 + private val timer = Timer() + private var interval = 0 + private val _fps = MutableLiveData(0) + fun getFPS(): LiveData = _fps + + + fun checkFPS() { + timer.scheduleAtFixedRate(object : TimerTask() { + override fun run() { + framesPerSecond = interval + interval = 0 + } + + }, 0, 1000) + } + + fun increaseInterval() { + interval++ + _fps.postValue(framesPerSecond) + } + + override fun onCleared() { + super.onCleared() + timer.cancel() + } } \ No newline at end of file diff --git a/MyApplication/app/src/main/res/layout/activity_mediapipe.xml b/MyApplication/app/src/main/res/layout/activity_mediapipe.xml index d6b4944..ee7b5bd 100644 --- a/MyApplication/app/src/main/res/layout/activity_mediapipe.xml +++ b/MyApplication/app/src/main/res/layout/activity_mediapipe.xml @@ -1,6 +1,7 @@ + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools"> @@ -9,6 +10,7 @@ type="com.example.myapplication.ui.mediapipe.MediaPipeViewModel" /> + @@ -17,17 +19,23 @@ android:id="@+id/preview_display_layout" android:layout_width="0dp" android:layout_height="0dp" - app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintBottom_toTopOf="@+id/fps" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toTopOf="parent"> + app:layout_constraintTop_toTopOf="parent" /> - - + \ No newline at end of file