DasCognitiveServices

DasCognitiveServices © MIT

Detect human face details with the help of an Arduino. Store detection results in into cloud data storage.

  • 17,182 views
  • 8 comments
  • 69 respects

Components and supplies

Apps and online services

About this project

Next generation applications will certainly have some AI services into their existing functionality. In this project Arduino is used to activate when the picture is taken based on a distance sensor.

Microsoft Cognitive Services - Face API

Face API is a cloud-based API that provides the most advanced algorithms for face detection and recognition. The main functionality of Face API can be divided into two categories: face detection with attributes extraction and face recognition.

First you have to apply for a Key that will be used in your application, if you have more than 30,000 transactions per month and less than 20 per minute is FREE else you could get it from Azure.

You can learn more about FaceAPI and get some sample codes from here https://www.microsoft.com/cognitive-services/en-us/face-api/documentation/overview

Web Camera 

I've been using a Microsoft Live camera connected to a PC and WebCam Library for WinForm and WPF, this control is pretty easy to use and implement into your applications 

Developer can add one line of code for display video from webcam and capture image from webcam. It provide dialog for resolution setting and advance setting (Flip,Rotate, Brightness etc.) by adding one line of code.

Application will also save locally pictures on daily folders and generates html reports.

Arduino Distance Trigger

I wanted to get the picture when someone is at a certain distance. For this I've been using a MKR1000 + HC-SR04 distance sensor.

  • MKR - SENSOR
  • A0 - ECHO
  • A1 - TRIG
  • 5V - VCC
  • GND - GND

Code samples you can find bellow - just modify the Wi-fi connection details and also proper libraries such as aREST, WiFi101.

DasData storage

You can easily store result into a data channel offered for free by DasData

Click on the duplicate dataset and enter your email, change the key codes into your code and you're ready to go.

Code

aRest - DistanceC/C++
/*
 * 
  Face detectino - gets distance from HC-SR04 Sensor using
  aREST Library for the Arduino/Genuino MKR1000 board. 
  Written in 2016 by Marco Schwartz under a GPL license.
*/

// Import required libraries
#include <SPI.h>
#include <WiFi101.h>
#include <aREST.h>
#define echoPin A0 // Echo pin A0
#define trigPin A1 // Trigger pin A1

long duration ; // duration to calculate distance
int HR_dist = 0; // Calculated distance

int minimumRange=5; //Min Sonar range
int maximumRange=200; //Max Sonar range

// Status
int status = WL_IDLE_STATUS;
 
// Create aREST instance
aREST rest = aREST();

// WiFi parameters
char ssid[] = "DASDATA";
char password[] = "WIFI_PASSWORD";

// The port to listen for incoming TCP connections
#define LISTEN_PORT           80

// Create an instance of the server
WiFiServer server(LISTEN_PORT);

// Declare functions to be exposed to the API
int ledControl(String command);

void setup(void)
{
  // Start Serial
//  Serial.begin(115200); 
 pinMode(trigPin, OUTPUT);
 pinMode(echoPin, INPUT);
  // Init variables and expose them to REST API

  // Function to be exposed
  rest.function("led",ledControl);

  // Give name and ID to device
  rest.set_id("1");
  rest.set_name("dasX");

  // Connect to WiFi
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    status = WiFi.begin(ssid, password);

    // Wait 10 seconds for connection:
    delay(5000);
  }
  Serial.println("WiFi connected");

  // Start the server
  server.begin();
  Serial.println("Server started");
 
  // Print the IP address
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip); 

  rest.variable("Distance",&HR_dist );
  
}

void loop() {
  getDistance();
  // Handle REST calls
  WiFiClient client = server.available();
  if (!client) {
    return;
  }
  while(!client.available()){
    delay(1);
  }
  rest.handle(client);
  
}

void getDistance() {
  digitalWrite(trigPin,LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin,HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin,LOW);

  duration = pulseIn(echoPin,HIGH);
  //calculate distance
  HR_dist = duration/58.2;

  if (HR_dist >= maximumRange || HR_dist <= minimumRange) {
    //Serial.println("0");
    }
    else {
  Serial.println(HR_dist); 
      }

      delay(100);
  }

// Custom function accessible by the API
int ledControl(String command) {

  // Get state from command
  int state = command.toInt();

  digitalWrite(6,state);
  return 1;
}
DasCognitive services
Visual Studio - project

Schematics

face_detection.pdf

Comments

Similar projects you might like

MKR1000 Temp and Humidity Sensor

Project tutorial by Don Coleman

  • 18,134 views
  • 11 comments
  • 31 respects

DasFilisera Green House

Project tutorial by Marius Dima

  • 9,092 views
  • 5 comments
  • 62 respects

PlantAnalyzer

Project in progress by Ryan Michaud

  • 8,005 views
  • 3 comments
  • 33 respects

Azure Stream Analytics saving lives!

Project tutorial by Asad Zia

  • 6,413 views
  • 3 comments
  • 26 respects

TIA Weak Artificial Intelligence IoT Assistant

Project tutorial by Adam Milton-Barker

  • 3,898 views
  • 0 comments
  • 20 respects

Thundercatch IoT Network

Project tutorial by Christos Chatzigeorgiou

  • 3,571 views
  • 1 comment
  • 10 respects
Add projectSign up / Login