AWS Rekognition图像编码问题

时间:2018-06-14 22:39:15

标签: reactjs amazon-web-services webcam encode amazon-rekognition

我有一个项目要完成,每当图像被编码到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: "facerdb",
          Name: "jayprofile.jpg"
        }
      },
      SimilarityThreshold: 0.0
    };

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

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

提前致谢!

0 个答案:

没有答案