Skip to content

Commit 33838de

Browse files
committed
Face recognition
1 parent 64433a6 commit 33838de

File tree

1 file changed

+43
-9
lines changed

1 file changed

+43
-9
lines changed

samples/Calling/src/app/views/CallScreen.tsx

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ const AzureCommunicationCallScreen = (props: AzureCommunicationCallScreenProps):
179179

180180
if (imageUrl && imageUrl.length > 10) {
181181
console.log('image url - ', imageBase64ToBlob(imageUrl));
182-
await detectHandGestures(imageUrl);
182+
// await detectHandGestures(imageUrl);
183+
await detectHeadMovements(imageUrl);
183184
}
184185
animationFrameId = requestAnimationFrame(analyzeFrame);
185186
}
@@ -211,11 +212,11 @@ const AzureCommunicationCallScreen = (props: AzureCommunicationCallScreenProps):
211212
return null;
212213
}
213214
async function detectHandGestures1(imageBase64: string) {
214-
const CUSTOM_VISION_ENDPOINT = 'https://azureaiinsravan.cognitiveservices.azure.com';
215+
// const CUSTOM_VISION_ENDPOINT = 'https://azureaiinsravan.cognitiveservices.azure.com';
215216
const CUSTOM_VISION_KEY = 'Ffnb7EK1Z65PWAn9o31l5dxMV8kP1C6rIMAn2vbPRzZ3EidaEKjvJQQJ99BBACYeBjFXJ3w3AAAFACOGXhO6';
216217
const PREDICTION_KEY = 'ebc77a8a52e04e9394125c19f2dc8a16';
217-
const PROJECT_ID = 'daaea539-0d1a-456b-a0fc-31e121039d56';
218-
const MODEL_NAME = 'FaceExpressionAndHandGestures';
218+
// const PROJECT_ID = 'daaea539-0d1a-456b-a0fc-31e121039d56';
219+
// const MODEL_NAME = 'FaceExpressionAndHandGestures';
219220

220221
const response = await fetch(
221222
//`${CUSTOM_VISION_ENDPOINT}/customvision/v3.0/Prediction/${PROJECT_ID}/classify/iterations/${MODEL_NAME}/url`,
@@ -239,11 +240,11 @@ const AzureCommunicationCallScreen = (props: AzureCommunicationCallScreenProps):
239240
console.log(data);
240241
}
241242
async function detectHandGestures(imageBase64: string) {
242-
const CUSTOM_VISION_ENDPOINT = 'https://azureaiinsravan.cognitiveservices.azure.com';
243+
// const CUSTOM_VISION_ENDPOINT = 'https://azureaiinsravan.cognitiveservices.azure.com';
243244
const CUSTOM_VISION_KEY = 'Ffnb7EK1Z65PWAn9o31l5dxMV8kP1C6rIMAn2vbPRzZ3EidaEKjvJQQJ99BBACYeBjFXJ3w3AAAFACOGXhO6';
244245
const PREDICTION_KEY = 'ebc77a8a52e04e9394125c19f2dc8a16';
245-
const PROJECT_ID = 'daaea539-0d1a-456b-a0fc-31e121039d56';
246-
const MODEL_NAME = 'FaceExpressionAndHandGestures';
246+
// const PROJECT_ID = 'daaea539-0d1a-456b-a0fc-31e121039d56';
247+
// const MODEL_NAME = 'FaceExpressionAndHandGestures';
247248

248249
const response = await fetch(
249250
//`${CUSTOM_VISION_ENDPOINT}/customvision/v3.0/Prediction/${PROJECT_ID}/classify/iterations/${MODEL_NAME}/url`,
@@ -260,9 +261,9 @@ const AzureCommunicationCallScreen = (props: AzureCommunicationCallScreenProps):
260261
);
261262

262263
const data = await response.json();
263-
console.log('Gesture detected data - \n');
264-
console.log(data);
264+
console.log(`CHUK ==== ${JSON.stringify(data)}`);
265265
}
266+
266267
function imageBase64ToBlob(base64: string) {
267268
const base64Data = base64.split(',')[1];
268269
if (!base64Data) {
@@ -289,6 +290,38 @@ const AzureCommunicationCallScreen = (props: AzureCommunicationCallScreenProps):
289290
// return new Blob([new Uint8Array(byteNumbers)], { type: 'image/jpeg' });
290291
// }
291292

293+
async function detectHeadMovements(imageBase64: string): Promise<void> {
294+
const FACE_API_ENDPOINT = '<YOUR_FACE_API';
295+
const FACE_API_KEY = '<YOUR_FACE_API';
296+
297+
const response = await fetch(`${FACE_API_ENDPOINT}/face/v1.0/detect?returnFaceAttributes=headPose`, {
298+
method: 'POST',
299+
headers: {
300+
'Ocp-Apim-Subscription-Key': FACE_API_KEY,
301+
'Content-Type': 'application/octet-stream'
302+
},
303+
body: imageBase64ToBlob(imageBase64)
304+
});
305+
306+
const data = await response.json();
307+
processHeadMovements(data);
308+
}
309+
310+
function processHeadMovements(data: { faceAttributes: { headPose: { yaw: number; pitch: number } } }[]): void {
311+
data.forEach((face: { faceAttributes: { headPose: { yaw: number; pitch: number } } }) => {
312+
const { yaw, pitch } = face.faceAttributes.headPose;
313+
let resultText = '';
314+
315+
if (pitch > 10) {
316+
resultText = '✅ Nodding (Yes)';
317+
} else if (yaw > 15 || yaw < -15) {
318+
resultText = '❌ Shaking Head (No)';
319+
}
320+
321+
console.log(`HeadMovement ====> ${resultText}`);
322+
});
323+
}
324+
292325
const callAdapterOptions: AzureCommunicationCallAdapterOptions = useMemo(() => {
293326
return {
294327
videoBackgroundOptions: {
@@ -418,6 +451,7 @@ const AzureCommunicationOutboundCallScreen = (props: AzureCommunicationCallScree
418451
console.log('Gesture detected data - \n');
419452
console.log(data);
420453
}
454+
421455
function imageBase64ToBlob(base64: string) {
422456
const base64Data = base64.split(',')[1];
423457
if (!base64Data) {

0 commit comments

Comments
 (0)