本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
您可以使用任何支援的 AWS SDK 測試 Amazon Rekognition 人臉活體,例如 AWS Python SDK Boto3 或適用於 Java 的 AWS SDK。您可以使用所選的 SDK 來呼叫 CreateFaceLivenessSession
和 GetFaceLivenessSessionResults
API。下一節將示範如何使用 Python 和 Java SDK 呼叫這些 API。
若要呼叫人臉活體 API:
-
如果您尚未這麼做,請建立或更新具有
AmazonRekognitionFullAccess
權限的使用者。如需詳細資訊,請參閱步驟 1:設定 AWS 帳戶並建立使用者。 -
如果您尚未準備就緒,請安裝並設定 AWS CLI 與 AWS SDK。如需詳細資訊,請參閱步驟 2:設定 AWS CLI 和 AWS SDK。
下面的片段顯示了如何在 Python 應用程式中呼叫這些 API。請注意,若要執行此範例,您必須至少使用 Boto3 SDK 的 1.26.110 版本,但建議您使用最新版本的 SDK。
import boto3
session = boto3.Session(profile_name='default')
client = session.client('rekognition')
def create_session():
response = client.create_face_liveness_session()
session_id = response.get("SessionId")
print('SessionId: ' + session_id)
return session_id
def get_session_results(session_id):
response = client.get_face_liveness_session_results(SessionId=session_id)
confidence = response.get("Confidence")
status = response.get("Status")
print('Confidence: ' + "{:.2f}".format(confidence) + "%")
print('Status: ' + status)
return status
def main():
session_id = create_session()
print('Created a Face Liveness Session with ID: ' + session_id)
status = get_session_results(session_id)
print('Status of Face Liveness Session: ' + status)
if __name__ == "__main__":
main()