Приложение не отображает никаких результатов на экране, однако информация отображается в журнале.
Вот зависимости проекта:
implementation 'com.google.firebase:firebase-ml-vision:23.0.0'
implementation 'com.google.firebase:firebase-ml-vision-image-label-model:18.0.0'
implementation 'com.wonderkiln:camerakit:0.13.1'
И вот код:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_label_image)
requestedOrientation=(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)
btn_label.setOnClickListener {
labelCamera_view.start()
labelCamera_view.captureImage()
}
labelCamera_view.addCameraKitListener(object :CameraKitEventListener{
override fun onVideo(p0: CameraKitVideo?) {
}
override fun onEvent(p0: CameraKitEvent?) {
}
override fun onImage(p0: CameraKitImage?) {
var bitmap=p0!!.bitmap
bitmap= Bitmap.createScaledBitmap(bitmap,labelCamera_view.width,labelCamera_view.height,false)
labelCamera_view.stop()
runLabel(bitmap)
}
override fun onError(p0: CameraKitError?) {
}
})
}
private fun runLabel(bitmap: Bitmap?) {
val image=FirebaseVisionImage.fromBitmap(bitmap!!)
val options=FirebaseVisionOnDeviceImageLabelerOptions.Builder()
.setConfidenceThreshold(0.8f)
.build()
val detector=FirebaseVision.getInstance().getOnDeviceImageLabeler(options)
detector.processImage(image)
.addOnFailureListener { e -> Log.e("EDMTERROR",e.message) }
.addOnSuccessListener { result-> processResultFromDevice(result) }
}
private fun processResultFromDevice(result: List<FirebaseVisionImageLabel>) {
for (label in result) {
val text = label.text
val entityId = label.entityId
val confidence = label.confidence
Toast.makeText(this, "Success", Toast.LENGTH_SHORT).show()
Log.i("SAFE", "success")
print("result : $text ")
}
}
}