Advanced Facial Attributes Detection

Overview

Cloudinary provides an add-on for advanced face attribute detection capabilities, fully integrated into Cloudinary's image management and manipulation pipeline. With the Advanced Facial Attribute Detection add-on, you can extend the Cloudinary features that involve semantic photo data extraction, image cropping and the positioning of image overlays. When using the Advanced Facial Attribute Detection add-on, your images are further processed and many advanced face attributes are automatically extracted. Cloudinary can then use these additional details to smartly crop, position, rotate and overlay images.

Cloudinary is a cloud-based service that provides an end-to-end image management solution including uploads, storage, manipulations, optimizations and delivery, and offers a rich set of image management, manipulation, analysis and cropping capabilities.

The Advanced Facial Attribute Detection add-on is an integrated face detection solution that utilizes Project Oxford developed by Microsoft. Project Oxford provides high precision face location detection with state-of-the-art cloud-based algorithms that can detect up to 64 human faces in an image. The detected faces are returned with rectangles (left, top, width and height) indicating the location of faces in the image in pixels, the exact position details of the eyes, mouth, eyebrows, nose and lips, as well as a series of face related attributes from each face such as pose, gender and age.

Face attribute detection on upload

The Advanced Facial Attribute Detection add-on is very simple to use. The extensive list of face attributes can be extracted from any photo when calling Cloudinary's upload API and setting the detection parameter to adv_face. For example, take a look at the following photo that we want to upload to Cloudinary's demo account:

photo to upload

When calling Cloudinary's API to upload the photo, the detection parameter is added to extract the face attributes in the uploaded photo:

Ruby:
Cloudinary::Uploader.upload("coupled.jpg", 
  :detection => "adv_face")
PHP:
\Cloudinary\Uploader::upload("coupled.jpg", 
  array("detection" => "adv_face"));
Python:
cloudinary.uploader.upload("coupled.jpg",
  detection = "adv_face")
Node.js:
cloudinary.uploader.upload("coupled.jpg", 
  function(result) { console.log(result); }, 
  { detection: "adv_face" });
Java:
cloudinary.uploader().upload("coupled.jpg", 
  ObjectUtils.asMap("detection", "adv_face"));

