2

当我尝试从 imagelabeler 调用 processImage() 时出现以下错误如他们的文档中所述,我已经添加了依赖项,但它似乎仍然没有工作。

错误

E/flutter ( 5149): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: PlatformException(imageLabelerError, No model is bundled. Please check your app setup to includefirebase-ml-vision-image-label-model dependency., null, null)
E/flutter ( 5149): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:582:7)
E/flutter ( 5149): #1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:159:18)
E/flutter ( 5149): <asynchronous suspension>
E/flutter ( 5149): #2      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:332:12)
E/flutter ( 5149): #3      MethodChannel.invokeListMethod (package:flutter/src/services/platform_channel.dart:345:41)
E/flutter ( 5149): #4      ImageLabeler.processImage (package:firebase_ml_vision/src/image_labeler.dart:53:38)
E/flutter ( 5149): #5      _DetailScreenState._labelScanner (package:flutter_ml_practice/DetailScreen.dart:48:51)
E/flutter ( 5149): #6      _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:993:19)
E/flutter ( 5149): #7      _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:1111:38)
E/flutter ( 5149): #8      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:183:24)
E/flutter ( 5149): #9      TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:598:11)
E/flutter ( 5149): #10     BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:287:5)
E/flutter ( 5149): #11     BaseTapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:222:7)
E/flutter ( 5149): #12     PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:476:9)
E/flutter ( 5149): #13     PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:77:12)
E/flutter ( 5149): #14     PointerRouter._dispatchEventToRoutes.<anonymous closure> (package:flutter/src/gestures/pointer_router.dart:122:9)
E/flutter ( 5149): #15     _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:377:8)
E/flutter ( 5149): #16     PointerRouter._dispatchEventToRoutes (package:flutter/src/gestures/pointer_router.dart:120:18)
E/flutter ( 5149): #17     PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:106:7)
E/flutter ( 5149): #18     GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:358:19)
E/flutter ( 5149): #19     GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:338:22)
E/flutter ( 5149): #20     RendererBinding.dispatchEvent (package:flutter/src/rendering/binding.dart:267:11)
E/flutter ( 5149): #21     GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:295:7)
E/flutter ( 5149): #22     GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:240:7)
E/flutter ( 5149): #23     GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:213:7)
E/flutter ( 5149): #24     _rootRunUnary (dart:async/zone.dart:1206:13)
E/flutter ( 5149): #25     _CustomZone.runUnary (dart:async/zone.dart:1100:19)
E/flutter ( 5149): #26     _CustomZone.runUnaryGuarded (dart:async/zone.dart:1005:7)
E/flutter ( 5149): #27     _invoke1 (dart:ui/hooks.dart:265:10)
E/flutter ( 5149): #28     _dispatchPointerDataPacket (dart:ui/hooks.dart:174:5)

我使用图像贴标机的功能。

Future<void> _labelScanner() async{
    result='';
    FirebaseVisionImage visionImage = FirebaseVisionImage.fromFile(_pickedImage);
    ImageLabeler labeler = FirebaseVision.instance.imageLabeler();
    final List<ImageLabel> labels = await labeler.processImage(visionImage);
    for(ImageLabel label in labels){
      print(label.toString());
    }
  }

我的应用级别 build.gradle

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
apply plugin: 'com.google.gms.google-services'


android {
    compileSdkVersion 29

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.b.biradar.flutter_ml_practice"
        minSdkVersion 16
        targetSdkVersion 29
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }

        dependencies {
            implementation platform('com.google.firebase:firebase-bom:26.1.0')
            implementation 'com.google.firebase:firebase-ml-vision'
            implementation 'com.google.mlkit:image-labeling:17.0.0'
            implementation 'com.google.android.gms:play-services-vision:20.1.1'
            implementation 'com.google.android.gms:play-services-vision-common:19.1.1'
            implementation 'com.google.android.gms:play-services-vision-image-label:18.0.5'
            implementation 'com.google.android.gms:play-services-vision-face-contour-internal:16.0.2'
        }


    }
}

flutter {
    source '../..'
}

项目级 build.gradle 文件正如他们的官方文档链接中提到的那样。我在 buildscript 和依赖部分都添加了 maven 存储库。

buildscript {
    repositories {
        google()
        jcenter()
        maven{
            url 'https://maven.google.com/'
            name 'Google'
        }
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:4.0.2'
        classpath 'com.google.gms:google-services:4.3.4'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven{
            url 'https://maven.google.com/'
            name 'Google'
        }
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
4

0 回答 0