Javascript 如何使用Microsoft视频API?
我希望用户插入视频的直接链接,如 只要单击“提交”按钮,您就会查阅MICROSOFT视频API JSON并获得此信息 我能够为图像创建一个,我将在这里提供代码,但是我在为视频创建时遇到了很多问题 我还想知道我是否可以通过“实时流”获取这些信息,例如在线摄像机的IP VÍDEOJavascript 如何使用Microsoft视频API?,javascript,json,azure,microsoft-cognitive,Javascript,Json,Azure,Microsoft Cognitive,我希望用户插入视频的直接链接,如 只要单击“提交”按钮,您就会查阅MICROSOFT视频API JSON并获得此信息 我能够为图像创建一个,我将在这里提供代码,但是我在为视频创建时遇到了很多问题 我还想知道我是否可以通过“实时流”获取这些信息,例如在线摄像机的IP VÍDEO <!DOCTYPE html> <html> <head> <title>JSSample</title> <script src="htt
<!DOCTYPE html>
<html>
<head>
<title>JSSample</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
</head>
<body>
<script type="text/javascript">
$(function() {
var params = {
// Request parameters
"sensitivityLevel": "{string}",
"frameSamplingValue": "{number}",
"detectionZones": "{string}",
"detectLightChange": "{boolean}",
"mergeTimeThreshold": "{number}",
};
$.ajax({
url: "https://westus.api.cognitive.microsoft.com/video/v1.0/detectmotion?" + $.param(params),
beforeSend: function(xhrObj){
// Request headers
xhrObj.setRequestHeader("Content-Type","application/json");
xhrObj.setRequestHeader("Ocp-Apim-Subscription-Key","INSERT KEY");
},
type: "POST",
// Request body
data: "{body}",
})
.done(function(data) {
alert("success");
})
.fail(function() {
alert("error");
});
});
</script>
</body>
</html>
JSSample
$(函数(){
变量参数={
//请求参数
“敏感度级别”:“{string}”,
“frameSamplingValue”:“{number}”,
“检测区域”:“{string}”,
“detectLightChange”:“{boolean}”,
“mergeTimeThreshold”:“{number}”,
};
$.ajax({
url:“https://westus.api.cognitive.microsoft.com/video/v1.0/detectmotion?“+$.param(params),
发送前:函数(xhrObj){
//请求头
setRequestHeader(“内容类型”、“应用程序/json”);
setRequestHeader(“Ocp Apim订阅密钥”、“插入密钥”);
},
类型:“POST”,
//请求主体
数据:“{body}”,
})
.完成(功能(数据){
警惕(“成功”);
})
.fail(函数(){
警报(“错误”);
});
});
图像处理
<!DOCTYPE html>
<html>
<head>
<title>TESTANDO DETECTOR DE FACE EM FOTOS</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
</head>
<body>
<script type="text/javascript">
function processImage() {
// **********************************************
// *** Update or verify the following values. ***
// **********************************************
// Replace the subscriptionKey string value with your valid subscription key.
var subscriptionKey = "INSERT KEY";
// Replace or verify the region.
//
// You must use the same region in your REST API call as you used to obtain your subscription keys.
// For example, if you obtained your subscription keys from the westus region, replace
// "westcentralus" in the URI below with "westus".
//
// NOTE: Free trial subscription keys are generated in the westcentralus region, so if you are using
// a free trial subscription key, you should not need to change this region.
var uriBase = "https://westcentralus.api.cognitive.microsoft.com/face/v1.0/detect";
// Request parameters.
var params = {
"returnFaceId": "true",
"returnFaceLandmarks": "false",
"returnFaceAttributes": "age,gender,headPose,smile,facialHair,glasses,emotion,hair,makeup,occlusion,accessories,blur,exposure,noise",
};
// Display the image.
var sourceImageUrl = document.getElementById("inputImage").value;
document.querySelector("#sourceImage").src = sourceImageUrl;
// Perform the REST API call.
$.ajax({
url: uriBase + "?" + $.param(params),
// Request headers.
beforeSend: function(xhrObj){
xhrObj.setRequestHeader("Content-Type","application/json");
xhrObj.setRequestHeader("Ocp-Apim-Subscription-Key", subscriptionKey);
},
type: "POST",
// Request body.
data: '{"url": ' + '"' + sourceImageUrl + '"}',
})
.done(function(data) {
// Show formatted JSON on webpage.
$("#responseTextArea").val(JSON.stringify(data, null, 2));
})
.fail(function(jqXHR, textStatus, errorThrown) {
// Display error message.
var errorString = (errorThrown === "") ? "Error. " : errorThrown + " (" + jqXHR.status + "): ";
errorString += (jqXHR.responseText === "") ? "" : (jQuery.parseJSON(jqXHR.responseText).message) ?
jQuery.parseJSON(jqXHR.responseText).message : jQuery.parseJSON(jqXHR.responseText).error.message;
alert(errorString);
});
};
</script>
<h1>Detectar Faces:</h1>
Entre com a URL para <strong>Analisar o Rosto</strong>.
<br><br>
Imagem para Analise: <input type="text" name="inputImage" id="inputImage" value="" />
<button onclick="processImage()">Analizar face</button>
<br><br>
<div id="wrapper" style="width:1020px; display:table;">
<div id="jsonOutput" style="width:600px; display:table-cell;">
Resposta
<br><br>
<textarea id="responseTextArea" class="UIInput" style="width:580px; height:400px;"></textarea>
</div>
<div id="imageDiv" style="width:420px; display:table-cell;">
Imagem Utilizada
<br><br>
<img id="sourceImage" width="400" />
</div>
</div>
</body>
</html>
TESTANDO正面EM FOTOS探测器
函数processImage(){
// **********************************************
//***更新或验证以下值***
// **********************************************
//用有效的订阅密钥替换subscriptionKey字符串值。
var subscriptionKey=“插入键”;
//更换或验证该区域。
//
//在REST API调用中必须使用与获取订阅密钥相同的区域。
//例如,如果您从westus地区获得订阅密钥,请替换
//以下URI中的“westcentralus”和“westus”。
//
//注意:免费试用订阅密钥是在westcentralus地区生成的,因此如果您使用
//免费试用订阅密钥,您不需要更改此区域。
变量uriBase=”https://westcentralus.api.cognitive.microsoft.com/face/v1.0/detect";
//请求参数。
变量参数={
“returnFaceId”:“true”,
“returnFaceLandmarks”:“false”,
“returnFaceAttributes”:“年龄、性别、头型、微笑、面部头发、眼镜、情绪、头发、化妆、遮挡、配饰、模糊、曝光、噪音”,
};
//显示图像。
var sourceImageUrl=document.getElementById(“inputImage”).value;
document.querySelector(“#sourceImage”).src=sourceImageUrl;
//执行RESTAPI调用。
$.ajax({
url:uriBase+“?”+$.param(params),
//请求头。
发送前:函数(xhrObj){
setRequestHeader(“内容类型”、“应用程序/json”);
setRequestHeader(“Ocp Apim订阅密钥”,subscriptionKey);
},
类型:“POST”,
//请求主体。
数据:“{”url:“+”+sourceImageUrl+“}”,
})
.完成(功能(数据){
//在网页上显示格式化的JSON。
$(“#responseTextArea”).val(JSON.stringify(data,null,2));
})
.fail(函数(jqXHR、textStatus、errorshown){
//显示错误消息。
var errorString=(errorSprown==“”)?“Error.”:errorSprown+“(“+jqXHR.status+”)”;
errorString+=(jqXHR.responseText==“”)吗?“”:(jQuery.parseJSON(jqXHR.responseText.message)?
parseJSON(jqXHR.responseText).message:jQuery.parseJSON(jqXHR.responseText).error.message;
警报(错误字符串);
});
};
Detectar面:
请访问URL paraAnalisar o Rosto。
Imagem段落分析:
分析面
Resposta
实用图像
我还想知道我是否可以通过“实时流”获取这些信息,例如在线摄像机的IP
根据的文件,如果我们提交一个视频链接。视频将上载到服务进行分析。它不适用于活流
如果要实时分析视频,需要在客户端捕获视频帧并逐帧分析视频。下面是使用C#的代码示例 但是我如何在javascript和html5中做到这一点呢?你需要寻找一个javascript库,它可以从实时流中捕获帧,并使用你发布的图像的工作代码分析这些帧(图像)。你能帮我一下吗?我正试图为网络做这件事。我错过了这个JSON的视频API。信息不多。我只需要做与图像相同的事情,插入视频的url,提取所有信息并返回结果。