旷视AI开放平台接入

作者:追风剑情 发布于:2021-8-11 14:05 分类:Unity3d

面部特征分析API文档

一、复制官方文档上的访问代码

  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Net;
  5. using System.Net.Security;
  6. using System.Security.Cryptography.X509Certificates;
  7. using System.Text;
  8. using System.Threading;
  9. //官方示例代码
  10. //https://console.faceplusplus.com.cn/documents/6329752
  11. namespace MgLiveCOM_Eyes
  12. {
  13. public static class HttpHelper4MultipartForm
  14. {
  15. public class FileParameter
  16. {
  17. public byte[] File
  18. {
  19. get;
  20. set;
  21. }
  22.  
  23. public string FileName
  24. {
  25. get;
  26. set;
  27. }
  28.  
  29. public string ContentType
  30. {
  31. get;
  32. set;
  33. }
  34.  
  35. public FileParameter(byte[] file) : this(file, null)
  36. {
  37. }
  38.  
  39. public FileParameter(byte[] file, string filename) : this(file, filename, null)
  40. {
  41. }
  42.  
  43. public FileParameter(byte[] file, string filename, string contenttype)
  44. {
  45. this.File = file;
  46. this.FileName = filename;
  47. this.ContentType = contenttype;
  48. }
  49. }
  50. private static readonly Encoding encoding = Encoding.UTF8;
  51. /// <summary>
  52. /// MultipartForm请求
  53. /// </summary>
  54. /// <param name="postUrl">服务地址</param>
  55. /// <param name="userAgent"></param>
  56. /// <param name="postParameters">参数</param>
  57. /// <returns></returns>
  58. public static HttpWebResponse MultipartFormDataPost(string postUrl, string userAgent, Dictionary<string, object> postParameters)
  59. {
  60. string text = string.Format("----------{0:N}", Guid.NewGuid());
  61. string contentType = "multipart/form-data; boundary=" + text;//multipart类型
  62. byte[] multipartFormData = HttpHelper4MultipartForm.GetMultipartFormData(postParameters, text);
  63. return HttpHelper4MultipartForm.PostForm(postUrl, userAgent, contentType, multipartFormData);
  64. }
  65.  
  66. private static HttpWebResponse PostForm(string postUrl, string userAgent, string contentType, byte[] formData)
  67. {
  68. HttpWebRequest httpWebRequest = WebRequest.Create(postUrl) as HttpWebRequest;
  69. if (httpWebRequest == null)
  70. {
  71. throw new NullReferenceException("request is not a http request");
  72. }
  73.  
  74. httpWebRequest.Method = "POST";//post方式
  75. httpWebRequest.SendChunked = false;
  76. httpWebRequest.KeepAlive = true;
  77. httpWebRequest.Proxy = null;
  78. httpWebRequest.Timeout = Timeout.Infinite;
  79. httpWebRequest.ReadWriteTimeout = Timeout.Infinite;
  80. httpWebRequest.AllowWriteStreamBuffering = false;
  81. httpWebRequest.ProtocolVersion = HttpVersion.Version11;
  82. httpWebRequest.ContentType = contentType;
  83. httpWebRequest.CookieContainer = new CookieContainer();
  84. httpWebRequest.ContentLength = (long)formData.Length;
  85.  
  86. try
  87. {
  88. using (Stream requestStream = httpWebRequest.GetRequestStream())
  89. {
  90. int bufferSize = 4096;
  91. int position = 0;
  92. while (position < formData.Length)
  93. {
  94. bufferSize = Math.Min(bufferSize, formData.Length - position);
  95. byte[] data = new byte[bufferSize];
  96. Array.Copy(formData, position, data, 0, bufferSize);
  97. requestStream.Write(data, 0, data.Length);
  98. position += data.Length;
  99. }
  100. requestStream.Close();
  101. }
  102. }
  103. catch (Exception ex)
  104. {
  105. return null;
  106. }
  107.  
  108. HttpWebResponse result;
  109. try
  110. {
  111. result = (httpWebRequest.GetResponse() as HttpWebResponse);
  112. }
  113. catch (WebException arg_9C_0)
  114. {
  115. result = (arg_9C_0.Response as HttpWebResponse);
  116. }
  117. return result;
  118. }
  119.  
  120. public static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
  121. {
  122. return true;
  123. }
  124. /// <summary>
  125. /// 从表单中获取数据
  126. /// </summary>
  127. /// <param name="postParameters"></param>
  128. /// <param name="boundary"></param>
  129. /// <returns></returns>
  130. private static byte[] GetMultipartFormData(Dictionary<string, object> postParameters, string boundary)
  131. {
  132. Stream stream = new MemoryStream();
  133. bool flag = false;
  134. foreach (KeyValuePair<string, object> current in postParameters)
  135. {
  136. if (flag)
  137. {
  138. stream.Write(HttpHelper4MultipartForm.encoding.GetBytes("\r\n"), 0, HttpHelper4MultipartForm.encoding.GetByteCount("\r\n"));
  139. }
  140. flag = true;
  141. if (current.Value is HttpHelper4MultipartForm.FileParameter)
  142. {
  143. HttpHelper4MultipartForm.FileParameter fileParameter = (HttpHelper4MultipartForm.FileParameter)current.Value;
  144. string s = string.Format("--{0}\r\nContent-Disposition: form-data; name=\"{1}\"; filename=\"{2}\"\r\nContent-Type: {3}\r\n\r\n", new object[]
  145. {
  146. boundary,
  147. current.Key,
  148. fileParameter.FileName ?? current.Key,
  149. fileParameter.ContentType ?? "application/octet-stream"
  150. });
  151. stream.Write(HttpHelper4MultipartForm.encoding.GetBytes(s), 0, HttpHelper4MultipartForm.encoding.GetByteCount(s));
  152. stream.Write(fileParameter.File, 0, fileParameter.File.Length);
  153. }
  154. else
  155. {
  156. string s2 = string.Format("--{0}\r\nContent-Disposition: form-data; name=\"{1}\"\r\n\r\n{2}", boundary, current.Key, current.Value);
  157. stream.Write(HttpHelper4MultipartForm.encoding.GetBytes(s2), 0, HttpHelper4MultipartForm.encoding.GetByteCount(s2));
  158. }
  159. }
  160. string s3 = "\r\n--" + boundary + "--\r\n";
  161. stream.Write(HttpHelper4MultipartForm.encoding.GetBytes(s3), 0, HttpHelper4MultipartForm.encoding.GetByteCount(s3));
  162. stream.Position = 0L;
  163. byte[] array = new byte[stream.Length];
  164. stream.Read(array, 0, array.Length);
  165. stream.Close();
  166. return array;
  167. }
  168. }
  169. }


二、接入AI功能

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Net;
  5. using System.IO;
  6. using UnityEngine;
  7. using MgLiveCOM_Eyes;
  8. /// <summary>
  9. /// Face++旷视
  10. /// 人工智能开放平台
  11. ///
  12. /// 面部特征分析文档
  13. /// https://console.faceplusplus.com.cn/documents/118131136
  14. /// </summary>
  15. public class FacePlusSDK : MonoBehaviour
  16. {
  17. //人脸检测请求地址
  18. public const string FACE_DETECT_URL = "https://api-cn.faceplusplus.com/facepp/v3/detect";
  19. //面部特征分析请求地址
  20. public const string FACIAL_URL = "https://api-cn.faceplusplus.com/facepp/v1/facialfeatures";
  21. public const string API_KEY = "";
  22. public const string API_SECRET = "";
  23.  
  24. public Action<FaceDetectResult> OnFaceDetectResult;
  25. public Action<FacialFeaturesResult> OnFacialFeaturesResult;
  26.  
  27. /// <summary>
  28. /// 人脸检测
  29. /// 图片格式:JPG(JPEG),PNG
  30. /// 图片像素尺寸:最小 48*48 像素,最大 4096*4096 像素
  31. /// 图片文件大小:2 MB
  32. /// 最小人脸像素尺寸:
  33. /// 系统能够检测到的人脸框为一个正方形,
  34. /// 正方形边长的最小值为图像短边长度的 48 分之一,最小值不低于 48 像素。
  35. /// 例如图片为 4096*3200 像素,则最小人脸像素尺寸为 66*66 像素。
  36. /// </summary>
  37. /// <param name="tex"></param>
  38. public void AsyncFaceDetect(Texture2D tex)
  39. {
  40. byte[] bytes = tex.EncodeToJPG();
  41. var postParameters = new Dictionary<string, object>();
  42. postParameters.Add("api_key", API_KEY);
  43. postParameters.Add("api_secret", API_SECRET);
  44. postParameters.Add("return_landmark", 0);
  45. string attributes = "gender,age,eyestatus,emotion,beauty,mouthstatus,skinstatus";
  46. postParameters.Add("return_attributes", attributes);
  47. postParameters.Add("image_file", new HttpHelper4MultipartForm.FileParameter(bytes, "1.jpg", "application/octet-stream"));
  48. HttpWebResponse response = HttpHelper4MultipartForm.MultipartFormDataPost(FACE_DETECT_URL, string.Empty, postParameters);
  49. StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
  50. string result = reader.ReadToEnd();
  51. File.WriteAllText("D:/face_detect.txt", result);
  52. var face = JsonUtility.FromJson<FaceDetectResult>(result);
  53. if (!string.IsNullOrEmpty(face.error_message))
  54. {
  55. Debug.LogError(face.error_message);
  56. }
  57. OnFaceDetectResult?.Invoke(face);
  58. }
  59.  
  60. /// <summary>
  61. /// 面部特征分析
  62. /// 图片格式: JPG(JPEG)
  63. /// 图片像素尺寸: 最小200*200像素,最大4096*4096像素
  64. /// 图片文件大小:最大 2 MB
  65. /// </summary>
  66. /// <param name="tex"></param>
  67. public void AsyncFacialFeatures(Texture2D tex)
  68. {
  69. byte[] bytes = tex.EncodeToJPG();
  70. var postParameters = new Dictionary<string, object>();
  71. postParameters.Add("api_key", API_KEY);
  72. postParameters.Add("api_secret", API_SECRET);
  73. postParameters.Add("image_file", new HttpHelper4MultipartForm.FileParameter(bytes, "1.jpg", "application/octet-stream"));
  74. HttpWebResponse response = HttpHelper4MultipartForm.MultipartFormDataPost(FACIAL_URL, string.Empty, postParameters);
  75. StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
  76. string result = reader.ReadToEnd();
  77. //File.WriteAllText("D:/face_feature.txt", result);
  78. var facial = JsonUtility.FromJson<FacialFeaturesResult>(result);
  79. if (!string.IsNullOrEmpty(facial.error_message)) {
  80. Debug.LogError(facial.error_message);
  81. }
  82. OnFacialFeaturesResult?.Invoke(facial);
  83. }
  84.  
  85. //人脸检测结果
  86. public class FaceDetectResult
  87. {
  88. //用于区分每一次请求的唯一的字符串
  89. public string request_id;
  90. //被检测出的人脸数组
  91. public Face[] faces;
  92. //被检测的图片在系统中的标识
  93. public string image_id;
  94. //整个请求所花费的时间,单位为毫秒
  95. public int time_used;
  96. //当请求失败时才会返回此字符串
  97. public string error_message;
  98. //检测出的人脸个数
  99. public int face_num;
  100.  
  101. [Serializable]
  102. public class Face
  103. {
  104. //人脸的标识
  105. public string face_token;
  106. //人脸矩形框的位置
  107. public FaceRectangle face_rectangle;
  108. //人脸的关键点坐标数组
  109. public object landmark;
  110. //人脸属性特征
  111. public FaceAttribute attributes;
  112.  
  113. [Serializable]
  114. public class FaceRectangle
  115. {
  116. //矩形框左上角像素点的纵坐标
  117. public int top;
  118. //矩形框左上角像素点的横坐标
  119. public int left;
  120. //矩形框的宽度
  121. public int width;
  122. //矩形框的高度
  123. public int height;
  124. }
  125.  
  126. [Serializable]
  127. public class FaceAttribute
  128. {
  129. //性别分析结果 Male:男, Female:女
  130. public Gender gender;
  131. //年龄
  132. public Age age;
  133. //笑容分析结果
  134. public Smile smile;
  135. //人脸姿势分析结果
  136. public Headpose headpose;
  137. //人脸模糊分析结果
  138. public Blur blur;
  139. //眼睛状态信息
  140. public EyeStatus eyestatus;
  141. //情绪识别结果
  142. public Emotion emotion;
  143. //人脸质量判断结果
  144. public Facequality facequality;
  145. //颜值识别结果
  146. public Beauty beauty;
  147. //嘴部状态信息
  148. public Mouthstatus mouthstatus;
  149. //眼球位置与视线方向信息
  150. public Eyegaze eyegaze;
  151. //面部特征识别结果
  152. public Skinstatus skinstatus;
  153.  
  154. [Serializable]
  155. public class Gender
  156. {
  157. public string value;
  158. }
  159.  
  160. [Serializable]
  161. public class Age
  162. {
  163. public int value;
  164. }
  165.  
  166. [Serializable]
  167. public class Smile
  168. {
  169. //值为一个 [0,100] 的浮点数,小数点后3位有效数字。数值越大表示笑程度高。
  170. public float value;
  171. //代表笑容的阈值,超过该阈值认为有笑容
  172. public float threshold;
  173. }
  174.  
  175. [Serializable]
  176. public class Headpose
  177. {
  178. //抬头
  179. public float pitch_angle;
  180. //旋转(平面旋转)
  181. public float roll_angle;
  182. //摇头
  183. public float yaw_angle;
  184. }
  185.  
  186. [Serializable]
  187. public class Blur
  188. {
  189. //人脸模糊分析结果
  190. public Blurness blurness;
  191.  
  192. [Serializable]
  193. public class Blurness
  194. {
  195. //范围 [0,100],小数点后 3 位有效数字。值越大,越模糊。
  196. public float value;
  197. //表示人脸模糊度是否影响辨识的阈值。
  198. public float threshold;
  199. }
  200. }
  201.  
  202. [Serializable]
  203. public class EyeStatus
  204. {
  205. //左眼状态
  206. public EyeState left_eye_status;
  207. //右眼状态
  208. public EyeState right_eye_status;
  209.  
  210. [Serializable]
  211. public class EyeState
  212. {
  213. //眼睛被遮挡的置信度
  214. public float occlusion;
  215. //不戴眼镜且睁眼的置信度
  216. public float no_glass_eye_open;
  217. //佩戴普通眼镜且闭眼的置信度
  218. public float normal_glass_eye_close;
  219. //佩戴普通眼镜且睁眼的置信度
  220. public float normal_glass_eye_open;
  221. //佩戴墨镜的置信度
  222. public float dark_glasses;
  223. //不戴眼镜且闭眼的置信度
  224. public float no_glass_eye_close;
  225.  
  226. //带眼镜的置信度
  227. public float glass
  228. {
  229. get
  230. {
  231. return normal_glass_eye_close +
  232. normal_glass_eye_open +
  233. dark_glasses;
  234. }
  235. }
  236. }
  237. }
  238.  
  239. [Serializable]
  240. public class Emotion
  241. {
  242. //愤怒
  243. public float anger;
  244. //厌恶
  245. public float disgust;
  246. //恐惧
  247. public float fear;
  248. //高兴
  249. public float happiness;
  250. //平静
  251. public float neutral;
  252. //伤心
  253. public float sadness;
  254. //惊讶
  255. public float surprise;
  256. }
  257. [Serializable]
  258. public class Facequality
  259. {
  260. //值为人脸的质量判断的分数,是一个浮点数,范围 [0,100],小数点后 3 位有效数字
  261. public float value;
  262. //表示人脸质量基本合格的一个阈值,超过该阈值的人脸适合用于人脸比对
  263. public float threshold;
  264. }
  265.  
  266. [Serializable]
  267. public class Beauty
  268. {
  269. //男性认为的此人脸颜值分数。值越大,颜值越高。
  270. public float male_score;
  271. //女性认为的此人脸颜值分数。值越大,颜值越高。
  272. public float female_score;
  273. }
  274.  
  275. [Serializable]
  276. public class Mouthstatus
  277. {
  278. //嘴部被医用口罩或呼吸面罩遮挡的置信度
  279. public float surgical_mask_or_respirator;
  280. //嘴部被其他物体遮挡的置信度
  281. public float other_occlusion;
  282. //嘴部没有遮挡且闭上的置信度
  283. public float close;
  284. //嘴部没有遮挡且张开的置信度
  285. public float open;
  286. }
  287.  
  288. [Serializable]
  289. public class Eyegaze
  290. {
  291. //左眼的位置与视线状态
  292. public EyePosition left_eye_gaze;
  293. //右眼的位置与视线状态
  294. public EyePosition right_eye_gaze;
  295.  
  296. [Serializable]
  297. public class EyePosition
  298. {
  299. //眼球中心位置的 X 轴坐标
  300. public float position_x_coordinate;
  301. //眼球中心位置的 Y 轴坐标
  302. public float position_y_coordinate;
  303. //眼球视线方向向量的 X 轴分量
  304. public float vector_x_component;
  305. //眼球视线方向向量的 Y 轴分量
  306. public float vector_y_component;
  307. //眼球视线方向向量的 Z 轴分量
  308. public float vector_z_component;
  309. }
  310. }
  311.  
  312. [Serializable]
  313. public class Skinstatus
  314. {
  315. //健康
  316. public float health;
  317. //色斑
  318. public float stain;
  319. //青春痘
  320. public float acne;
  321. //黑眼圈
  322. public float dark_circle;
  323. }
  324. }
  325. }
  326. }
  327.  
  328. //面部特征结果
  329. public class FacialFeaturesResult
  330. {
  331. //用于区分每一次请求的唯一的字符串
  332. public string request_id;
  333. //被检测的图片在系统中的标识
  334. public string image_id;
  335. //人脸矫正后的图片,jpg格式。base64 编码的二进制图片数据
  336. public string image_reset;
  337. //人脸特征分析的结果
  338. public Result result;
  339. //人脸矩形框的位置
  340. public FaceRectangle face_rectangle;
  341. //人脸姿势分析结果
  342. public HeadPose headpose;
  343. //人脸五官及轮廓的关键点坐标数组
  344. public DenseLandmark denselandmark;
  345. //整个请求所花费的时间,单位为毫秒
  346. public int time_used;
  347. //当请求失败时才会返回此字符串,具体返回内容见后续错误信息章节。否则此字段不存在。
  348. public string error_message;
  349.  
  350. [Serializable]
  351. public class Result
  352. {
  353. //三庭
  354. public ThreeParts three_parts;
  355. //五眼
  356. public FiveEyes five_eyes;
  357. //黄金三角度数,单位为°,范围[0,180],保留至小数点后两位(若为0则返回null)
  358. public float golden_triangle;
  359. //脸型
  360. public Face face;
  361. //下巴
  362. public Jaw jaw;
  363. //眉型
  364. public Eyebrow eyebrow;
  365. //眼型
  366. public Eyes eyes;
  367. //鼻型
  368. public Nose nose;
  369. //唇型
  370. public Mouth mouth;
  371.  
  372. [Serializable]
  373. public class ThreeParts
  374. {
  375. //返回三庭比例,保留至小数点后两位,若为0,则返回null
  376. public string parts_ratio;
  377. //返回上庭分析结果,距离单位为mm,保留至小数点后两位
  378. public OnePart one_part;
  379. //返回中庭分析结果,距离单位为mm,保留至小数点后两位
  380. public TwoPart two_part;
  381. //返回下庭分析结果,距离单位为mm,保留至小数点后两位
  382. public ThreePart three_part;
  383.  
  384. [Serializable]
  385. public class OnePart
  386. {
  387. //上庭长度(若为0或无法判断,则返回null)
  388. public float faceup_length;
  389. //上庭占比(若为0或无法判断,则返回null)
  390. public float faceup_ratio;
  391. //上庭判断结果(若为0或无法判断,则返回null)
  392. public FaceupResult faceup_result;
  393.  
  394. //上庭判断结果枚举
  395. [Serializable]
  396. public enum FaceupResult
  397. {
  398. //上庭标准
  399. faceup_normal,
  400. //上庭偏长
  401. faceup_long,
  402. //上庭偏短
  403. faceup_short
  404. }
  405. }
  406.  
  407. [Serializable]
  408. public class TwoPart
  409. {
  410. //中庭长度(若为0或无法判断,则返回null)
  411. public float facemid_length;
  412. //中庭占比(若为0或无法判断,则返回null)
  413. public float facemid_ratio;
  414. //中庭判断结果(若为0或无法判断,则返回null)
  415. public FacemidResult facemid_result;
  416.  
  417. //中庭判断结果枚举
  418. [Serializable]
  419. public enum FacemidResult
  420. {
  421. //中庭标准
  422. facemid_normal,
  423. //中庭偏长
  424. facemid_long,
  425. //中庭偏短
  426. facemid_short
  427. }
  428. }
  429.  
  430. [Serializable]
  431. public class ThreePart
  432. {
  433. //下庭长度(若为0或无法判断,则返回null)
  434. public float facedown_length;
  435. //下庭占比(若为0或无法判断,则返回null)
  436. public float facedown_ratio;
  437. //下庭判断结果(若为0或无法判断,则返回null)
  438. public FacedownResult facedown_result;
  439.  
  440. //下庭判断结果枚举
  441. [Serializable]
  442. public enum FacedownResult
  443. {
  444. //下庭标准
  445. facedown_normal,
  446. //下庭偏长
  447. facedown_long,
  448. //下庭偏短
  449. facedown_short
  450. }
  451. }
  452. }
  453.  
  454. [Serializable]
  455. public class FiveEyes
  456. {
  457. //返回五眼比例,保留至小数点后两位,若出现0,则返回null
  458. public string eyes_ratio;
  459. //返回五眼右侧分析结果,距离单位为mm,保留至小数点后两位
  460. public OneEye one_eye;
  461. //返回右眼宽度分析结果,距离单位为mm,保留至小数点后两位,若为0,则返回null
  462. public float righteye;
  463. //返回内眼角间距分析结果,距离单位为mm,保留至小数点后两位
  464. public ThreeEye three_eye;
  465. //返回左眼宽度分析结果,距离单位为mm,保留至小数点后两位,若为0,则返回null
  466. public float lefteye;
  467. //返回五眼左侧分析结果,距离单位为mm,保留至小数点后两位
  468. public FiveEve five_eye;
  469.  
  470. [Serializable]
  471. public class OneEye
  472. {
  473. //右外眼角颧弓留白距离(若为0或无法判断,则返回null)
  474. public float righteye_empty_length;
  475. //右外眼角颧弓留白占比(若为0或无法判断,则返回null)
  476. public float righteye_empty_ratio;
  477. //五眼右侧判断结果(若为0或无法判断,则返回null)
  478. public RighteyeEmptyResult righteye_empty_result;
  479.  
  480. [Serializable]
  481. public enum RighteyeEmptyResult
  482. {
  483. //右眼外侧适中
  484. righteye_empty_normal,
  485. //右眼外侧偏窄
  486. righteye_empty_short,
  487. //右眼外侧偏宽
  488. righteye_empty_long
  489. }
  490. }
  491.  
  492. [Serializable]
  493. public class ThreeEye
  494. {
  495. //内眼角间距(若为0或无法判断,则返回null)
  496. public float eyein_length;
  497. //内眼角间距占比(若为0或无法判断,则返回null)
  498. public float eyein_ratio;
  499. //内眼角间距判断结果(若为0或无法判断,则返回null)
  500. public EyeinResult eyein_result;
  501.  
  502. [Serializable]
  503. public enum EyeinResult
  504. {
  505. //内眼角间距适中
  506. eyein_normal,
  507. //内眼角间距偏窄
  508. eyein_short,
  509. //内眼角间距偏宽
  510. eyein_long
  511. }
  512. }
  513.  
  514. [Serializable]
  515. public class FiveEve
  516. {
  517. //左外眼角颧弓留白 (若为0或无法判断,则返回null)
  518. public float lefteye_empty_length;
  519. //左外眼角颧弓留白占比(若为0或无法判断,则返回null)
  520. public float lefteye_empty_ratio;
  521. //五眼左侧距判断结果(若为0或无法判断,则返回null)
  522. public LefteyeEmptyResult lefteye_empty_result;
  523.  
  524. [Serializable]
  525. public enum LefteyeEmptyResult
  526. {
  527. //左眼外侧适中
  528. lefteye_empty_normal,
  529. //左眼外侧偏窄
  530. lefteye_empty_short,
  531. //左眼外侧偏宽
  532. lefteye_empty_long
  533. }
  534. }
  535. }
  536.  
  537. [Serializable]
  538. public class Face
  539. {
  540. //颞部宽度(若为0则返回null)
  541. public float tempus_length;
  542. //颧骨宽度(若为0则返回null)
  543. public float zygoma_length;
  544. //脸部长度(若为0则返回null)
  545. public float face_length;
  546. //下颌角宽度(若为0则返回null)
  547. public float mandible_length;
  548. //下颌角度数(若为0则返回null)
  549. public float E;
  550. //颞部宽度、颧部宽度(固定颧部为1)、下颌角宽度比(若为0则返回null)
  551. public float ABD_ratio;
  552. //脸型判断结果(若无法判断则返回null)
  553. public FaceType face_type;
  554.  
  555. [Serializable]
  556. public enum FaceType
  557. {
  558. //瓜子脸
  559. pointed_face,
  560. //椭圆脸
  561. oval_face,
  562. //菱形脸
  563. diamond_face,
  564. //圆形脸
  565. round_face,
  566. //长形脸
  567. long_face,
  568. //方形脸
  569. square_face,
  570. //标准脸
  571. normal_face
  572. }
  573. }
  574. [Serializable]
  575. public class Jaw
  576. {
  577. //下巴宽度(若为0或者无法判断,则返回null)
  578. public float jaw_width;
  579. //下巴长度(若为0或者无法判断,则返回null)
  580. public float jaw_length;
  581. //下巴角度(若为0则返回null)
  582. public float jaw_angle;
  583. //下巴判断结果(若为0或者无法判断,则返回null)
  584. public JawType jaw_type;
  585.  
  586. [Serializable]
  587. public enum JawType
  588. {
  589. //圆下巴
  590. flat_jaw,
  591. //尖下巴
  592. sharp_jaw,
  593. //方下巴
  594. square_jaw
  595. }
  596. }
  597.  
  598. [Serializable]
  599. public class Eyebrow
  600. {
  601. //眉毛宽度(若为0则返回null)
  602. public float brow_width;
  603. //毛高度(若为0则返回null)
  604. public float brow_height;
  605. //眉毛挑度,若通过M2的水平线在M3的下方,则返回null
  606. public float brow_uptrend_angle;
  607. //眉毛弯度
  608. public float brow_camber_angle;
  609. //眉毛粗细(若为0则返回null)
  610. public float brow_thick;
  611. //眉型判断结果(若无法判断则返回null)
  612. public EyebrowType eyebrow_type;
  613.  
  614. //眉型判断结果枚举
  615. [Serializable]
  616. public enum EyebrowType
  617. {
  618. //粗眉
  619. bushy_eyebrows,
  620. //八字眉
  621. eight_eyebrows,
  622. //上挑眉
  623. raise_eyebrows,
  624. //一字眉
  625. straight_eyebrows,
  626. //拱形眉
  627. round_eyebrows,
  628. //柳叶眉
  629. arch_eyebrows,
  630. //细眉
  631. thin_eyebrows
  632. }
  633. }
  634.  
  635. [Serializable]
  636. public class Eyes
  637. {
  638. //眼睛宽度(若为0或无法判断,则返回null)
  639. public float eye_width;
  640. //眼睛高度(若为0或无法判断,则返回null)
  641. public float eye_height;
  642. //内眦角度数(若为0或无法判断,则返回null)
  643. public float angulus_oculi_medialis;
  644. //眼型判断结果(若为0或无法判断,则返回null)
  645. public EyesType eyes_type;
  646.  
  647. [Serializable]
  648. public enum EyesType
  649. {
  650. //圆眼
  651. round_eyes,
  652. //细长眼
  653. thin_eyes,
  654. //大眼
  655. big_eyes,
  656. //小眼
  657. small_eyes,
  658. //标准眼
  659. normal_eyes
  660. }
  661. }
  662.  
  663. [Serializable]
  664. public class Nose
  665. {
  666. //鼻翼宽度(若为0或无法判断,则返回null)
  667. public float nose_width;
  668. //鼻翼判断结果(若为0或无法判断,则返回null)
  669. public NoseType nose_type;
  670.  
  671. [Serializable]
  672. public enum NoseType
  673. {
  674. //标准鼻
  675. normal_nose,
  676. //宽鼻
  677. thick_nose,
  678. //窄鼻
  679. thin_nose
  680. }
  681. }
  682.  
  683. [Serializable]
  684. public class Mouth
  685. {
  686. //嘴巴高度(若为0或无法判断,则返回null)
  687. public float mouth_height;
  688. //嘴巴宽度(若为0或无法判断,则返回null)
  689. public float mouth_width;
  690. //嘴唇厚度(若为0或无法判断,则返回null)
  691. public float lip_thickness;
  692. //嘴角弯曲度(若为0或无法判断,则返回null)
  693. public float angulus_oris;
  694. //唇型判断结果(若为0或无法判断,则返回null)
  695. public MouthType mouth_type;
  696.  
  697. [Serializable]
  698. public enum MouthType
  699. {
  700. //薄唇
  701. thin_lip,
  702. //厚唇
  703. thick_lip,
  704. //微笑唇
  705. smile_lip,
  706. //态度唇
  707. upset_lip,
  708. //标准唇
  709. normal_lip
  710. }
  711. }
  712. }
  713.  
  714. [Serializable]
  715. public class FaceRectangle
  716. {
  717. public int top;
  718. public int left;
  719. public int width;
  720. public int height;
  721. }
  722.  
  723. [Serializable]
  724. public class HeadPose
  725. {
  726. //抬头
  727. public float pitch_angle;
  728. //旋转(平面旋转)
  729. public float roll_angle;
  730. //摇头
  731. public float yaw_angle;
  732. }
  733.  
  734. //数据结构文档
  735. //https://console.faceplusplus.com.cn/documents/55107022
  736. [Serializable]
  737. public class DenseLandmark
  738. {
  739. public object face;
  740. public object left_eyebrow;
  741. public object right_eyebrow;
  742. public object left_eye;
  743. public object left_eye_eyelid;
  744. public object right_eye;
  745. public object right_eye_eyelid;
  746. public object nose;
  747. public object mouth;
  748. }
  749. }
  750. }


标签: Unity3d

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号