The JSON snippet below contains an excerpt of the results of applying automatic face attribute detection on the uploaded image. The response includes very detailed information regarding each of the faces that were automatically detected in the photo:

  • bounding_box - The bounding box surrounding a detected face.
  • smile - The likelihood that the person is smiling.
  • head_pose - The way the face is positioned in 3D.
  • gender - Whether the person is a male or a female.
  • age - Estimated age of the person.
  • facial_hair - The likelihood that the person has a moustache, beard, and/or sideburns, respectively.
  • glasses - Whether the person is wearing glasses.
  • emotion - The likelihood that the person's expression implies certain emotions.
  • blur - The amount of blur on the face.
  • exposure - The photo exposure on the face.
  • noise - A general and numeric evaluation of the amount of photographic noise on the face.
  • makeup - Whether the person is wearing eye and/or lip makeup.
  • accessories - An array of accessory items (if any) detected around the face area, such as headwear, glasses, or mask.
  • occlusion - Whether the forehead, eyes, or mouth is blocked, for example by a scarf, hat, or mask.
  • hair - Information about the hair, including whether the hair is visible in the photo, the likelihood that the person is bald, and the likelihood that the person's hair is a particular color.
  • facial_landmarks - Exact position details of specific elements of the mouth, eybrows, eyes, and nose.
{
...
 "info"=>
  {"detection"=>
    {"adv_face"=>
      {"status"=>"complete",
       "data"=>
        [{"bounding_box"=>
           {"top"=>95.0, "left"=>104.0,  "width"=>48.0, "height"=>48.0},
          "attributes"=>
           {"smile"=>0.999,
            "head_pose"=>{"pitch"=>0.0, "roll"=>-7.9, "yaw"=>10.8},
            "gender"=>"male",
            "age"=>55.8,
            "facial_hair"=>{"moustache"=>0.0, "beard"=>0.0, "sideburns"=>0.0},
            "glasses"=>"NoGlasses",
            "emotion"=>
             {"anger"=>0.0,
              "contempt"=>0.0,
              "disgust"=>0.001,
              "fear"=>0.0,
              "happiness"=>0.999,
              "neutral"=>0.0,
              "sadness"=>0.0,
              "surprise"=>0.0},
            "blur"=>{"blurLevel"=>"medium", "value"=>0.41},
            "exposure"=>{"exposureLevel"=>"goodExposure", "value"=>0.66},
            "noise"=>{"noiseLevel"=>"low", "value"=>0.0},
            "makeup"=>{"eyeMakeup"=>false, "lipMakeup"=>false},
            "accessories"=>[],
            "occlusion"=>
             {"foreheadOccluded"=>false,
              "eyeOccluded"=>false,
              "mouthOccluded"=>false},
            "hair"=>
             {"bald"=>0.21,
              "invisible"=>false,
              "hairColor"=>
               [{"color"=>"gray", "confidence"=>0.98},
                {"color"=>"black", "confidence"=>0.67},
                {"color"=>"brown", "confidence"=>0.39},
                {"color"=>"other", "confidence"=>0.38},
                {"color"=>"blond", "confidence"=>0.18},
                {"color"=>"red", "confidence"=>0.12}]}},
          "facial_landmarks"=>
           {"mouth"=>
             {"left"=>{"x"=>118.1, "y"=>132.0},
              "right"=>{"x"=>139.2, "y"=>129.4},
              "under_lip"=>
               {"bottom"=>{"x"=>130.6, "y"=>135.2},
                "top"=>{"x"=>130.2, "y"=>132.2}},
              "upper_lip"=>
               {"bottom"=>{"x"=>130.2, "y"=>129.2},
                "top"=>{"x"=>129.9, "y"=>127.3}}},
            "eyebrow"=>
             {"left_outer"=>{"x"=>105.7, "y"=>108.2},
              "left_inner"=>{"x"=>121.9, "y"=>105.5},
              "right_inner"=>{"x"=>131.6, "y"=>104.4},
              "right_outer"=>{"x"=>145.9, "y"=>104.7}},
            "eye"=>
             {"left_outer"=>{"x"=>111.9, "y"=>111.3},
              "left_top"=>{"x"=>115.5, "y"=>109.3},
              "left_bottom"=>{"x"=>115.6, "y"=>111.6},
              "left_inner"=>{"x"=>119.3, "y"=>110.7},
              "right_inner"=>{"x"=>132.9, "y"=>108.9},
              "right_top"=>{"x"=>136.4, "y"=>107.0},
              "right_bottom"=>{"x"=>136.4, "y"=>109.4},
              "right_outer"=>{"x"=>139.8, "y"=>108.6},
              "left_pupil"=>{"x"=>115.0, "y"=>110.4},
              "right_pupil"=>{"x"=>136.3, "y"=>107.8}},
            "nose"=>
             {"tip"=>{"x"=>130.1, "y"=>119.2},
              "root_left"=>{"x"=>123.5, "y"=>110.4},
              "root_right"=>{"x"=>130.2, "y"=>109.5},
              "left_alar_top"=>{"x"=>122.8, "y"=>117.1},
              "right_alar_top"=>{"x"=>133.1, "y"=>116.1},
              "left_alar_out_tip"=>{"x"=>120.7, "y"=>120.6},
              "right_alar_out_tip"=>{"x"=>136.2, "y"=>119.2}}}},
        {"bounding_box"=>
          {"top"=>148.0, "left"=>144.0, "width"=>43.0, "height"=>43.0},
          "attributes"=>
           {"smile"=>1.0,
            "head_pose"=>{"pitch"=>0.0, "roll"=>-12.6, "yaw"=>-14.9},
            "gender"=>"female",
            "age"=>40.2,
            ...
            ...
            ...
           }
        }
      }]
    }
  }
}

Face attribute detection after uploading

The example above shows how to automatically detect face attributes of photos during their upload process. Alternatively, you can use Cloudinary's Admin API to apply automatic face attribute detection to already uploaded images, based on their public IDs. The following code sample uses Cloudinary's update API to apply face attribute detection to the uploaded image that has the 'coupled' public ID.

Ruby:
Cloudinary::Api.update("coupled", 
  :detection => "adv_face")
PHP:
\Cloudinary\Api::update("coupled", 
  array("detection" => "adv_face"));
Python:
cloudinary.api.update("coupled",
  detection = "adv_face")
