Azure人脸识别 – 返回403

huangapple go评论81阅读模式
英文:

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>

Azure人脸识别 – 返回403

英文:

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:

&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta charset=&quot;UTF-8&quot;&gt;
&lt;title&gt;Reconhecimento Facial - Login&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Reconhecimento Facial - Login&lt;/h1&gt;
&lt;div id=&quot;message&quot;&gt;&lt;/div&gt;
&lt;video id=&quot;video&quot; width=&quot;640&quot; height=&quot;480&quot; autoplay&gt;&lt;/video&gt;
&lt;canvas id=&quot;canvas&quot; width=&quot;640&quot; height=&quot;480&quot;&gt;&lt;/canvas&gt;
&lt;button id=&quot;loginButton&quot;&gt;Login&lt;/button&gt;
&lt;script src=&quot;https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js&quot;&gt;&lt;/script&gt;
&lt;script&gt;
// Azure Face API Endpoint e Chave de Assinatura
const endpoint = &#39;my endpoint&#39;;
const subscriptionKey = &#39;my key&#39;;
// Elementos de v&#237;deo e canvas
const video = document.getElementById(&#39;video&#39;);
const canvas = document.getElementById(&#39;canvas&#39;);
const context = canvas.getContext(&#39;2d&#39;);
// Fun&#231;&#227;o para carregar o v&#237;deo
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia || navigator.mediaDevices.getUserMedia || navigator.getUserMedia;
if (navigator.getUserMedia) {
navigator.getUserMedia({ video: true }, stream =&gt; {
video.srcObject = stream;
}, error =&gt; {
console.log(&#39;Erro ao acessar a c&#226;mera: &#39; + error);
});
}
// Fun&#231;&#227;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(&#39;image/jpeg&#39;);
// Enviar a imagem para o Azure Face API
axios.post(`${endpoint}/face/v1.0/detect?returnFaceId=true&amp;returnFaceAttributes=emotion`, {
url: imageData
}, {
headers: {
&#39;Content-Type&#39;: &#39;application/json&#39;,
&#39;Ocp-Apim-Subscription-Key&#39;: subscriptionKey
}
}).then(response =&gt; {
const faceId = response.data[0].faceId;
const emotions = response.data[0].faceAttributes.emotion;
// Verificar as emo&#231;&#245;es para autenticar o usu&#225;rio
if (emotions.happiness &gt; 0.5) {
// Emo&#231;&#227;o de felicidade detectada, autentica&#231;&#227;o bem-sucedida
showMessage(&#39;Usu&#225;rio autenticado com sucesso!&#39;);
} else {
// Emo&#231;&#227;o de felicidade n&#227;o detectada, autentica&#231;&#227;o falhou
showMessage(&#39;Falha na autentica&#231;&#227;o. Por favor, tente novamente.&#39;);
}
}).catch(error =&gt; {
console.log(&#39;Erro na requisi&#231;&#227;o para o Azure Face API: &#39; + error);
showMessage(&#39;Erro na requisi&#231;&#227;o para o Azure Face API. Por favor, tente novamente.&#39;);
});
}
// Fun&#231;&#227;o para exibir mensagens na tela
function showMessage(message) {
const messageDiv = document.getElementById(&#39;message&#39;);
messageDiv.innerHTML = message;
}
// Evento para acionar o reconhecimento facial ao pressionar o bot&#227;o de login
const loginButton = document.getElementById(&#39;loginButton&#39;);
loginButton.addEventListener(&#39;click&#39;, takeSnapshot);
&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;

Azure人脸识别 – 返回403

答案1

得分: 0

Face API返回403错误

上述错误发生在您未被授权使用您尝试从请求中调用的功能时,现在已经阻止了对其的访问。

Face服务的访问受限于符合资格和使用要求,以限制我们的负责任AI原则。要了解速率限制并修改您的使用方式,请参阅Face API 文档

请确保使用适当的身份验证,您可以在我的环境中使用相同的代码,它可以成功运行。

Azure人脸识别 – 返回403

Azure人脸识别 – 返回403

参考资料:

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.

Azure人脸识别 – 返回403

Azure人脸识别 – 返回403

Reference:

Microsoft Azure Cognitive Services Face API error 403 - Microsoft Q&A - romungi-MSFT

Face API return 403 error - Microsoft Q&A - YutongTie-MSFT

huangapple
  • 本文由 发表于 2023年6月1日 06:53:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/76377744.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定