How do I use the Microsoft Video API?

I would like the user to enter a direct video link like http://www.video.com/test.mp4

And as soon as you hit the submit button, you turn to MICROSOFT VIDEO API JSON and get this information.

I was able to create it for images and I will make the code available here, but I am having trouble creating the video.

I would also like to know if I can get this information through "Live Streams", for example, on the example of IP online cameras.

Video call

<!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>

      

IMAGE - OPERATION

<!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>

      

+3


source to share


1 answer


I would also like to know if I can get this information through "Live Streams", for example, on the example of IP online cameras.

According to the Video API doc , if we post a video link. The video will be uploaded to the service for analysis. It is not suitable for Live Streams.



If you want to analyze video in real time, you need to capture frames from the video on your client side and analyze the video frame by frame. Here is a sample Live Camera code using C #.

0


source







All Articles