【问题标题】:Is there any way to get firebaesevisionimagelabel data in oncreate?有没有办法在 oncreate 中获取 firebaesevisionimagelabel 数据?
【发布时间】:2019-09-29 14:06:53
【问题描述】:

我正在尝试制作 firebasevisionimagelabel 的副本,但只有它在功能上起作用,然后我无法在 oncreate 中获得任何标签

这是 firebase,用 kotlin 编写。我已将字符串放入 wordpilec 但我无法在 oncreate 中加载它

private fun runDetector (bitmap : Bitmap?){

        val image = FirebaseVisionImage.fromBitmap(bitmap!!)
        val options = FirebaseVisionCloudImageLabelerOptions.Builder()
            .setConfidenceThreshold(0.7f)
            .build()
        val labeler = FirebaseVision.getInstance().getCloudImageLabeler(options)
        labeler.processImage(image)
            .addOnSuccessListener { labels -> processResultfromcloud(labels)

            } 
private fun processResultfromcloud(labels: List<FirebaseVisionImageLabel>) {

        for (label in labels) {
            builder.append(label.text).append(",")

        }
       wordpilec = builder.toString()
        stringtoArray(wordpilec)


    }

我希望字符串应该是相同的,但一个是 null 另一个是完美的。我无法得到完美的一个

【问题讨论】:

    标签: firebase kotlin firebase-mlkit


    【解决方案1】:

    检测器以异步方式运行,我猜您正试图在检测器分配给它的值之前访问 onCreate 中的 wordpilec。您可以尝试将您尝试对字符串执行的操作移至成功侦听器。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-11-02
      • 2022-10-14
      • 2018-02-02
      • 2019-07-07
      • 1970-01-01
      • 1970-01-01
      • 2016-08-14
      相关资源
      最近更新 更多