1

我正在尝试在 Android 中使用 Amazon Web Services Recognition,但我遇到了 RekognitionClient 的问题。当我尝试初始化它时,我得到了错误:

没有 Ljava/lang/String 类型的实例字段 endpointPrefix;在 Lcom/amazonaws/services/rekognition/AmazonRekognitionClient 类中;或其超类(“com.amazonaws.services.rekognition.AmazonRekognitionClient”的声明出现在 /data/app/com.amazonaws.husebnerbot-2/base.apk 中)

我已经尝试了一切,但我找不到我的错误。你能帮助我吗?

private void initializeRekognitionSDK() {
    Log.d(TAG, "Rekognition Client");

    CognitoCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(
            getApplicationContext(),
            appContext.getResources().getString(R.string.identity_id_test),
            Regions.fromName("us-east-1")
    );

    amazonRekognitionClient = new AmazonRekognitionClient(credentialsProvider);
}

谢谢!

4

1 回答 1

0

当我在使用 amazon image rekognition 时,我遇到了同样的问题,我已经通过添加库解决了,坦率地说,不明白添加新库是如何解决这个问题的。这是我添加的库

compile group: 'com.amazonaws', name: 'aws-android-sdk-ddb-mapper', version: '2.6.13'

依赖项

dependencies {
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    compile group: 'com.amazonaws', name: 'aws-android-sdk-ddb-mapper', version: '2.6.13'
    implementation 'com.amazonaws:aws-android-sdk-core:2.2.+'
    implementation files('JarFilePath/AmazonRekognition/lib/aws-android-sdk-rekognition-2.6.9.jar')
}

这是使用 Amazon Rekognition 识别图像的最终代码

  ByteBuffer imageBytes = null;
    try {
        try (InputStream inputStream = new FileInputStream(new File(filePath))) {
            imageBytes = ByteBuffer.wrap(IOUtils.toByteArray(inputStream));
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

    CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(MainActivity.this,
            "YOUR IDENTITY POOL ID",
            Regions.EU_WEST_1);
    ClientConfiguration clientConfiguration = new ClientConfiguration();
    clientConfiguration.setProtocol(Protocol.HTTPS);

    AmazonRekognitionClient rekognitionClient = new AmazonRekognitionClient(credentialsProvider, clientConfiguration);
    rekognitionClient.setEndpoint("https://rekognition.us-east-1.amazonaws.com");
    rekognitionClient.setSignerRegionOverride("us-east-1");

    DetectLabelsRequest request = new DetectLabelsRequest()
            .withImage(new Image()
                    .withBytes(imageBytes))
            .withMaxLabels(10)
            .withMinConfidence(77F);


    DetectLabelsResult result = rekognitionClient.detectLabels(request);
    List<Label> labels = result.getLabels();
    System.out.println("REUSKT   " + result.toString());

    System.out.println("Detected labels for " + photo);
    for (Label label : labels) {
        System.out.println(label.getName() + ": " + label.getConfidence().toString());
    }
于 2018-01-08T12:57:03.733 回答