Table of contents
TOC
Collapse the table of content
Expand the table of content

Face Detection (U-SQL)

Michael Rys|Last Updated: 5/15/2018
|
4 Contributors

Cognitive face detection functions detect one or more human faces in an image and return face rectangles for where in the image the faces are, along with face attributes like age and gender. There are two ways in U-SQL to extract age and gender from the face in an image:

  • FaceDetectionApplier
  • FaceDetectionExtractor
Important

Use an Extractor rather than an Applier when you have images larger than 4 MB.

FaceDetectionApplier

Arguments
FaceDetectionApplier(                                                                                    
    string imgCol     = "ImgData", 
    string numCol     = "NumFaces", 
    string indexCol   = "FaceIndex", 
    string ageCol     = "FaceAge", 
    string genderCol  = "FaceGender")

FaceDetectionApplier is applied to each image in the byte array column with the default name ImgData and it generates one row per face detected in the file. It returns the number of detected faces in the image (column NumFaces of type int), the current index of the face from all the faces recognized in the image for the returned row (column FaceIndex of type int) and its face rectangle (columns RectX, RectY, Width, Height of type float) along with the estimated age (column FaceAge of type int) and gender (column FaceGender of type string) for the current face.

FaceDetectionExtractor

Arguments
FaceDetectionExtractor(                                                                                  
    string numCol     = "NumFaces", 
    string indexCol   = "FaceIndex", 
    string ageCol     = "FaceAge", 
    string genderCol  = "FaceGender")

FaceDetectionExtractor is applied to each image and it generates one row per face detected in the file. It returns the number of detected faces in the image (column NumFaces of type int), the current index of the face from all the faces recognized in the image for the returned row (column FaceIndex of type int) and its face rectangle (columns RectX, RectY, Width, Height of type float) along with the estimated age (column FaceAge of type int) and gender (column FaceGender of type string) for the current face.

Examples

A. FaceDetectionApplier

Estimate age and gender for human faces using Applier

REFERENCE ASSEMBLY ImageCommon;       
REFERENCE ASSEMBLY FaceSdk;

// Load images
@images =
    EXTRACT FileName string, 
            ImgData byte[]
    FROM @"/Samples/Images/{FileName}.jpg"
    USING new Cognition.Vision.ImageExtractor();

@faces_from_applier =
    SELECT FileName,
        Details.NumFaces,
        Details.FaceIndex,
        Details.RectX, Details.RectY, Details.Width, Details.Height,
        Details.FaceAge,
        Details.FaceGender
    FROM @images
    CROSS APPLY
        USING new Cognition.Vision.FaceDetectionApplier() AS Details(
            NumFaces int, 
            FaceIndex int, 
            RectX float, RectY float, Width float, Height float, 
            FaceAge int, 
            FaceGender string);

OUTPUT @faces_from_applier
TO "/ReferenceGuide/Cognition/Vision/FaceDetectionApplier.txt"
USING Outputters.Tsv(outputHeader: true);

B. FaceDetectionExtractor

Extract age and gender using Face Detection Extractor

REFERENCE ASSEMBLY ImageCommon; 
REFERENCE ASSEMBLY FaceSdk;       

@faces_from_extractor =
    EXTRACT FileName string, 
        NumFaces int, 
        FaceIndex int, 
        RectX float, RectY float, Width float, Height float, 
        FaceAge int, 
        FaceGender string
    FROM @"/Samples/Images/{FileName}.jpg"
    USING new Cognition.Vision.FaceDetectionExtractor();

OUTPUT @faces_from_extractor
TO "/ReferenceGuide/Cognition/Vision/FaceDetectionExtractor.txt"
USING Outputters.Tsv(outputHeader: true);

See Also

© 2018 Microsoft