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

Contact

Replications

Did you replicate this project? Share it!

I made one

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

Give feedback

Comments

Similar projects you might like

Winforms+Lattepanda=Control Everything With Your Mouse!
Easy
  • 1,015
  • 6

Protip

If you use other things instead of the LED, then you can use your mouse to control everything!!

One Small Step For a Yedi, One Giant Leap for Mankind
Easy
  • 165
  • 4

Work in progress

Counting your steps with the Calliope Mini. Hearing the Star Wars theme is always a huge motivator.

Cortana Skills and Bot Framework on Raspberry Pi
Easy
  • 369
  • 2

Protip

Using Bot Framework on Raspberry Pi, using Cortana Skills to Echo sent message.

Microsoft Workshop Setup Guide
Easy
  • 953
  • 9

Protip

A collection of screencasts for setting up your laptop for the Hackster/Microsoft IoT Roadshow events.

Sorting Hat: Circuit Playground Express Starter Project
Easy
  • 85
  • 2

Protip

Which Hogwarts House do you belong in? A quick first project for this beginner-friendly board from Adafruit.

The Factory at Exhibition - 4.0 and beyond - [Part 2]
Easy
  • 737
  • 6

Protip

PowerBerry/POWER-KI on 9 Raspberry PI3 and 10 LattePanda with Win10 to make a true 4.0 Control System for a factory that worked at BIE2017.

Add projectSign up / Login