let canvas = document.createElement('canvas');
let context = canvas.getContext( '2d' );
context.drawImage( video, 0, 0 );
let image_src = canvas.toDataURL('image/jpeg');
let dataURL = canvas.toDataURL("image/jpeg");
let image= dataURL.replace(/^data:image\/(png|jpg);base64,/, "");
console.log(image);
let params = {
// Request parameters
"returnFaceId": "true",
"returnFaceLandmarks": "false",
"returnFaceAttributes": "age",
};
$.ajax({
url: "https://westus.api.cognitive.microsoft.com/face/v1.0/detect?" + $.param(params),
beforeSend: function(xhrObj){
// Request headers
xhrObj.setRequestHeader("Content-Type","application/octet-stream");
xhrObj.setRequestHeader("Ocp-Apim-Subscription-Key","8b99a9ed839a40a08aa8b529ef0f9b8c");
},
type: "POST",
// Request body
data: [image],
})
This Javascript code captures an image and then passes it to a JSON object. However, the request always receives a response of 400. You can find more information about the Microsoft API here:
Here is a screenshot of the API documentation.
Can you provide any hints on how to properly pass the image?
https://i.sstatic.net/qVYqA.png