@@ -179,7 +179,8 @@ const AzureCommunicationCallScreen = (props: AzureCommunicationCallScreenProps):
179
179
180
180
if ( imageUrl && imageUrl . length > 10 ) {
181
181
console . log ( 'image url - ' , imageBase64ToBlob ( imageUrl ) ) ;
182
- await detectHandGestures ( imageUrl ) ;
182
+ // await detectHandGestures(imageUrl);
183
+ await detectHeadMovements ( imageUrl ) ;
183
184
}
184
185
animationFrameId = requestAnimationFrame ( analyzeFrame ) ;
185
186
}
@@ -211,11 +212,11 @@ const AzureCommunicationCallScreen = (props: AzureCommunicationCallScreenProps):
211
212
return null ;
212
213
}
213
214
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';
215
216
const CUSTOM_VISION_KEY = 'Ffnb7EK1Z65PWAn9o31l5dxMV8kP1C6rIMAn2vbPRzZ3EidaEKjvJQQJ99BBACYeBjFXJ3w3AAAFACOGXhO6' ;
216
217
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';
219
220
220
221
const response = await fetch (
221
222
//`${CUSTOM_VISION_ENDPOINT}/customvision/v3.0/Prediction/${PROJECT_ID}/classify/iterations/${MODEL_NAME}/url`,
@@ -239,11 +240,11 @@ const AzureCommunicationCallScreen = (props: AzureCommunicationCallScreenProps):
239
240
console . log ( data ) ;
240
241
}
241
242
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';
243
244
const CUSTOM_VISION_KEY = 'Ffnb7EK1Z65PWAn9o31l5dxMV8kP1C6rIMAn2vbPRzZ3EidaEKjvJQQJ99BBACYeBjFXJ3w3AAAFACOGXhO6' ;
244
245
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';
247
248
248
249
const response = await fetch (
249
250
//`${CUSTOM_VISION_ENDPOINT}/customvision/v3.0/Prediction/${PROJECT_ID}/classify/iterations/${MODEL_NAME}/url`,
@@ -260,9 +261,9 @@ const AzureCommunicationCallScreen = (props: AzureCommunicationCallScreenProps):
260
261
) ;
261
262
262
263
const data = await response . json ( ) ;
263
- console . log ( 'Gesture detected data - \n' ) ;
264
- console . log ( data ) ;
264
+ console . log ( `CHUK ==== ${ JSON . stringify ( data ) } ` ) ;
265
265
}
266
+
266
267
function imageBase64ToBlob ( base64 : string ) {
267
268
const base64Data = base64 . split ( ',' ) [ 1 ] ;
268
269
if ( ! base64Data ) {
@@ -289,6 +290,38 @@ const AzureCommunicationCallScreen = (props: AzureCommunicationCallScreenProps):
289
290
// return new Blob([new Uint8Array(byteNumbers)], { type: 'image/jpeg' });
290
291
// }
291
292
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
+
292
325
const callAdapterOptions : AzureCommunicationCallAdapterOptions = useMemo ( ( ) => {
293
326
return {
294
327
videoBackgroundOptions : {
@@ -418,6 +451,7 @@ const AzureCommunicationOutboundCallScreen = (props: AzureCommunicationCallScree
418
451
console . log ( 'Gesture detected data - \n' ) ;
419
452
console . log ( data ) ;
420
453
}
454
+
421
455
function imageBase64ToBlob ( base64 : string ) {
422
456
const base64Data = base64 . split ( ',' ) [ 1 ] ;
423
457
if ( ! base64Data ) {
0 commit comments