Node.js:
cloudinary.api.update("coupled", 
  function(result) { console.log(result); }, 
  { detection: "adv_face" });
Java:
cloudinary.api().update("coupled", 
  ObjectUtils.asMap("detection", "adv_face"));

The face attributes that were previously extracted either using the 'upload' or 'update' API, are also available using the Admin API's show resource details method:

Ruby:
Cloudinary::Api.resource('coupled')
PHP:
$api->resource("coupled");
Python:
cloudinary.api.resource("coupled")
Node.js:
cloudinary.api.resource('coupled', 
  function(result)  { console.log(result) });
Java:
cloudinary.api().resource("coupled", ObjectUtils.emptyMap());

Face detection based cropping

Cloudinary provides a large set of image manipulation and cropping options. Based on the position of facial attributes detected by the Advanced Facial Attribute Detection add-on, Cloudinary can crop your images to focus on the detected faces, while providing a large set of image transformation and cropping options when using a Cloudinary delivery URL or calling Cloudinary's image API.

To focus an automatic crop on the detected faces, simply set the crop parameter to thumb, fill or crop and the gravity parameter to adv_faces (set gravity to adv_face for focusing on the single largest detected face in the image).

The following code sample creates a 150x150 thumbnail of the coupled image that is generated using face-detection based cropping. The gravity parameter is set to adv_faces while the crop mode is set to thumb.

Ruby:
cl_image_tag("coupled.jpg", :gravity=>"adv_faces", :width=>150, :height=>150, :crop=>"thumb")
PHP:
cl_image_tag("coupled.jpg", array("gravity"=>"adv_faces", "width"=>150, "height"=>150, "crop"=>"thumb"))
Python:
CloudinaryImage("coupled.jpg").image(gravity="adv_faces", width=150, height=150, crop="thumb")
Node.js:
cloudinary.image("coupled.jpg", {gravity: "adv_faces", width: 150, height: 150, crop: "thumb"})
Java:
cloudinary.url().transformation(new Transformation().gravity("adv_faces").width(150).height(150).crop("thumb")).imageTag("coupled.jpg")
JS:
cl.imageTag('coupled.jpg', {gravity: "adv_faces", width: 150, height: 150, crop: "thumb"}).toHtml();
jQuery:
$.cloudinary.image("coupled.jpg", {gravity: "adv_faces", width: 150, height: 150, crop: "thumb"})
React:
<Image publicId="coupled.jpg" >
        <Transformation gravity="adv_faces" width="150" height="150" crop="thumb" />
</Image>
Angular:
<cl-image public-id="coupled.jpg" >
        <cl-transformation gravity="adv_faces" width="150" height="150" crop="thumb">
        </cl-transformation>
</cl-image>
.Net:
cloudinary.Api.UrlImgUp.Transform(new Transformation().Gravity("adv_faces").Width(150).Height(150).Crop("thumb")).BuildImageTag("coupled.jpg")
150x150 thumbnail of faces cropped with the Advanced Facial Attribute Detection add-on

Alternatively, you can crop an image based on the single most visible face in a photo. The following code sample generates and delivers a 100x100 thumbnail containing a single face. The gravity parameter is set to adv_face while the crop mode is set to thumb.

Ruby:
cl_image_tag("coupled.jpg", :gravity=>"adv_face", :width=>100, :height=>100, :crop=>"thumb")
PHP:
cl_image_tag("coupled.jpg", array("gravity"=>"adv_face", "width"=>100, "height"=>100, "crop"=>"thumb"))
Python:
CloudinaryImage("coupled.jpg").image(gravity="adv_face", width=100, height=100, crop="thumb")
Node.js:
cloudinary.image("coupled.jpg", {gravity: "adv_face", width: 100, height: 100, crop: "thumb"})
Java:
cloudinary.url().transformation(new Transformation().gravity("adv_face").width(100).height(100).crop("thumb")).imageTag("coupled.jpg")
JS:
cl.imageTag('coupled.jpg', {gravity: "adv_face", width: 100, height: 100, crop: "thumb"}).toHtml();
jQuery:
$.cloudinary.image("coupled.jpg", {gravity: "adv_face", width: 100, height: 100, crop: "thumb"})
React:
<Image publicId="coupled.jpg" >
        <Transformation gravity="adv_face" width="100" height="100" crop="thumb" />
