/* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ import React from "react"; import "./PoseChallenge.css"; import SpinnerMessage from "../components/SpinnerMessage"; import { CanvasUtils } from "../utils/CanvasUtils"; import { APIUtils, ChallengeMetadata } from "../utils/APIUtils"; import { ConfigUtils } from "../utils/ConfigUtils"; import { MediaUtils } from "../utils/MediaUtils"; import { FacePose } from "./FacePose"; const STEP_1 = "InstructionsStep"; const STEP_2 = "PoseStep"; const STEP_3 = "CheckStep"; type Props = { challengeMetadata: ChallengeMetadata; onLocalEnd: (localSuccess: boolean) => void; onError: (error: Error) => void; }; type State = { uploading: boolean; stepName: string; }; export default class PoseChallenge extends React.Component { constructor(props: Props | Readonly) { super(props); this.state = { uploading: false, stepName: STEP_1 }; this.startChallenge = this.startChallenge.bind(this); this.takePhoto = this.takePhoto.bind(this); this.endChallenge = this.endChallenge.bind(this); } startChallenge() { this.setState({ stepName: STEP_2 }); } takePhoto() { const videoWidth = MediaUtils.getMediaStreamInfo().actualWidth; const videoHeight = MediaUtils.getMediaStreamInfo().actualHeight; const flip = ConfigUtils.getConfigBooleanValue("FLIP_VIDEO"); CanvasUtils.takePhoto("video-camera", "canvas-invisible", videoWidth, videoHeight, flip); CanvasUtils.drawScaledCanvasInCanvas("canvas-invisible", "canvas-photo-check"); this.setState({ stepName: STEP_3 }); } endChallenge() { const base64Photo = CanvasUtils.getPhotoFromCanvas("canvas-invisible", ConfigUtils.getConfig().IMAGE_JPG_QUALITY); this.setState({ uploading: true }); const self = this; APIUtils.putChallengeFrame( this.props.challengeMetadata.id, this.props.challengeMetadata.token, base64Photo, Date.now() ) .then(() => this.props.onLocalEnd(true)) .catch(error => this.props.onError(error)) .finally(() => { self.setState({ uploading: false }); }); } componentDidMount() { CanvasUtils.setVideoElementSrc("video-camera", MediaUtils.getMediaStreamInfo().mediaStream); // @ts-ignore const pose = this.props.challengeMetadata.params.pose; for (const canvasElementId of ["canvas-pose-big", "canvas-pose-small", "canvas-pose-check"]) { new FacePose(pose.eyes, pose.mouth).draw(canvasElementId); } } render() { const videoWidth = MediaUtils.getMediaStreamInfo().actualWidth; const videoHeight = MediaUtils.getMediaStreamInfo().actualHeight; const shouldRotate = ConfigUtils.getConfigBooleanValue("FLIP_VIDEO"); return (
{!this.state.uploading && (
{/* */}

Get ready to copy the pose

In the next step, copy the facial expression shown below.

Copy the pose

Avoid rotating your face and make sure it is well-illuminated.

Do these pictures match?

Check if your pose is as similar as possible.

)} {this.state.uploading && }
); } }