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

Running Native .NET Core Apps on Raspberry Pi (ARM)
Easy
  • 2,335
  • 28

Protip

Finally you can run your .NET Core apps on ARM versions of Ubuntu 16.04, 14.04 and Windows 10 IoT. We'll be making a Pi calculation app.

Windows 98 Wrist Watch
Easy
  • 3,454
  • 24

Full instructions

Everyone's favourite Operating System. On your wrist!

The Factory at Exhibition - 4.0 and beyond - [Part 1]
Easy
  • 398
  • 4

Work in progress

Control and Supervision of a true 4.0 Working Factory that will be visible in a public Exhibition using Raspberry Pi, PowerBerry, Win10Iot

Windows 10 IoT Temperature SMT172
Easy
  • 1,391
  • 6

Protip

Read temperature from sensor (SMT172) with Windows 10 IOT, Raspberry Pi and C# UWP.

PlatformIO for Visual Studio Code
Easy
  • 60
  • 0

Protip

PlatformIO is an open source ecosystem for IoT development. And now, PlatformIO for Visual Studio Code is coming!

Get Stared: Intel Edison, Azure IoT Hub and Blink App
Easy
  • 188
  • 1

Full instructions

This is a getting started guide on how to use Intel Edison to send data to Azure IoT hub, store data in Azure Storage thru Azure functions.

Add projectSign up / Login
Respect project