</Image>
Angular:
<cl-image public-id="coupled.jpg" >
        <cl-transformation gravity="adv_face" width="100" height="100" crop="thumb">
        </cl-transformation>
</cl-image>
.Net:
cloudinary.Api.UrlImgUp.Transform(new Transformation().Gravity("adv_face").Width(100).Height(100).Crop("thumb")).BuildImageTag("coupled.jpg")
100x100 thumbnail of a single face cropped with the Advanced Facial Attribute Detection add-on

Face detection with signed URLs

Cloudinary's dynamic image manipulation URLs are quite powerful, however, due to the potential costs of users accessing unplanned dynamic URLs with the Advanced Facial Attribute Detection cropping directives, we request that you sign your image manipulation URLs using Cloudinary's authenticated API and with the sign_url parameter set to true.

Note you can create dynamic unsigned image manipulation URLs based on Advanced Facial Attribute Detection as long as you first extract the face attributes during upload or by using the Admin API.

For example, the following code snippet generates a signed URL that can be used when the facial attributes have not been previously extracted:

Ruby:
cloudinary_url("coupled.jpg", :crop => "thumb", 
        :width => 100, :height => 100,
        :gravity => "adv_face",
        :sign_url => true)
PHP:
cloudinary_url("coupled.jpg", 
        array("crop" => "thumb", "width" => 100, "height" => 100,
              "gravity" => "adv_face",
              "sign_url" => true));
Python:
cloudinary.CloudinaryImage("coupled.jpg").build_url(
        crop = "thumb", width = 100, height = 100, 
        gravity = "adv_face",
        sign_url = True)
Node.js:
cloudinary.url("coupled.jpg", 
        { crop: "thumb", width: 100, height: 100, 
          gravity: "adv_face",
          sign_url: true });
Java:
cloudinary.url().transformation(
        new Transformation().crop("thumb").width(100).height(100).
          gravity("adv_face")).
          signed(true).generate("coupled.jpg");

The code above dynamically generates the following signed URL:

As you can see, the generated Cloudinary URL includes a signature component (s--vnhlc4WH--). Only URLs with a valid signature will be approved for on-the-fly image manipulation using advanced facial attribute detection.

Eyes detection based cropping

In addition to face-detection based cropping, Cloudinary can dynamically crop your images based on the position of detected eyes. Simply set the gravity parameter to adv_eyes (g_adv_eyes for URLs) to center the image on the detected eyes. The example below delivers a 100x40 thumbnail centered on the eyes of the woman in the photo.

Original photo

Ruby:
cl_image_tag("face1.jpg", :width=>100, :height=>40, :gravity=>"adv_eyes", :crop=>"thumb")
PHP:
cl_image_tag("face1.jpg", array("width"=>100, "height"=>40, "gravity"=>"adv_eyes", "crop"=>"thumb"))
Python:
CloudinaryImage("face1.jpg").image(width=100, height=40, gravity="adv_eyes", crop="thumb")
Node.js:
cloudinary.image("face1.jpg", {width: 100, height: 40, gravity: "adv_eyes", crop: "thumb"})
Java:
cloudinary.url().transformation(new Transformation().width(100).height(40).gravity("adv_eyes").crop("thumb")).imageTag("face1.jpg")
JS:
cl.imageTag('face1.jpg', {width: 100, height: 40, gravity: "adv_eyes", crop: "thumb"}).toHtml();
jQuery:
$.cloudinary.image("face1.jpg", {width: 100, height: 40, gravity: "adv_eyes", crop: "thumb"})
React:
<Image publicId="face1.jpg" >
        <Transformation width="100" height="40" gravity="adv_eyes" crop="thumb" />
</Image>
Angular:
<cl-image public-id="face1.jpg" >
        <cl-transformation width="100" height="40" gravity="adv_eyes" crop="thumb">
        </cl-transformation>
</cl-image>
.Net:
cloudinary.Api.UrlImgUp.Transform(new Transformation().Width(100).Height(40).Gravity("adv_eyes").Crop("thumb")).BuildImageTag("face1.jpg")
Thumbnail centered on eyes using Advanced Facial Attribute Detection

Eyes detection for accurate red eye removal

