Skip to content

Commit

Permalink
#16 ML Kit 쓰기 전에 커밋..
Browse files Browse the repository at this point in the history
  • Loading branch information
comye1 committed Mar 9, 2022
1 parent 056b5b2 commit 548b9e6
Showing 1 changed file with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.util.Log
import androidx.camera.core.ImageAnalysis
import androidx.camera.core.ImageProxy
import com.comye1.dontsleepdriver.ml.SleepModel
import com.google.mlkit.vision.common.InputImage
import org.tensorflow.lite.DataType
import org.tensorflow.lite.support.image.ImageProcessor
import org.tensorflow.lite.support.image.TensorImage
Expand All @@ -25,19 +26,23 @@ class SleepAnalyzer(context: Context, private val listener: (String) -> Unit) :
override fun analyze(image: ImageProxy) {
Log.d("SleepAnalyzer", "image : ${image.image.toString()}")
if (image.image != null) {

// val input = TensorBuffer.createFixedSize(intArrayOf(1,320,320,3), DataType.FLOAT32)
// input.loadBuffer(TensorImage.fromBitmap(image.image!!.toBitmap()).buffer)


var tfImage = TensorImage(DataType.FLOAT32)
tfImage.load(image.image!!.toBitmap())
tfImage = imageProcessor.process(tfImage) // image resize
Log.d("SleepAnalyzer", tfImage.tensorBuffer.shape.toString())
// Log.d("SleepAnalyzer", tfImage.tensorBuffer.shape.toString())

// val output = model.process(tfImage)

// Log.d("SleepAnalyzer", "model : ${model is SleepModel}")
val output = model.process(tfImage.tensorBuffer)
// Log.d("SleepAnalyzer", output.toString())

Log.d("SleepAnalyzer", tfImage.toString())
// Log.d("SleepAnalyzer", output.toString())

listener(output.toString())
// listener(output.toString())

// listener(tfImage.tensorBuffer.intArray.size.toString())
image.close()
Expand Down Expand Up @@ -66,7 +71,7 @@ class SleepAnalyzer(context: Context, private val listener: (String) -> Unit) :
// image resize processor
private val imageProcessor =
ImageProcessor.Builder()
.add(ResizeOp(640, 640, ResizeOp.ResizeMethod.BILINEAR))
.add(ResizeOp(320, 320, ResizeOp.ResizeMethod.BILINEAR))
.build()
}

0 comments on commit 548b9e6

Please sign in to comment.