Android中的Amazon Rekognition中的人脸比较

时间:2019-09-09 07:05:57

标签: java android amazon-web-services

我正在使用Amazon Face Camparasion api,因为当我将源图像作为人物ID和目标图像作为人物图像进行比较时,其相似度约为16%,但是当我在亚马逊控制台中使用这两个图像时,其相似度为85%, 在我的程序中,当我比较两个图像而不是id或仅是图像时,它将提供准确的相似性,为什么会这样,但我找不到问题,请帮助我........谢谢

    String sourceImagePath = path+"/DCIM/Camera/20190617_144126.jpg";
    String targetImagePath = path+"/DCIM/Camera/20190605_134214.jpg";
    ByteBuffer sourceImageBytes = null;
    ByteBuffer targetImageBytes = null;

rekognitionClient = new AmazonRekognitionClient (new BasicAWSCredentials ( accessKey, secretKey));

 try (InputStream inputStream = new FileInputStream (new File (sourceImagePath))) {
        sourceImageBytes = ByteBuffer.wrap( IOUtils.toByteArray(inputStream));
    }
    catch(Exception e)
    {
        Log.d("exception1","Failed to load source image " + sourceImagePath +e);
        //System.exit(1);
    }
 try (InputStream inputStream = new FileInputStream(new File(getFilesDir (),getPhotoFilename ()))) {
        targetImageBytes = ByteBuffer.wrap(IOUtils.toByteArray(inputStream));
    }
    catch(Exception e)
    {
        Log.d("exception2","Failed to load target images: " + targetImagePath);
        //System.exit(1);
    }
Image source = new Image()
            .withBytes(sourceImageBytes);
    Image target = new Image()
            .withBytes(targetImageBytes);
CompareFacesRequest request = new CompareFacesRequest()
            .withSourceImage(source)
            .withTargetImage(target)
            .withSimilarityThreshold(similarityThreshold);

CompareFacesResult compareFacesResult = rekognitionClient.compareFaces(request);

List<CompareFacesMatch> faceDetails = compareFacesResult.getFaceMatches();

    for (CompareFacesMatch match: faceDetails){
        ComparedFace face= match.getFace();
        BoundingBox position = face.getBoundingBox();

        Log.d("facess","Face at " + position.getLeft().toString() +" left and top " + position.getTop() +
                " matches with " + match.getSimilarity().toString()
                +"% confidence." );
    }
    List<ComparedFace> uncompared = compareFacesResult.getUnmatchedFaces();

Log.d("faceUncompare","There was " + uncompared.size()
            + " face(s) that did not match");

0 个答案:

没有答案