Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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