使用Azure Face Recognition遇403错误,无商用资质求替代方案
Azure Face Recognition本地测试遇403错误的替代方案
我在本地网页中使用Azure Face Recognition时收到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 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>
错误截图

替代方案建议
- 使用本地开源人脸识别库:完全无需云端服务,直接在浏览器端处理逻辑,适配本地测试场景。比如
face-api.js(基于TensorFlow.js,支持人脸检测、表情识别,和现有代码逻辑适配度高),或是功能更全面的opencv.js。 - 如实提交Azure审批表单:填写时说明处于本地测试阶段,商用邮箱可填个人邮箱并备注情况,生产URL填写本地地址(如
http://localhost:8080),审核团队通常会认可这类测试申请。 - 改用其他云服务商免费API:部分平台提供免费额度的人脸检测服务,无需复杂审批,能满足小规模测试需求。
内容的提问来源于stack exchange,提问作者Wilton
相关产品推荐
相关产品推荐

