iOS/Android 应用程序索引的面孔未被 Android/iOS 应用程序检测到 - AWS Rekognition

Faces indexed by iOS/Android app are not detected by Android/iOS App - AWS Rekognition

所以我长期以来一直致力于开发一种产品(Android,然后是 iOS),该产品为使用 AWS Rekognition 的人的面孔编制索引,稍后再次扫描时,它识别他们。 当我从 Android 设备索引一张脸然后尝试使用 Android 设备搜索它时,它工作得很好。但是,如果我稍后尝试在 iOS 应用程序上搜索它,它不会找到它。如果我反过来,结果也是一样的。使用 iOS 索引,使用 Android 搜索,未找到。 在两个设备上进行索引和搜索时,集合 ID 相同。我无法弄清楚如何在其他设备上找不到由一种 OS 类型、相同区域、相同集合索引的面孔。

如果这里有人可以帮助我解决这个问题,请帮忙。我会非常感谢。

更新 1:我在 iOS 和 android 应用程序上都调用了 "listCollections" 函数。他们都显示不同的集合列表。这就是问题所在。但我不明白我们为什么会这样。两者的身份池和区域相同。

这是我的 Android 访问 Rekognition 的代码:

mCredentialsProvider = new CognitoCachingCredentialsProvider(
        mContext,
        "us-east-2:xbxfxexf-x5x5-xax7-x9xf-x5x0xexfx1xb", // Identity pool ID
        Regions.US_EAST_2 // Region
);

mUUID = UUID.randomUUID().toString().replace("-", "");

mAmazonS3Client = new AmazonS3Client(mCredentialsProvider);
mAmazonS3Client.setRegion(Region.getRegion(Regions.US_EAST_2));
mAmazonRekognitionClient = new AmazonRekognitionClient(mCredentialsProvider);

if(!mAmazonS3Client.doesBucketExist(mFacesBucket)) {
    mAmazonS3Client.createBucket(mFacesBucket);
}

Log.i(TAG, "Uploading image to S3 Bucket");
mAmazonS3Client.putObject(mFacesBucket, getS3ObjectName(), new File(data[0].toString()));
Log.i(TAG, "Image Uploaded");

Image image = new Image();
try {
    image.setBytes(ByteBuffer.wrap(Files.toByteArray(new File(data[0].toString()))));
} catch (IOException e) {
    e.printStackTrace();
}

Log.i(TAG, "Indexing image");
IndexFacesRequest indexFacesRequest =new IndexFacesRequest()
        .withCollectionId(mFacesCollection)
        .withImage(image)
        .withExternalImageId(mUUID)
        .withDetectionAttributes("ALL");

mAmazonRekognitionClient.indexFaces(indexFacesRequest);

这是我的 iOS 访问 Rekognition 的代码:

func uploadToCollection(img: UIImage)
    {
        let myIdentityPoolId="us-east-2:xbxfxexf-x5x5-xax7-x9xf-x5x0xexfx1xb"

        let credentialsProvider = AWSCognitoCredentialsProvider(regionType: .USEast2, identityPoolId: myIdentityPoolId)
        //store photo in s3()
        let configuration = AWSServiceConfiguration(region: .USEast2, credentialsProvider: credentialsProvider)

        AWSServiceManager.default().defaultServiceConfiguration = configuration
        rekognitionClient = AWSRekognition.default()

        guard let request = AWSRekognitionIndexFacesRequest() else
        {
            puts("Unable to initialize AWSRekognitionindexFaceRequest.")
            return
        }
        var go=false
        request.collectionId = "i_faces" + self.firebaseID.lowercased() //here iosCollection will be replaced by firebase Current UserID
        request.detectionAttributes = ["ALL", "DEFAULT"]
        request.externalImageId = self.UUID //this should be mUUID, passed as parameter to this function
        let sourceImage = img
        let image = AWSRekognitionImage()
        image!.bytes = sourceImage.jpegData(compressionQuality: 0.7)
        request.image = image
        self.rekognitionClient.indexFaces(request) { (response:AWSRekognitionIndexFacesResponse?, error:Error?) in
            if error == nil
            {
                print("Upload to Collection Complete")
            }
            go=true
            return
        }
        while(go==false){}
    }

