Azure Functions (Serverless Computing) Cognitive Services Vision API Demo

What is Serverless Computing?

Serverless Computing doesn’t really mean there’s no server. Serverless means there’s no server you need to worry about. That might sound like PaaS, but it’s higher level that than. – Scott Hanselman

AWS LambdaAzure Functions  and Azure Logic Apps are the best examples of serverless computing.

Azure Functions is a great way for easily running pieces of code, or “functions,” in the Azure cloud.

All you need need is just the code for the problem at hand, without thinking about a whole application or the infrastructure to run it.

Azure Functions can make development even more easier , productive, and even you can use any of the following development language

Azure Function supports C#, F#, Node.js, Python or PHP.

You are required to Pay only for the time your code runs and trust Azure to scale as needed. It is a great solution for processing data, integrating systems, working with the internet-of-things (IoT), and building simple APIs and microservices.

Azure functions can be considered for tasks like image or order processing, file maintenance, long-running background tasks , or for any tasks that you want to run on a specific schedule.

Azure Functions provides following templates to get you started with some very common scenarios.

  • BlobTrigger – To process Azure Storage blobs when they are added to containers.     Example : You might use this function for image resizing.
  • EventHubTrigger – If you want to respond to events delivered to an Azure Event Hub. Particularly useful in application instrumentation, user experience or workflow processing, and Internet of Things (IoT) scenarios.
  • Generic webhook – You can process webhook HTTP requests from any service that supports webhooks.
  • GitHub webhook – You can respond to events that occur in your GitHub repositories.
  • HTTPTrigger – You can trigger the execution of your code by using an HTTP request.
  • QueueTrigger – You can respond to messages as they arrive in an Azure Storage queue.
  • ServiceBusQueueTrigger – You can easily connect your code to other Azure services or on-premise services by listening to message queues.
  • ServiceBusTopicTrigger – You can even connect your code to other Azure services or on-premise services by subscribing to topics.
  • TimerTrigger – If you want to execute cleanup or other batch tasks on a predefined schedule Azure function is perfect way for you.

Cost of Azure Functions

Azure Functions has two kinds of pricing plans:

  • Consumption plan – When your function runs, Azure provides all of the necessary computational resources. You don’t have to worry about resource management, and you only pay for the time that your code runs.
  • App Service plan – Run your functions just like your web, mobile, and API apps. When you are already using App Service for your other applications, you can run your functions on the same plan at no additional cost.

Ok enough talks lets go straight to code and let us see how soon we can  write and deploy Web API for face detection in pictures.

Vision API Will return following JSON once I uplaod a image of me to azure Function.

api
https://ad.atdmt.com/m/a.html;m=11087206420460;noscript=1

JSON:
[
  {
    "faceId": "13883451-482a-4a35-a0c1-bcd3a25d7674",
    "faceRectangle": {
      "width": 155,
      "height": 155,
      "left": 160,
      "top": 127
    },
    "faceLandmarks": {
      "pupilLeft": {
        "x": 204.3,
        "y": 167.5
      },
      "pupilRight": {
        "x": 273.7,
        "y": 172.2
      },
      "noseTip": {
        "x": 240.8,
        "y": 215.8
      },
      "mouthLeft": {
        "x": 197.6,
        "y": 237.1
      },
      "mouthRight": {
        "x": 268.1,
        "y": 238.4
      },
      "eyebrowLeftOuter": {
        "x": 180.6,
        "y": 148.3
      },
      "eyebrowLeftInner": {
        "x": 235.7,
        "y": 157.1
      },
      "eyeLeftOuter": {
        "x": 191.8,
        "y": 165.5
      },
      "eyeLeftTop": {
        "x": 205.3,
        "y": 160.9
      },
      "eyeLeftBottom": {
        "x": 203.1,
        "y": 172.1
      },
      "eyeLeftInner": {
        "x": 217.5,
        "y": 168.8
      },
      "eyebrowRightInner": {
        "x": 255,
        "y": 161
      },
      "eyebrowRightOuter": {
        "x": 303.5,
        "y": 160.6
      },
      "eyeRightInner": {
        "x": 261,
        "y": 173.7
      },
      "eyeRightTop": {
        "x": 273.7,
        "y": 166.2
      },
      "eyeRightBottom": {
        "x": 273.3,
        "y": 176.8
      },
      "eyeRightOuter": {
        "x": 286.3,
        "y": 172.1
      },
      "noseRootLeft": {
        "x": 232.1,
        "y": 172.2
      },
      "noseRootRight": {
        "x": 253.9,
        "y": 175.3
      },
      "noseLeftAlarTop": {
        "x": 223.7,
        "y": 199
      },
      "noseRightAlarTop": {
        "x": 256.1,
        "y": 202.1
      },
      "noseLeftAlarOutTip": {
        "x": 214.3,
        "y": 210.6
      },
      "noseRightAlarOutTip": {
        "x": 264.3,
        "y": 214.4
      },
      "upperLipTop": {
        "x": 234.3,
        "y": 235.6
      },
      "upperLipBottom": {
        "x": 235.1,
        "y": 240.4
      },
      "underLipTop": {
        "x": 234.5,
        "y": 250.5
      },
      "underLipBottom": {
        "x": 234.5,
        "y": 259.3
      }
    },
    "faceAttributes": {
      "age": 33.3,
      "gender": "male",
      "headPose": {
        "roll": 4.7,
        "yaw": 7.8,
        "pitch": 0
      },
      "smile": 0.602,
      "facialHair": {
        "moustache": 0.2,
        "beard": 0.2,
        "sideburns": 0
      },
      "glasses": "Sunglasses"
    }
  }
]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.