I want to use image tagging and text recognition at the same time in my application. I have the following:
fun initAnalyzer(cameraExecutor: Executor) {
imageAnalyzer = ImageAnalysis.Builder().build().also { imageAnalysis ->
imageAnalysis.setAnalyzer(
cameraExecutor,
ImageMLAnalyzer { image, imageProxy, machineLearningUtils ->
textClassifier?.processImageWithText(image,
onSuccess = { result ->
val resultString = processLineText(result)
if (TextRecognitionClassifier.NORESULT !=
resultString &&
!isProcessingImage) {
processAnalyzedResult(resultString)
} else {
imageClassifier?.processImage(image,
onSuccess = { labelProbList ->
val labelResult = processResult(labelProbList)
if (ImageClassifier.NORESULT != labelResult &&
!isProcessingImage) {
openWebView(labelResult)
}
machineLearningUtils.analyzing(false)
imageProxy.close()
}, onFailure = {
machineLearningUtils.analyzing(false)
imageProxy.close()
})
}
machineLearningUtils.analyzing(false)
imageProxy.close()
}, onFailure = {
machineLearningUtils.analyzing(false)
imageProxy.close()
})
})
}
}
The problem I have is that, firstly, this way I am not really using them at the same time, and secondly that I get an error when I enter the image detector that says:
com.google.firebase.ml.common.FirebaseMLException: No image data found.
I answer myself, I have solved it with a Boolean:
It has worked for me, as it analyses until it finds something that "works for it" and uses it, if you can think of a better way, I'm listening.