Cloudinary's rich manipulation capabilities already allow you to automate red eye removal by setting the effect parameter to redeye (e_redeye for URLs). This enables smart red eye removal algorithms to be automatically applied on-the-fly to uploaded images.

In order to get even better quality results, you can use Cloudinary’s Advanced Facial Attribute Detection add-on for eye detection together with the red eye removal effect. The add-on can automatically detect where eyes are located in a photo and then the red eye removal algorithm can be applied in a more precise way: simply set the effect parameter to adv_redeye (e_adv_redeye for URLs).

For example, an image named redeye was uploaded to Cloudinary. A cropped 300x80 thumbnail of the photo centered on the eyes only for illustration is displayed below:

Ruby:
cl_image_tag("redeye.jpg", :width=>300, :height=>80, :gravity=>"adv_eyes", :crop=>"thumb")
PHP:
cl_image_tag("redeye.jpg", array("width"=>300, "height"=>80, "gravity"=>"adv_eyes", "crop"=>"thumb"))
Python:
CloudinaryImage("redeye.jpg").image(width=300, height=80, gravity="adv_eyes", crop="thumb")
Node.js:
cloudinary.image("redeye.jpg", {width: 300, height: 80, gravity: "adv_eyes", crop: "thumb"})
Java:
cloudinary.url().transformation(new Transformation().width(300).height(80).gravity("adv_eyes").crop("thumb")).imageTag("redeye.jpg")
JS:
cl.imageTag('redeye.jpg', {width: 300, height: 80, gravity: "adv_eyes", crop: "thumb"}).toHtml();
jQuery:
$.cloudinary.image("redeye.jpg", {width: 300, height: 80, gravity: "adv_eyes", crop: "thumb"})
React:
<Image publicId="redeye.jpg" >
        <Transformation width="300" height="80" gravity="adv_eyes" crop="thumb" />
</Image>
Angular:
<cl-image public-id="redeye.jpg" >
        <cl-transformation width="300" height="80" gravity="adv_eyes" crop="thumb">
        </cl-transformation>
</cl-image>
.Net:
cloudinary.Api.UrlImgUp.Transform(new Transformation().Width(300).Height(80).Gravity("adv_eyes").Crop("thumb")).BuildImageTag("redeye.jpg")
redeye example photo

Adding the redeye effect parameter and setting its value to adv_redeye delivers the following image:

Ruby:
cl_image_tag("redeye.jpg", :transformation=>[
  {:effect=>"adv_redeye"},
  {:width=>300, :height=>80, :gravity=>"adv_eyes", :crop=>"thumb"}
  ])
PHP:
cl_image_tag("redeye.jpg", array("transformation"=>array(
  array("effect"=>"adv_redeye"),
  array("width"=>300, "height"=>80, "gravity"=>"adv_eyes", "crop"=>"thumb")
  )))
Python:
CloudinaryImage("redeye.jpg").image(transformation=[
  {"effect": "adv_redeye"},
  {"width": 300, "height": 80, "gravity": "adv_eyes", "crop": "thumb"}
  ])
Node.js:
cloudinary.image("redeye.jpg", {transformation: [
  {effect: "adv_redeye"},
  {width: 300, height: 80, gravity: "adv_eyes", crop: "thumb"}
  ]})
Java:
cloudinary.url().transformation(new Transformation()
  .effect("adv_redeye").chain()
  .width(300).height(80).gravity("adv_eyes").crop("thumb")).imageTag("redeye.jpg")
JS:
cl.imageTag('redeye.jpg', {transformation: [
  {effect: "adv_redeye"},
  {width: 300, height: 80, gravity: "adv_eyes", crop: "thumb"}
  ]}).toHtml();
jQuery:
$.cloudinary.image("redeye.jpg", {transformation: [
  {effect: "adv_redeye"},
  {width: 300, height: 80, gravity: "adv_eyes", crop: "thumb"}
  ]})
React:
<Image publicId="redeye.jpg" >
        <Transformation effect="adv_redeye" />
        <Transformation width="300" height="80" gravity="adv_eyes" crop="thumb" />
</Image>
Angular:
<cl-image public-id="redeye.jpg" >
        <cl-transformation effect="adv_redeye">
        </cl-transformation>
        <cl-transformation width="300" height="80" gravity="adv_eyes" crop="thumb">
        </cl-transformation>
