Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kustraslawomir/734948e95edda3368425d13cceb3dcc9 to your computer and use it in GitHub Desktop.
Save kustraslawomir/734948e95edda3368425d13cceb3dcc9 to your computer and use it in GitHub Desktop.
private fun initializeDetector(modelFile: File, labels: List<String>) {
val detector = TensorObjectDetector.create(
interpreter = Interpreter(modelFile),
labels = labels)
cameraView.addFrameProcessor { frame ->
when (frame.dataClass) {
ByteArray::class.java -> {
val bitmap = BitmapUtils.getBitmapFromFrame(
frame = frame,
bitmapSize = detector.bitmapSize)
processResults(detector.recognizeImage(bitmap))
}
}
}
}
private fun processResults(results: List<Recognition>) {
for (result in results) {
TimberLog.d("Recognized: ${result.title} with confidence: ${result.confidence}")
if (result.confidence >= minimumConfidence) {
getNavigationActivity().runOnUiThread {
gamePlayViewModel.showSuccessDialog("Recognized: ${result.title} with confidence: ${result.confidence}")
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment