英文:
Azure Face Recognition - returning 403
问题
我正在尝试使用Azure人脸识别,但我收到了403错误。我搜索了一下,看起来我需要填写一个表格并获得批准才能使用这个资源。问题是,我正在尝试在我的本地网页中使用人脸识别的解决方案,如果工作良好,我将开发一个生产网页,所以我没有商业电子邮件或生产URL来填写表格。
有替代解决方案吗?
以下是我的代码和返回的错误:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Reconhecimento Facial - Login</title>
</head>
<body>
<h1>Reconhecimento Facial - Login</h1>
<div id="message"></div>
<video id="video" width="640" height="480" autoplay></video>
<canvas id="canvas" width="640" height="480"></canvas>
<button id="loginButton">Login</button>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script>
// Azure人脸API端点和订阅密钥
const endpoint = '我的端点';
const subscriptionKey = '我的密钥';
// 视频和画布元素
const video = document.getElementById('video');
const canvas = document.getElementById('canvas');
const context = canvas.getContext('2d');
// 加载视频的函数
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia || navigator.mediaDevices.getUserMedia || navigator.getUserMedia;
if (navigator.getUserMedia) {
navigator.getUserMedia({ video: true }, stream => {
video.srcObject = stream;
}, error => {
console.log('访问摄像头时出错:' + error);
});
}
// 拍照并发送到Azure人脸API进行识别的函数
function takeSnapshot() {
context.drawImage(video, 0, 0, canvas.width, canvas.height);
const imageData = canvas.toDataURL('image/jpeg');
// 将图像发送到Azure人脸API
axios.post(`${endpoint}/face/v1.0/detect?returnFaceId=true&returnFaceAttributes=emotion`, {
url: imageData
}, {
headers: {
'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key': subscriptionKey
}
}).then(response => {
const faceId = response.data[0].faceId;
const emotions = response.data[0].faceAttributes.emotion;
// 检查情感以进行用户身份验证
if (emotions.happiness > 0.5) {
// 检测到幸福情感,身份验证成功
showMessage('用户已成功验证!');
} else {
// 未检测到幸福情感,身份验证失败
showMessage('身份验证失败。请重试。');
}
}).catch(error => {
console.log('Azure人脸API请求出错:' + error);
showMessage('Azure人脸API请求出错。请重试。');
});
}
// 在屏幕上显示消息的函数
function showMessage(message) {
const messageDiv = document.getElementById('message');
messageDiv.innerHTML = message;
}
// 点击登录按钮触发人脸识别的事件
const loginButton = document.getElementById('loginButton');
loginButton.addEventListener('click', takeSnapshot);
</script>
</body>
</html>
英文:
I'm trying to use Azure Face Recognition but I'm receiving a 403 return. I searched and it looks like a need to fill a form and be approved to use this resource. The problem is that I'm trying to find a solution to use face recognition in my local webpage and if work well I will develop a webpage in production, so I don't have a commercial e-mail or a production url to fill the form.
There is a alternative solution?
To exemplify here is my code and the returning error:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Reconhecimento Facial - Login</title>
</head>
<body>
<h1>Reconhecimento Facial - Login</h1>
<div id="message"></div>
<video id="video" width="640" height="480" autoplay></video>
<canvas id="canvas" width="640" height="480"></canvas>
<button id="loginButton">Login</button>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script>
// Azure Face API Endpoint e Chave de Assinatura
const endpoint = 'my endpoint';
const subscriptionKey = 'my key';
// Elementos de vídeo e canvas
const video = document.getElementById('video');
const canvas = document.getElementById('canvas');
const context = canvas.getContext('2d');
// Função para carregar o vídeo
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia || navigator.mediaDevices.getUserMedia || navigator.getUserMedia;
if (navigator.getUserMedia) {
navigator.getUserMedia({ video: true }, stream => {
video.srcObject = stream;
}, error => {
console.log('Erro ao acessar a câmera: ' + error);
});
}
// Função para tirar uma foto e enviar para o Azure Face API para reconhecimento
function takeSnapshot() {
context.drawImage(video, 0, 0, canvas.width, canvas.height);
const imageData = canvas.toDataURL('image/jpeg');
// Enviar a imagem para o Azure Face API
axios.post(`${endpoint}/face/v1.0/detect?returnFaceId=true&returnFaceAttributes=emotion`, {
url: imageData
}, {
headers: {
'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key': subscriptionKey
}
}).then(response => {
const faceId = response.data[0].faceId;
const emotions = response.data[0].faceAttributes.emotion;
// Verificar as emoções para autenticar o usuário
if (emotions.happiness > 0.5) {
// Emoção de felicidade detectada, autenticação bem-sucedida
showMessage('Usuário autenticado com sucesso!');
} else {
// Emoção de felicidade não detectada, autenticação falhou
showMessage('Falha na autenticação. Por favor, tente novamente.');
}
}).catch(error => {
console.log('Erro na requisição para o Azure Face API: ' + error);
showMessage('Erro na requisição para o Azure Face API. Por favor, tente novamente.');
});
}
// Função para exibir mensagens na tela
function showMessage(message) {
const messageDiv = document.getElementById('message');
messageDiv.innerHTML = message;
}
// Evento para acionar o reconhecimento facial ao pressionar o botão de login
const loginButton = document.getElementById('loginButton');
loginButton.addEventListener('click', takeSnapshot);
</script>
</body>
</html>
答案1
得分: 0
Face API返回403错误
上述错误发生在您未被授权使用您尝试从请求中调用的功能时,现在已经阻止了对其的访问。
Face服务的访问受限于符合资格和使用要求,以限制我们的负责任AI原则。要了解速率限制并修改您的使用方式,请参阅Face API 文档。
请确保使用适当的身份验证,您可以在我的环境中使用相同的代码,它可以成功运行。
参考资料:
Microsoft Azure Cognitive Services Face API错误403 - Microsoft Q&A - romungi-MSFT
Face API返回403错误 - Microsoft Q&A - YutongTie-MSFT
英文:
> Face API return 403 error
The above error occurs when you were not authorized to use the capability you were attempting to call from the request, which has now blocked access for them.
Access to the Face service is restricted based on eligibility and use requirements to limit our Responsible AI tenets. To understand the rate limitations and modify the way you use it, see the Face API documentation.
Make sure with proper authentication and you can use the same code and in my environment, it worked successfully.
Reference:
Microsoft Azure Cognitive Services Face API error 403 - Microsoft Q&A - romungi-MSFT
Face API return 403 error - Microsoft Q&A - YutongTie-MSFT
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论