我希望用户插入视频的直接链接,例如http://www.video.com/test.mp4
单击“提交”按钮后,您将查阅MICROSOFT VIDEO API JSON并获取此信息。
我能够为图像创建一个,我将在这里提供代码,但是我在为视频创建时遇到了很多麻烦。
我还想知道我是否可以通过“直播流”获取此信息,例如IP在线相机的示例。
视频
<!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>
图片 - 工作
<!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>
答案 0 :(得分:0)
我还想知道我是否可以通过“直播流”获取此信息,例如IP在线相机的示例。
根据Video API的文件,如果我们提交视频链接。视频将上传到服务进行分析。它不适合直播。
如果您想实时分析视频,则需要从客户端的视频中捕获帧并逐帧分析视频。以下是使用C#的Live Camera的代码示例。