解析json aws api响应

问题描述 投票:0回答:1

下面的代码是从Amazon Web Service api返回的json响应,我的问题是我需要能够访问json数据中的“ confidence”值才能使用它。

这是我的go文件:

package main

import (
    "fmt"
    "github.com/aws/aws-sdk-go/aws"
    "github.com/aws/aws-sdk-go/aws/credentials"
    "github.com/aws/aws-sdk-go/aws/session"
    "github.com/aws/aws-sdk-go/service/rekognition"
    "io/ioutil"
)

func main() {
    imagePath := "image.jpg"

    imageBytes, err := ioutil.ReadFile(imagePath)
    if err != nil {
        fmt.Println(err.Error())
        return
    }

    image := &rekognition.Image {
        Bytes: imageBytes,
    }

    accessKeyId := "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    secretAccessKey := "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    sess := session.Must(session.NewSession(&aws.Config{
        Region: aws.String("us-west-2"),
        Credentials: credentials.NewStaticCredentials(accessKeyId, secretAccessKey, ""),
    }))

    {
        svc := rekognition.New(sess)
        input := &rekognition.CompareFacesInput{}

        input.SetSourceImage(image)
        input.SetTargetImage(image)

        result, err := svc.CompareFaces(input)
        if err != nil {
        {

                fmt.Println(err.Error())
            }
            return
        }

        fmt.Println(result)
    }

}
json amazon-web-services go
1个回答
0
投票

这是json输出:

{
  FaceMatches: [{
      Face: {
        BoundingBox: {
          Height: 0.33446764945983887,
          Left: 0.7269275784492493,
          Top: 0.3698653280735016,
          Width: 0.1676127314567566
        },
        Confidence: 100,
        Landmarks: [
          {
            Type: "eyeLeft",
            X: 0.7650560140609741,
            Y: 0.49462559819221497
          },
          {
            Type: "eyeRight",
            X: 0.8407831192016602,
            Y: 0.48974335193634033
          },
          {
            Type: "mouthLeft",
            X: 0.7740461826324463,
            Y: 0.6112403273582458
          },
          {
            Type: "mouthRight",
            X: 0.8370857238769531,
            Y: 0.6070452332496643
          },
          {
            Type: "nose",
            X: 0.804897129535675,
            Y: 0.5548359155654907
          }
        ],
        Pose: {
          Pitch: 29.87976837158203,
          Roll: -8.730767250061035,
          Yaw: -4.869274616241455
        },
        Quality: {
          Brightness: 64.4018783569336,
          Sharpness: 86.86019134521484
        }
      },
      Similarity: 100
    },{
      Face: {
        BoundingBox: {
          Height: 0.18176360428333282,
          Left: 0.5159885883331299,
          Top: 0.3066486716270447,
          Width: 0.08783846348524094
        },
        Confidence: 99.9986801147461,
        Landmarks: [
          {
            Type: "eyeLeft",
            X: 0.5425398945808411,
            Y: 0.38129788637161255
          },
          {
            Type: "eyeRight",
            X: 0.581177830696106,
            Y: 0.38023239374160767
          },
          {
            Type: "mouthLeft",
            X: 0.5462372303009033,
            Y: 0.4429836869239807
          },
          {
            Type: "mouthRight",
            X: 0.5782404541969299,
            Y: 0.44202104210853577
          },
          {
            Type: "nose",
            X: 0.5634965896606445,
            Y: 0.4119497239589691
          }
        ],
        Pose: {
          Pitch: -8.745380401611328,
          Roll: -1.6505851745605469,
          Yaw: 1.6412829160690308
        },
        Quality: {
          Brightness: 92.24726104736328,
          Sharpness: 78.64350128173828
        }
      },
      Similarity: 98.98473358154297
    }],
  SourceImageFace: {
    BoundingBox: {
      Height: 0.33446764945983887,
      Left: 0.7269275784492493,
      Top: 0.3698653280735016,
      Width: 0.1676127314567566
    },
    Confidence: 100
  },
  UnmatchedFaces: []
}
© www.soinside.com 2019 - 2024. All rights reserved.