当我在使用 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());
}