</cl-image>
.Net:
cloudinary.Api.UrlImgUp.Transform(new Transformation()
  .Effect("adv_redeye").Chain()
  .Width(300).Height(80).Gravity("adv_eyes").Crop("thumb")).BuildImageTag("redeye.jpg")
photo after applying the adv_redeye effect

Face overlays

The extracted facial attribute details also include the pose of the detected face, which allows Cloudinary to not only position overlays on top of detected faces, but also to rotate and scale the overlays accordingly for exact positioning over the underlying face. This is easily accomplished by setting the gravity parameter of the added overlay to adv_faces.

For example, the following PNG image named silver_face_mask was uploaded to Cloudinary:

silver mask

To smartly overlay the mask image on top of all detected faces in the coupled image, the overlay parameter is set to the ID of the mask image and the gravity parameter is set to adv_faces. In addition, we set the region_relative flag together with a 1.1 width, which means that each overlay will be scaled to 110% of the width of the detected face.

Ruby:
cl_image_tag("coupled.jpg", :flags=>"region_relative", :gravity=>"adv_faces", :overlay=>"silver_face_mask", :width=>1.1)
PHP:
cl_image_tag("coupled.jpg", array("flags"=>"region_relative", "gravity"=>"adv_faces", "overlay"=>"silver_face_mask", "width"=>1.1))
Python:
CloudinaryImage("coupled.jpg").image(flags="region_relative", gravity="adv_faces", overlay="silver_face_mask", width=1.1)
Node.js:
cloudinary.image("coupled.jpg", {flags: "region_relative", gravity: "adv_faces", overlay: "silver_face_mask", width: "1.1"})
Java:
cloudinary.url().transformation(new Transformation().flags("region_relative").gravity("adv_faces").overlay("silver_face_mask").width(1.1)).imageTag("coupled.jpg")
JS:
cl.imageTag('coupled.jpg', {flags: "region_relative", gravity: "adv_faces", overlay: "silver_face_mask", width: "1.1"}).toHtml();
jQuery:
$.cloudinary.image("coupled.jpg", {flags: "region_relative", gravity: "adv_faces", overlay: "silver_face_mask", width: "1.1"})
React:
<Image publicId="coupled.jpg" >
        <Transformation flags="region_relative" gravity="adv_faces" overlay="silver_face_mask" width="1.1" />
</Image>
Angular:
<cl-image public-id="coupled.jpg" >
        <cl-transformation flags="region_relative" gravity="adv_faces" overlay="silver_face_mask" width="1.1">
        </cl-transformation>
</cl-image>
.Net:
cloudinary.Api.UrlImgUp.Transform(new Transformation().Flags("region_relative").Gravity("adv_faces").Overlay("silver_face_mask").Width(1.1)).BuildImageTag("coupled.jpg")
mask overlayed coupled.jpg

Eyes overlays

As described above, the Advanced Facial Attribute Detection add-on detects specific facial attributes, including the exact position of the eyes of each face in a photo. Based on this information, Cloudinary can position overlays on top of all the detected eye pairs in an image.

For example, the following PNG image named glasses was uploaded to Cloudinary:

image of glasses

In order to smartly overlay the glasses on top of all detected eye pairs in an uploaded image, the overlay parameter is set to the ID of the glasses image and the gravity parameter is set to adv_eyes. In addition, we set the region_relative flag together with a 1.5 width, which means that each overlay should be scaled to 150% of the detected eyes.

Ruby:
cl_image_tag("coupled.jpg", :flags=>"region_relative", :gravity=>"adv_eyes", :overlay=>"glasses", :width=>1.5)
PHP:
cl_image_tag("coupled.jpg", array("flags"=>"region_relative", "gravity"=>"adv_eyes", "overlay"=>"glasses", "width"=>1.5))
Python:
CloudinaryImage("coupled.jpg").image(flags="region_relative", gravity="adv_eyes", overlay="glasses", width=1.5)
Node.js:
cloudinary.image("coupled.jpg", {flags: "region_relative", gravity: "adv_eyes", overlay: "glasses", width: "1.5"})
Java:
cloudinary.url().transformation(new Transformation().flags("region_relative").gravity("adv_eyes").overlay("glasses").width(1.5)).imageTag("coupled.jpg")
JS:
cl.imageTag('coupled.jpg', {flags: "region_relative", gravity: "adv_eyes", overlay: "glasses", width: "1.5"}).toHtml();
jQuery:
$.cloudinary.image("coupled.jpg", {flags: "region_relative", gravity: "adv_eyes", overlay: "glasses", width: "1.5"})
React:
<Image publicId="coupled.jpg" >
        <Transformation flags="region_relative" gravity="adv_eyes" overlay="glasses" width="1.5" />
