0

我有一个项目要完成,每当图像被编码为 base64 时,AWS Rekognition 文档告诉我如何获取元数据。

.getScreenshot()返回已捕获图像的 base64。

到目前为止,以下是我的代码:

import React, { Component } from "react";
import Webcam from "react-webcam";
import AWS from "aws-sdk";
import { creds } from "./secret";
import { Grid, Container, Button, Input } from "semantic-ui-react";

AWS.config.update({
  accessKeyId: creds.accessKeyId,
  secretAccessKey: creds.secretAccessKey,
  region: "us-east-1"
});

const rekognition = new AWS.Rekognition({ apiVersion: "2016-06-27" });

class CameraComponent extends Component {
  constructor() {
    super();

    this.state = {
      verificationFailed: "",
      verificationSucceed: "",
      faceId: "",
      fileName: ""
    };

    this.changeToFileName = this.changeToFileName.bind(this);
  }

  setRef = webcam => {
    this.webcam = webcam;
  };

  capture = () => {
    const image = this.webcam.getScreenshot().slice(23);
    console.log(image);

    const params = {
      SourceImage: {
        Bytes: image
      },
      TargetImage: {
        S3Object: {
          Bucket: "my-bucket",
          Name: "my-image.jpg"
        }
      },
      SimilarityThreshold: 0.0
    };

    rekognition.compareFaces(params, (err, data) => {
      if (err) console.log(err);

      console.log(data);
    });
  };

提前致谢!

4

0 回答 0