Skip to content

Commit

Permalink
[#9] FPS 화면 출력 & 학습 완료된 모델 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
zozero94 committed Jan 11, 2021
1 parent 2be8dce commit 7ccfcf0
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 27 deletions.
Binary file not shown.
Binary file not shown.
Binary file modified MyApplication/app/src/main/assets/mobile_gpu.binarypb
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -40,39 +40,35 @@ class MediaPipeActivity : BaseActivity<ActivityMediapipeBinding>() {
}
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()
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Int> = _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()
}
}
28 changes: 18 additions & 10 deletions MyApplication/app/src/main/res/layout/activity_mediapipe.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">

<data>

Expand All @@ -9,6 +10,7 @@
type="com.example.myapplication.ui.mediapipe.MediaPipeViewModel" />
</data>


<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
Expand All @@ -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" />

<TextView
android:id="@+id/no_camera_access_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Text" />
</FrameLayout>
<TextView
android:id="@+id/fps"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:textColor="@color/black"
android:textSize="30sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0"
app:layout_constraintStart_toStartOf="parent"
tools:text="30" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>

0 comments on commit 7ccfcf0

Please sign in to comment.