Created
August 19, 2020 10:24
-
-
Save kustraslawomir/734948e95edda3368425d13cceb3dcc9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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