</Image>
Angular:
<cl-image public-id="coupled.jpg" >
        <cl-transformation flags="region_relative" gravity="adv_eyes" overlay="glasses" width="1.5">
        </cl-transformation>
</cl-image>
.Net:
cloudinary.Api.UrlImgUp.Transform(new Transformation().Flags("region_relative").Gravity("adv_eyes").Overlay("glasses").Width(1.5)).BuildImageTag("coupled.jpg")
glasses added to auto detected eyes of all faces in the image

In another example, the following PNG image named harlequinmask was uploaded to Cloudinary:

harlequinmask

To smartly overlay the mask on top of all the detected eye pairs in the uploaded image cloudinary_team, the overlay parameter is set to the ID of the harlequinmask image and the gravity parameter is set to adv_eyes. We also set the region_relative flag together with a 1.7 width to scale the overlay to 170% of the width of the detected eyes, and resize the image to an oval thumbnail with a width of 700 pixels.

Ruby:
cl_image_tag("cloudinary_team.jpg", :transformation=>[
  {:width=>700, :radius=>"max", :crop=>"scale"},
  {:flags=>"region_relative", :gravity=>"adv_eyes", :overlay=>"harlequinmask", :width=>1.7}
  ])
PHP:
cl_image_tag("cloudinary_team.jpg", array("transformation"=>array(
  array("width"=>700, "radius"=>"max", "crop"=>"scale"),
  array("flags"=>"region_relative", "gravity"=>"adv_eyes", "overlay"=>"harlequinmask", "width"=>1.7)
  )))
Python:
CloudinaryImage("cloudinary_team.jpg").image(transformation=[
  {"width": 700, "radius": "max", "crop": "scale"},
  {"flags": "region_relative", "gravity": "adv_eyes", "overlay": "harlequinmask", "width": 1.7}
  ])
Node.js:
cloudinary.image("cloudinary_team.jpg", {transformation: [
  {width: 700, radius: "max", crop: "scale"},
  {flags: "region_relative", gravity: "adv_eyes", overlay: "harlequinmask", width: "1.7"}
  ]})
Java:
cloudinary.url().transformation(new Transformation()
  .width(700).radius("max").crop("scale").chain()
  .flags("region_relative").gravity("adv_eyes").overlay("harlequinmask").width(1.7)).imageTag("cloudinary_team.jpg")
JS:
cl.imageTag('cloudinary_team.jpg', {transformation: [
  {width: 700, radius: "max", crop: "scale"},
  {flags: "region_relative", gravity: "adv_eyes", overlay: "harlequinmask", width: "1.7"}
  ]}).toHtml();
jQuery:
$.cloudinary.image("cloudinary_team.jpg", {transformation: [
  {width: 700, radius: "max", crop: "scale"},
  {flags: "region_relative", gravity: "adv_eyes", overlay: "harlequinmask", width: "1.7"}
  ]})
React:
<Image publicId="cloudinary_team.jpg" >
        <Transformation width="700" radius="max" crop="scale" />
        <Transformation flags="region_relative" gravity="adv_eyes" overlay="harlequinmask" width="1.7" />
</Image>
Angular:
<cl-image public-id="cloudinary_team.jpg" >
        <cl-transformation width="700" radius="max" crop="scale">
        </cl-transformation>
        <cl-transformation flags="region_relative" gravity="adv_eyes" overlay="harlequinmask" width="1.7">
        </cl-transformation>
</cl-image>
.Net:
cloudinary.Api.UrlImgUp.Transform(new Transformation()
  .Width(700).Radius("max").Crop("scale").Chain()
  .Flags("region_relative").Gravity("adv_eyes").Overlay("harlequinmask").Width(1.7)).BuildImageTag("cloudinary_team.jpg")

For a full list of additional Cloudinary's image manipulation options, see Image transformations.