public static FaceDetectionResult DetectFaceFromFile(string imagePath, bool landmarks, FaceAttributesValues faceAttributes) { if (!File.Exists(imagePath)) { return(null); } string attributes = "gender,age,smiling,headpose,blur,facequality,eyestatus,ethnicity"; if (!faceAttributes.HasFlag(FaceAttributesValues.All)) { attributes = ""; foreach (var attr in Enum.GetValues(typeof(FaceAttributesValues)).Cast <Enum>().Where(faceAttributes.HasFlag)) { attributes += attr.ToString().ToLower() + ","; } //TODO: check if last , removing attributes = attributes.Substring(0, attributes.Length); } string base64 = ImageBase64.ImageToBase64(Image.FromFile(imagePath), System.Drawing.Imaging.ImageFormat.Jpeg); return(getResponse <FaceDetectionResult>("detect", new NameValueCollection() { { "image_base64", base64 }, { "return_landmark", (landmarks ? "1" : "0") }, { "return_attributes", attributes } })); }
public static FaceDetectionResult DetectFaceFromUrl(string imageUrl, bool landmarks, FaceAttributesValues faceAttributes) { string attributes = "gender,age,smiling,headpose,blur,facequality,eyestatus,ethnicity"; if (!faceAttributes.HasFlag(FaceAttributesValues.All)) { attributes = ""; foreach (var attr in Enum.GetValues(typeof(FaceAttributesValues)).Cast <Enum>().Where(faceAttributes.HasFlag)) { attributes += attr.ToString().ToLower() + ","; } //TODO: check if last , removing attributes = attributes.Substring(0, attributes.Length); } return(getResponse <FaceDetectionResult>("detect", new NameValueCollection() { { "image_url", imageUrl }, { "return_landmark", (landmarks ? "1" : "0") }, { "return_attributes", attributes } })); }