Skip to content

Commit 904e52b

Browse files
committed
Add Python code snippet
1 parent 6e6defa commit 904e52b

File tree

1 file changed

+73
-0
lines changed
  • articles/ai-services/computer-vision/Tutorials

1 file changed

+73
-0
lines changed

articles/ai-services/computer-vision/Tutorials/liveness.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,21 @@ The high-level steps involved in liveness orchestration are illustrated below:
101101

102102
#### [Python](#tab/python)
103103
```python
104+
endpoint = os.environ["VISION_ENDPOINT"]
105+
key = os.environ["VISION_KEY"]
106+
107+
face_session_client = FaceSessionClient(endpoint=endpoint, credential=AzureKeyCredential(key))
108+
109+
created_session = await face_session_client.create_liveness_session(
110+
CreateLivenessSessionContent(
111+
liveness_operation_mode=LivenessOperationMode.PASSIVE,
112+
device_correlation_id="723d6d03-ef33-40a8-9682-23a1feb7bccd",
113+
send_results_to_client=False,
114+
)
115+
)
116+
print("Session created.")
117+
print(f"Session id: {created_session.session_id}")
118+
print(f"Auth token: {created_session.auth_token}")
104119
```
105120

106121
#### [JavaScript](#tab/javascript)
@@ -184,6 +199,18 @@ The high-level steps involved in liveness orchestration are illustrated below:
184199

185200
#### [Python](#tab/python)
186201
```python
202+
liveness_result = await face_session_client.get_liveness_session_result(
203+
created_session.session_id
204+
)
205+
print(f"Session id: {liveness_result.id}")
206+
print(f"Session status: {liveness_result.status}")
207+
print(f"Liveness detection request id: {liveness_result.result.request_id}")
208+
print(f"Liveness detection received datetime: {liveness_result.result.received_date_time}")
209+
print(f"Liveness detection result: {liveness_result.result.response.body.liveness_decision}")
210+
print(f"Session created datetime: {liveness_result.created_date_time}")
211+
print(f"Auth token TTL (seconds): {liveness_result.auth_token_time_to_live_in_seconds}")
212+
print(f"Session expired: {liveness_result.session_expired}")
213+
print(f"Device correlation id: {liveness_result.device_correlation_id}")
187214
```
188215

189216
#### [JavaScript](#tab/javascript)
@@ -261,6 +288,11 @@ The high-level steps involved in liveness orchestration are illustrated below:
261288

262289
#### [Python](#tab/python)
263290
```python
291+
await face_session_client.delete_liveness_session(
292+
created_session.session_id
293+
)
294+
print(f"The session {created_session.session_id} is deleted.")
295+
await face_session_client.close()
264296
```
265297

266298
#### [JavaScript](#tab/javascript)
@@ -326,6 +358,28 @@ The high-level steps involved in liveness with verification orchestration are il
326358

327359
#### [Python](#tab/python)
328360
```python
361+
endpoint = os.environ["VISION_ENDPOINT"]
362+
key = os.environ["VISION_KEY"]
363+
364+
face_session_client = FaceSessionClient(endpoint=endpoint, credential=AzureKeyCredential(key))
365+
366+
reference_image_path = "test.png"
367+
with open(reference_image_path, "rb") as fd:
368+
reference_image_content = fd.read()
369+
370+
created_session = await face_session_client.create_liveness_with_verify_session(
371+
CreateLivenessSessionContent(
372+
liveness_operation_mode=LivenessOperationMode.PASSIVE,
373+
device_correlation_id="723d6d03-ef33-40a8-9682-23a1feb7bccd",
374+
),
375+
verify_image=reference_image_content,
376+
)
377+
print("Session created.")
378+
print(f"Session id: {created_session.session_id}")
379+
print(f"Auth token: {created_session.auth_token}")
380+
print("The reference image:")
381+
print(f" Face rectangle: {created_session.verify_image.face_rectangle}")
382+
print(f" The quality for recognition: {created_session.verify_image.quality_for_recognition}")
329383
```
330384

331385
#### [JavaScript](#tab/javascript)
@@ -406,6 +460,20 @@ The high-level steps involved in liveness with verification orchestration are il
406460

407461
#### [Python](#tab/python)
408462
```python
463+
liveness_result = await face_session_client.get_liveness_with_verify_session_result(
464+
created_session.session_id
465+
)
466+
print(f"Session id: {liveness_result.id}")
467+
print(f"Session status: {liveness_result.status}")
468+
print(f"Liveness detection request id: {liveness_result.result.request_id}")
469+
print(f"Liveness detection received datetime: {liveness_result.result.received_date_time}")
470+
print(f"Liveness detection decision: {liveness_result.result.response.body.liveness_decision}")
471+
print(f"Verification result: {liveness_result.result.response.body.verify_result.is_identical}")
472+
print(f"Verification confidence: {liveness_result.result.response.body.verify_result.match_confidence}")
473+
print(f"Session created datetime: {liveness_result.created_date_time}")
474+
print(f"Auth token TTL (seconds): {liveness_result.auth_token_time_to_live_in_seconds}")
475+
print(f"Session expired: {liveness_result.session_expired}")
476+
print(f"Device correlation id: {liveness_result.device_correlation_id}")
409477
```
410478

411479
#### [JavaScript](#tab/javascript)
@@ -487,6 +555,11 @@ The high-level steps involved in liveness with verification orchestration are il
487555

488556
#### [Python](#tab/python)
489557
```python
558+
await face_session_client.delete_liveness_with_verify_session(
559+
created_session.session_id
560+
)
561+
print(f"The session {created_session.session_id} is deleted.")
562+
await face_session_client.close()
490563
```
491564

492565
#### [JavaScript](#tab/javascript)

0 commit comments

Comments
 (0)