Things used in this project

Hardware components:
DFRobot LattePanda
×1
Software apps and online services:
Microsoft Cognitive Services

Code

Code ExampleC#
Don't forget to replace the API key!
using System;
using System.IO;
using System.Net.Http.Headers;
using System.Net.Http;

namespace CSHttpClientSample
{
    static class Program
    {
        static void Main()
        {
            Console.Write("Enter the location of your picture:");
            string imageFilePath = Console.ReadLine();

            MakeAnalysisRequest(imageFilePath);

            Console.WriteLine("\n\n\nWait for the result below, then hit ENTER to exit...\n\n\n");
            Console.ReadLine();
        }

        static byte[] GetImageAsByteArray(string imageFilePath)
        {
            FileStream fileStream = new FileStream(imageFilePath, FileMode.Open, FileAccess.Read);
            BinaryReader binaryReader = new BinaryReader(fileStream);
            return binaryReader.ReadBytes((int)fileStream.Length);
        }

        static async void MakeAnalysisRequest(string imageFilePath)
        {
            var client = new HttpClient();

            // Request headers - replace this example key with your valid key.
            client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "Enter your apikey here");

            // Request parameters and URI string.
            string queryString = "returnFaceId=true&returnFaceLandmarks=false&returnFaceAttributes=age,gender";
            string uri = "https://westus.api.cognitive.microsoft.com/face/v1.0/detect?" + queryString;

            HttpResponseMessage response;
            string responseContent;

            // Request body. Try this sample with a locally stored JPEG image.
            byte[] byteData = GetImageAsByteArray(imageFilePath);

            using (var content = new ByteArrayContent(byteData))
            {
                // This example uses content type "application/octet-stream".
                // The other content types you can use are "application/json" and "multipart/form-data".
                content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
                response = await client.PostAsync(uri, content);
                responseContent = response.Content.ReadAsStringAsync().Result;
            }

            //A peak at the JSON response.
            Console.WriteLine(responseContent);
        }
    }
}

Credits

13245269 10153668742428652 5499237831655557257 n
Matt Jani

tech head, tinkerer, robo-wrangler

Replications

Did you replicate this project? Share it!

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

Theremino HAL 7.2 – Hardware Abstraction Layer.
Easy
  • 47
  • 3

Full instructions

The HAL connects the hardware of InOut with high-level software via USB and Slots.

Theremino, Windows 10 and HAL. The link with the real world
Easy
  • 131
  • 3

Full instructions

Windows 10 and the HAL (Hardware Abstraction Layer). How to communicate with sensors and actuators in the most easy way.

Read the signal of the AB quadrature encoder with Theremino.
Easy
  • 250
  • 3

Full instructions

The simplest way to read A B quadrature encoder using Theremino Master.

Theremino SlotViewer, the simplest way to manage slots.
Easy
  • 137
  • 4

Full instructions

Theremino SlotViewer is the very simple way to manage the slots, read the value and modify in real time the value of each slot.

Eddystone beacons with the micro:bit
Easy
  • 172
  • 2

Protip

Experiment with the Physical Web by turning your micro:bit into an Eddystone beacon.

Simple Light LED using Theremino Master
Easy
  • 314
  • 4

The simplest way to switch on a LED or dimming it.

Add projectSign up / Login
Respect project