gpt4 book ai didi

android - 将用于人脸匹配的图像发送到 Android 上的 AWS Rekognition 时出错

转载 作者:行者123 更新时间:2023-11-29 23:07:52 27 4
gpt4 key购买 nike

我在将图像发送到 AWS Rekognition 进行识别时遇到错误。这是我使用的代码:

        val byteBuffer = ByteBuffer.allocate(facePicture.byteCount)
facePicture.copyPixelsToBuffer(byteBuffer)
val image = Image().withBytes(byteBuffer)

val searchFacesByImageResult = rekognitionClient.searchFacesByImage(
SearchFacesByImageRequest()
.withCollectionId(collectionId)
.withImage(image)
.withMaxFaces(1)
.withFaceMatchThreshold(88F)
)

这是一个错误:

com.amazonaws.AmazonServiceException: 1 validation error detected: Value 'java.nio.HeapByteBuffer[pos=0 lim=0 cap=0]' at 'image.bytes' failed to satisfy constraint: Member must have length greater than or equal to 1 (Service: AmazonRekognition; Status Code: 400; Error Code: ValidationException; Request ID: 70a3f05c-8166-11e9-a1cb-fbae8cf4359b)
at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:730)
at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:405)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:212)
at com.amazonaws.services.rekognition.AmazonRekognitionClient.invoke(AmazonRekognitionClient.java:3006)
at com.amazonaws.services.rekognition.AmazonRekognitionClient.searchFacesByImage(AmazonRekognitionClient.java:238

异常看起来像 ByteBuffer 是空的,我已经调试并检查了 ByteBuffer 是有效的并且不为空

最佳答案

看来问题出在图像格式上,我使用的是 RAW BMP 格式,这是内存中表示位图的格式。但是亚马逊不支持这种格式,文档中有说明here

Amazon Rekognition supports the PNG and JPEG image formats. That is, the images you provide as input to various API operations, such as DetectLabels and IndexFaces must be in one of the supported formats.

为了解决这个问题,我将我的代码更改为:

     val stream = ByteArrayOutputStream()
facePicture.compress(Bitmap.CompressFormat.PNG, 100, stream)
val byteBuffer = ByteBuffer.wrap(stream.toByteArray())
val image = Image().withBytes(byteBuffer)

关于android - 将用于人脸匹配的图像发送到 Android 上的 AWS Rekognition 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56346851/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com