创建一个集合并将图像添加到该集合并创建一个索引。我怀疑您的设置和代码中没有什么东西。

1) iOS 和 Android

中使用的身份池 ID、AWS 区域

2)使用的集合名称(注意集合名称中使用的分隔符)

Android:

CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(appContext, "MyPoolID", Regions.US_EAST_1);

public void searchFacesByImage() {
        Image source = new Image().withS3Object(new S3Object().withBucket("us-east-1-bucket").withName("ms.jpg"));
        Image ms2 = new Image().withS3Object(new S3Object().withBucket("us-east-1-bucket").withName("ms-2.jpg"));
        Image ms3 = new Image().withS3Object(new S3Object().withBucket("us-east-1-bucket").withName("ms-3.jpg"));
        Image ms4 = new Image().withS3Object(new S3Object().withBucket("us-east-1-bucket").withName("ms-4.jpg"));

        String collectionId = "MyCollectionID";
        AmazonRekognitionClient client = new AmazonRekognitionClient(credentialsProvider);

        try {
            System.out.println("Creating collection: " + collectionId );
            CreateCollectionRequest request = new CreateCollectionRequest().withCollectionId(collectionId);
            CreateCollectionResult createCollectionResult = client.createCollection(request);
            System.out.println("CollectionArn : " + createCollectionResult.getCollectionArn());
            System.out.println("Status code : " + createCollectionResult.getStatusCode().toString());
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        IndexFacesRequest indexFacesRequest = new IndexFacesRequest();
        indexFacesRequest.setImage(source);
        indexFacesRequest.setCollectionId(collectionId);
        client.indexFaces(indexFacesRequest);

        indexFacesRequest = new IndexFacesRequest();
        indexFacesRequest.setImage(ms2);
        indexFacesRequest.setCollectionId(collectionId);
        client.indexFaces(indexFacesRequest);

        indexFacesRequest = new IndexFacesRequest();
        indexFacesRequest.setImage(ms4);
        indexFacesRequest.setCollectionId(collectionId);
        client.indexFaces(indexFacesRequest);

        SearchFacesByImageRequest searchFacesByImageRequest = new SearchFacesByImageRequest();
        searchFacesByImageRequest
                .withCollectionId(collectionId)
                .withImage(ms3)
                .withFaceMatchThreshold(80F);

        SearchFacesByImageResult searchFacesByImageResult =
                client.searchFacesByImage(searchFacesByImageRequest);

        List <FaceMatch> faceImageMatches = searchFacesByImageResult.getFaceMatches();
        for (FaceMatch face: faceImageMatches) {
            Log.d(TAG, face.toString());
        }
    }

iOS:

创建 Cognito 凭据提供程序

AWSCognitoCredentialsProvider *credentialsProvider = [[AWSCognitoCredentialsProvider alloc] initWithRegionType:AWSRegionUSEast1                                                                                                        identityPoolId: @"MyPoolID"];

AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSEast1                                                                          credentialsProvider:credentialsProvider];

[AWSServiceManager defaultServiceManager].defaultServiceConfiguration = configuration;

使用相同的身份池 ID 和区域 (us-east-1)。

func faceIndexNoFacesSearch() {
    let rekognition = AWSRekognition.default()
    let faceRequest = AWSRekognitionSearchFacesByImageRequest()
    do {
        let image = AWSRekognitionImage()
        image?.s3Object = AWSRekognitionS3Object()
        image?.s3Object?.bucket = "us-east-1-bucket"
        image?.s3Object?.name = "ms-2.jpg"
        faceRequest!.image = image
        faceRequest!.collectionId = "MyCollectionID"

        rekognition.searchFaces(byImage: faceRequest!).continueWith { (response) -> Any? in
            XCTAssertNil(response.error)
            XCTAssertNotNil(response.result)
            if let result = response.result {
                XCTAssertNotNil(result.faceMatches)
            }
            return nil
            }.waitUntilFinished()

    } catch  {
        print("exception")
    }
}

请在评论中post问题,我们可以在那里讨论。

好的,结果问题大不相同,解决方案也非常简单。当我发现它有点不同时,我发布了关于同一问题的另一个问题,并且我也发布了一个答案。 这里是: