本文档详细介绍了 UnaAI 的功能,包括显示 AI 结果、物体和人臉检测、人脸比对 , 以及根据头发颜色、眼镜、性别和情感等属性识别人物。
常见
显示 AI 结果
打印 AI 结果
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>result</variable></variables><block type=\"UnaAI_AiResult_showContent\" disabled=\"true\" x=\"113\" y=\"202\"><value name=\"result\"><block type=\"variables_get\" disabled=\"true\"><field name=\"VAR\">result</field></block></value></block></xml>"}
这用于在 AI 加载图像或照片后显示 AI 结果。
参数: AI Result (from Azure)
输出: Json Value
示例代码:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>photo</variable><variable>visionAnalysisResult</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">photo</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Resources_getPhotoByURL\"><value name=\"url\"><shadow type=\"text\"><field name=\"TEXT\">https://www.magicubedu.com/una/AI1/2.jpg</field></shadow></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">visionAnalysisResult</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"UnaAI_detectObjects\"><value name=\"img\"><block type=\"variables_get\"><field name=\"VAR\">photo</field></block></value></block></value><next><block type=\"UnaAI_AiResult_showContent\"><value name=\"result\"><block type=\"variables_get\"><field name=\"VAR\">visionAnalysisResult</field></block></value><next><block type=\"Camera_showPhoto\"><value name=\"photo\"><block type=\"variables_get\"><field name=\"VAR\">photo</field></block></value></block></next></block></next></block></next></block></statement></block></xml>"}
输出:
接收 AI 结果并将其更改为 JsonValue
将 AI 结果获取为 JsonValue
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>photo</variable><variable>visionAnalysisResult</variable><variable>result</variable></variables><block type=\"UnaAI_AiResult_getContentAsJsonValue\" disabled=\"true\" x=\"113\" y=\"248\"><value name=\"result\"><block type=\"variables_get\" disabled=\"true\"><field name=\"VAR\">result</field></block></value></block></xml>"}
这用于在 AI 获取照片中的对象或面部并将其转换为 JSON 值后获取 AI 结果。
参数: AI Result (from Azure)
输出: Json Value
示例代码:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>photo</variable><variable>visionAnalysisResult</variable><variable>JsonValue</variable><variable>result</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">photo</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Resources_getPhotoByURL\"><value name=\"url\"><shadow type=\"text\"><field name=\"TEXT\">https://www.magicubedu.com/una/AI1/2.jpg</field></shadow></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">visionAnalysisResult</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"UnaAI_detectObjects\"><value name=\"img\"><block type=\"variables_get\"><field name=\"VAR\">photo</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">JsonValue</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"UnaAI_AiResult_getContentAsJsonValue\"><value name=\"result\"><block type=\"variables_get\"><field name=\"VAR\">visionAnalysisResult</field></block></value></block></value><next><block type=\"basic_consoleLogText\"><value name=\"text\"><block type=\"Json_JsonValue_stringify\"><value name=\"jsonValue\"><block type=\"variables_get\"><field name=\"VAR\">JsonValue</field></block></value></block></value><next><block type=\"Camera_showPhoto\"><value name=\"photo\"><block type=\"variables_get\"><field name=\"VAR\">photo</field></block></value></block></next></block></next></block></next></block></next></block></statement></block></xml>"}
输出:
物件检测
照片内部的物体检测
检测照片中的物件
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>photo</variable><variable>visionAnalysisResult</variable><variable>JsonValue</variable><variable>result</variable></variables><block type=\"UnaAI_detectObjects\" disabled=\"true\" x=\"248\" y=\"383\"/></xml>"}
这用于检测图像或照片中的物体。
参数: 相片
输出: Json Value
示例代码:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>photo</variable><variable>visionAnalysisResult</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">photo</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Resources_getPhotoByURL\"><value name=\"url\"><shadow type=\"text\"><field name=\"TEXT\">https://www.magicubedu.com/una/AI1/2.jpg</field></shadow></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">visionAnalysisResult</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"UnaAI_detectObjects\"><value name=\"img\"><block type=\"variables_get\"><field name=\"VAR\">photo</field></block></value></block></value><next><block type=\"UnaAI_AiResult_showContent\"><value name=\"result\"><block type=\"variables_get\"><field name=\"VAR\">visionAnalysisResult</field></block></value><next><block type=\"UnaAI_VisionAnalysisResult_markObjects\"><value name=\"visionAnalysisResult\"><block type=\"variables_get\"><field name=\"VAR\">visionAnalysisResult</field></block></value></block></next></block></next></block></next></block></statement></block></xml>"}
输出:
检查对象检测,包括关键字
视觉分析结果包含
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>photo</variable><variable>visionAnalysisResult</variable></variables><block type=\"UnaAI_VisionAnalysisResult_hasObject\" disabled=\"true\" x=\"112\" y=\"337\"><value name=\"visionAnalysisResult\"><block type=\"variables_get\" disabled=\"true\"><field name=\"VAR\">visionAnalysisResult</field></block></value><value name=\"objName\"><shadow type=\"text\" disabled=\"true\"><field name=\"TEXT\"/></shadow></value></block></xml>"}
这用于检查物件是否包含特定术语。
参数:
- AI结果(来自Azure的物体检测)
- 显示设置:字串
输出: 布尔值 (True/False)
示例代码:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>photo</variable><variable>visionAnalysisResult</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">photo</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Resources_getPhotoByURL\"><value name=\"url\"><shadow type=\"text\"><field name=\"TEXT\">https://www.magicubedu.com/una/AI1/2.jpg</field></shadow></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">visionAnalysisResult</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"UnaAI_detectObjects\"><value name=\"img\"><block type=\"variables_get\"><field name=\"VAR\">photo</field></block></value></block></value><next><block type=\"controls_if\"><mutation else=\"1\"/><value name=\"IF0\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">TRUE</field></shadow><block type=\"UnaAI_VisionAnalysisResult_hasObject\"><value name=\"visionAnalysisResult\"><block type=\"variables_get\"><field name=\"VAR\">visionAnalysisResult</field></block></value><value name=\"objName\"><shadow type=\"text\"><field name=\"TEXT\">Apple</field></shadow></value></block></value><statement name=\"DO0\"><block type=\"basic_consoleLogText\"><value name=\"text\"><shadow type=\"text\"><field name=\"TEXT\">It is an apple.</field></shadow></value></block></statement><statement name=\"ELSE\"><block type=\"basic_consoleLogText\"><value name=\"text\"><shadow type=\"text\"><field name=\"TEXT\">It is not an apple.</field></shadow></value></block></statement></block></next></block></next></block></statement></block></xml>"}
输出:
将物体检测结果放入图像中
视觉分析结果在照片上标记物体
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>photo</variable><variable>visionAnalysisResult</variable></variables><block type=\"UnaAI_VisionAnalysisResult_hasObject\" disabled=\"true\" x=\"112\" y=\"337\"><value name=\"visionAnalysisResult\"><block type=\"variables_get\" disabled=\"true\"><field name=\"VAR\">visionAnalysisResult</field></block></value><value name=\"objName\"><shadow type=\"text\" disabled=\"true\"><field name=\"TEXT\"/></shadow></value></block></xml>"}
这用于标记照片内的边界框。
参数: AI结果(来自Azure的物体检测)
输出: 相片
示例代码:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>photo</variable><variable>visionAnalysisResult</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">photo</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Resources_getPhotoByURL\"><value name=\"url\"><shadow type=\"text\"><field name=\"TEXT\">https://www.magicubedu.com/una/AI5/samples/man1.jpg</field></shadow></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">visionAnalysisResult</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"UnaAI_detectObjects\"><value name=\"img\"><block type=\"variables_get\"><field name=\"VAR\">photo</field></block></value></block></value><next><block type=\"UnaAI_VisionAnalysisResult_markObjects\"><value name=\"visionAnalysisResult\"><block type=\"variables_get\"><field name=\"VAR\">visionAnalysisResult</field></block></value></block></next></block></next></block></statement></block></xml>"}
输出:
人脸检测和验证
使用相似性置信度进行人脸比较
验证并具有相同的面孔
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>photo</variable><variable>visionAnalysisResult</variable></variables><block type=\"UnaAI_verifyFaces\" disabled=\"true\" x=\"0\" y=\"0\"/></xml>"}
这用于识别两张面孔之间的相似性置信度。
参数: AI结果(来自Azure的物体检测)
输出: Json Value
示例代码:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>photo1</variable><variable>photo2</variable><variable>faceDetectionResult1</variable><variable>faceDetectionResult2</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">photo1</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Resources_getPhotoByURL\"><value name=\"url\"><shadow type=\"text\"><field name=\"TEXT\">https://www.magicubedu.com/una/AI5/samples/man1.jpg</field></shadow></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">photo2</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Resources_getPhotoByURL\"><value name=\"url\"><shadow type=\"text\"><field name=\"TEXT\">https://www.magicubedu.com/una/AI5/samples/man2.jpg</field></shadow></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">faceDetectionResult1</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"UnaAI_detectFaces\"><value name=\"img\"><block type=\"variables_get\"><field name=\"VAR\">photo1</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">faceDetectionResult2</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"UnaAI_detectFaces\"><value name=\"img\"><block type=\"variables_get\"><field name=\"VAR\">photo2</field></block></value></block></value><next><block type=\"Camera_showPhoto\"><value name=\"photo\"><block type=\"variables_get\"><field name=\"VAR\">photo1</field></block></value><next><block type=\"Camera_showPhoto\"><value name=\"photo\"><block type=\"variables_get\"><field name=\"VAR\">photo2</field></block></value><next><block type=\"UnaAI_AiResult_showContent\"><value name=\"result\"><block type=\"UnaAI_verifyFaces\"><value name=\"face1\"><block type=\"variables_get\"><field name=\"VAR\">faceDetectionResult1</field></block></value><value name=\"face2\"><block type=\"variables_get\"><field name=\"VAR\">faceDetectionResult2</field></block></value></block></value></block></next></block></next></block></next></block></next></block></next></block></next></block></statement></block></xml>"}
输出:
照片中的人脸检测
检测照片中的人脸
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>photo1</variable><variable>photo2</variable><variable>faceDetectionResult1</variable><variable>faceDetectionResult2</variable></variables><block type=\"UnaAI_detectObjects\" disabled=\"true\" x=\"-22\" y=\"202\"/></xml>"}
这用于检测图像或照片中的人脸。
参数: 相片
输出: Json Value
示例代码:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>photo</variable><variable>faceDetectionResult</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">photo</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Resources_getPhotoByURL\"><value name=\"url\"><shadow type=\"text\"><field name=\"TEXT\">https://www.magicubedu.com/una/AI5/samples/man1.jpg</field></shadow></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">faceDetectionResult</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"UnaAI_detectFaces\"><value name=\"img\"><block type=\"variables_get\"><field name=\"VAR\">photo</field></block></value></block></value><next><block type=\"UnaAI_AiResult_showContent\"><value name=\"result\"><block type=\"variables_get\"><field name=\"VAR\">faceDetectionResult</field></block></value></block></next></block></next></block></statement></block></xml>"}
输出:
使用相似性置信度进行人脸比较
人脸验证结果:获得人脸相似度置信度
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>photo</variable><variable>faceDetectionResult</variable><variable>photo1</variable><variable>photo2</variable><variable>faceDetectionResult1</variable><variable>faceDetectionResult2</variable><variable>faceVerificationResult</variable></variables><block type=\"UnaAI_FaceVerificationResult_getSimilarityConfidence\" disabled=\"true\" x=\"158\" y=\"337\"><value name=\"faceVerificationResult\"><block type=\"variables_get\" disabled=\"true\"><field name=\"VAR\">faceVerificationResult</field></block></value></block></xml>"}
这用于获取两张面孔相似度置信度。
参数: AI 结果(来自 Azure 的人脸检测)
输出: AI 结果
示例代码:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>photo1</variable><variable>photo2</variable><variable>faceDetectionResult1</variable><variable>faceDetectionResult2</variable><variable>faceVerificationResult</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">photo1</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Resources_getPhotoByURL\"><value name=\"url\"><shadow type=\"text\"><field name=\"TEXT\">https://www.magicubedu.com/una/AI5/samples/man1.jpg</field></shadow></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">photo2</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Resources_getPhotoByURL\"><value name=\"url\"><shadow type=\"text\"><field name=\"TEXT\">https://www.magicubedu.com/una/AI5/samples/man2.jpg</field></shadow></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">faceDetectionResult1</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"UnaAI_detectFaces\"><value name=\"img\"><block type=\"variables_get\"><field name=\"VAR\">photo1</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">faceDetectionResult2</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"UnaAI_detectFaces\"><value name=\"img\"><block type=\"variables_get\"><field name=\"VAR\">photo2</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">faceVerificationResult</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"UnaAI_verifyFaces\"><value name=\"face1\"><block type=\"variables_get\"><field name=\"VAR\">faceDetectionResult1</field></block></value><value name=\"face2\"><block type=\"variables_get\"><field name=\"VAR\">faceDetectionResult2</field></block></value></block></value><next><block type=\"UnaAI_FaceDetectionResult_markFaces\"><field name=\"attribute\">FaceAttribute.Age</field><value name=\"faceDetectionResult\"><block type=\"variables_get\"><field name=\"VAR\">faceDetectionResult1</field></block></value><next><block type=\"UnaAI_FaceDetectionResult_markFaces\"><field name=\"attribute\">FaceAttribute.Age</field><value name=\"faceDetectionResult\"><block type=\"variables_get\"><field name=\"VAR\">faceDetectionResult2</field></block></value><next><block type=\"basic_consoleLogNum\"><value name=\"num\"><block type=\"UnaAI_FaceVerificationResult_getSimilarityConfidence\"><value name=\"faceVerificationResult\"><block type=\"variables_get\"><field name=\"VAR\">faceVerificationResult</field></block></value></block></value></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></statement></block></xml>"}
输出:
计算年龄范围内的人脸数量
人脸检测结果 计数 人脸老化
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>photo1</variable><variable>photo2</variable><variable>faceDetectionResult1</variable><variable>faceDetectionResult2</variable><variable>faceVerificationResult</variable><variable>faceDetectionResult</variable></variables><block type=\"UnaAI_FaceDetectionResult_countAge\" disabled=\"true\" x=\"-22\" y=\"337\"><field name=\"operator\">ConditionalOperator.EqualTo</field><value name=\"faceDetectionResult\"><block type=\"variables_get\" disabled=\"true\"><field name=\"VAR\">faceDetectionResult</field></block></value><value name=\"age\"><shadow type=\"math_number\" disabled=\"true\"><field name=\"NUM\">0</field></shadow></value></block></xml>"}
此块用于计算年龄范围内的人脸总数。
参数:
- AI 结果(来自 Azure 的人脸检测)
- 条件:
- 运算符:=(默认)/≠/≤/>/≥
- 数字(预设值:0)
输出: AI 结果
示例代码:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>photo</variable><variable>faceDetectionResult</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">photo</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Resources_getPhotoByURL\"><value name=\"url\"><shadow type=\"text\"><field name=\"TEXT\">https://www.magicubedu.com/una/AI5/samples/man1.jpg</field></shadow></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">faceDetectionResult</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"UnaAI_detectFaces\"><value name=\"img\"><block type=\"variables_get\"><field name=\"VAR\">photo</field></block></value></block></value><next><block type=\"basic_consoleLogNum\"><value name=\"num\"><block type=\"UnaAI_FaceDetectionResult_countAge\"><field name=\"operator\">ConditionalOperator.EqualTo</field><value name=\"faceDetectionResult\"><block type=\"variables_get\"><field name=\"VAR\">faceDetectionResult</field></block></value><value name=\"age\"><shadow type=\"math_number\"><field name=\"NUM\">32</field></shadow></value></block></value><next><block type=\"UnaAI_FaceDetectionResult_markFaces\"><field name=\"attribute\">FaceAttribute.Age</field><value name=\"faceDetectionResult\"><block type=\"variables_get\"><field name=\"VAR\">faceDetectionResult</field></block></value></block></next></block></next></block></next></block></statement></block></xml>"}
输出:
计算人脸总数
人脸检测结果 人脸计数
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>photo</variable><variable>faceDetectionResult</variable><variable>photo1</variable><variable>photo2</variable><variable>faceDetectionResult1</variable><variable>faceDetectionResult2</variable><variable>faceVerificationResult</variable></variables><block type=\"UnaAI_FaceDetectionResult_count\" disabled=\"true\" x=\"-22\" y=\"382\"><value name=\"faceDetectionResult\"><block type=\"variables_get\" disabled=\"true\"><field name=\"VAR\">faceDetectionResult</field></block></value></block></xml>"}
这用于计算图像中的人脸数量。
参数: AI 结果(来自 Azure 的人脸检测)
输出: AI 结果
示例代码:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>photo</variable><variable>faceDetectionResult</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">photo</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Resources_getPhotoByURL\"><value name=\"url\"><shadow type=\"text\"><field name=\"TEXT\">https://static01.nyt.com/images/2019/10/02/video/02-still-for-america-room-loop/02-still-for-america-room-loop-superJumbo.jpg</field></shadow></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">faceDetectionResult</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"UnaAI_detectFaces\"><value name=\"img\"><block type=\"variables_get\"><field name=\"VAR\">photo</field></block></value></block></value><next><block type=\"basic_consoleLogNum\"><value name=\"num\"><block type=\"UnaAI_FaceDetectionResult_count\"><value name=\"faceDetectionResult\"><block type=\"variables_get\"><field name=\"VAR\">faceDetectionResult</field></block></value></block></value><next><block type=\"UnaAI_FaceDetectionResult_markFaces\"><field name=\"attribute\">FaceAttribute.Age</field><value name=\"faceDetectionResult\"><block type=\"variables_get\"><field name=\"VAR\">faceDetectionResult</field></block></value></block></next></block></next></block></next></block></statement></block></xml>"}
输出:
将人脸检测结果放入图像中
人脸检测结果 用…在照片上
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>photo</variable><variable>faceDetectionResult</variable></variables><block type=\"UnaAI_FaceDetectionResult_markFaces\" disabled=\"true\" x=\"23\" y=\"113\"><field name=\"attribute\">FaceAttribute.Age</field><value name=\"faceDetectionResult\"><block type=\"variables_get\" disabled=\"true\"><field name=\"VAR\">faceDetectionResult</field></block></value></block></xml>"}
此块用于在图像内显示具有不同属性的边界框。
参数:
- AI 结果(来自 Azure 的人脸检测)
- 条件:年龄(默认)/情感/性别/眼镜类型/主要发色/微笑
输出: 图片
示例代码:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>photo</variable><variable>faceDetectionResult</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">photo</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Resources_getPhotoByURL\"><value name=\"url\"><shadow type=\"text\"><field name=\"TEXT\">https://www.magicubedu.com/una/AI5/samples/man1.jpg</field></shadow></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">faceDetectionResult</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"UnaAI_detectFaces\"><value name=\"img\"><block type=\"variables_get\"><field name=\"VAR\">photo</field></block></value></block></value><next><block type=\"UnaAI_FaceDetectionResult_markFaces\"><field name=\"attribute\">FaceAttribute.Age</field><value name=\"faceDetectionResult\"><block type=\"variables_get\"><field name=\"VAR\">faceDetectionResult</field></block></value></block></next></block></next></block></statement></block></xml>"}
输出:
更多 UnaAI
查找包含相关发色的人
人脸检测结果 计算头发颜色的人脸…
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>photo</variable><variable>faceDetectionResult</variable></variables><block type=\"UnaAI_FaceDetectionResult_countHairColor\" disabled=\"true\" x=\"67\" y=\"247\"><value name=\"faceDetectionResult\"><block type=\"variables_get\" disabled=\"true\"><field name=\"VAR\">faceDetectionResult</field></block></value><value name=\"color\"><shadow type=\"text\" disabled=\"true\"><field name=\"TEXT\"/></shadow></value></block></xml>"}
寻找戴眼镜的人
人脸检测结果 计算戴眼镜的人脸
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>photo</variable><variable>faceDetectionResult</variable></variables><block type=\"UnaAI_FaceDetectionResult_countGlasses\" disabled=\"true\" x=\"22\" y=\"203\"><value name=\"faceDetectionResult\"><block type=\"variables_get\" disabled=\"true\"><field name=\"VAR\">faceDetectionResult</field></block></value></block></xml>"}
人脸检测结果 计算男性的人脸
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>photo</variable><variable>faceDetectionResult</variable></variables><block type=\"UnaAI_FaceDetectionResult_countGender\" disabled=\"true\" x=\"-22\" y=\"202\"><field name=\"gender\">Gender.M</field><value name=\"faceDetectionResult\"><block type=\"variables_get\" disabled=\"true\"><field name=\"VAR\">faceDetectionResult</field></block></value></block></xml>"}
这用于计算有多少人是男性/女性。
参数:
- AI 结果(来自 Azure 的人脸检测)
- 显示设置:公头(默认)/母头
输出: 图片
示例代码:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>photo</variable><variable>faceDetectionResult</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">photo</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Resources_getPhotoByURL\"><value name=\"url\"><shadow type=\"text\"><field name=\"TEXT\">https://pbs.twimg.com/media/CQG1slyWIAASBJX.jpg</field></shadow></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">faceDetectionResult</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"UnaAI_detectFaces\"><value name=\"img\"><block type=\"variables_get\"><field name=\"VAR\">photo</field></block></value></block></value><next><block type=\"UnaAI_FaceDetectionResult_markFaces\"><field name=\"attribute\">FaceAttribute.Gender</field><value name=\"faceDetectionResult\"><block type=\"variables_get\"><field name=\"VAR\">faceDetectionResult</field></block></value><next><block type=\"basic_consoleLogNum\"><value name=\"num\"><block type=\"UnaAI_FaceDetectionResult_countGender\"><field name=\"gender\">Gender.M</field><value name=\"faceDetectionResult\"><block type=\"variables_get\"><field name=\"VAR\">faceDetectionResult</field></block></value></block></value></block></next></block></next></block></next></block></statement></block></xml>"}
输出:
寻找微笑的人
人脸检测结果 计算带笑容的面孔
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>photo</variable><variable>faceDetectionResult</variable></variables><block type=\"UnaAI_FaceDetectionResult_countSmile\" disabled=\"true\" x=\"-22\" y=\"292\"><value name=\"faceDetectionResult\"><block type=\"variables_get\" disabled=\"true\"><field name=\"VAR\">faceDetectionResult</field></block></value></block></xml>"}
这用于计算有多少人在微笑。
参数: AI 结果(来自 Azure 的人脸检测)
输出: AI 结果
示例代码:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>photo</variable><variable>faceDetectionResult</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">photo</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Resources_getPhotoByURL\"><value name=\"url\"><shadow type=\"text\"><field name=\"TEXT\">https://s.wsj.net/public/resources/images/BN-IR696_smilep_P_20150601134828.jpg</field></shadow></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">faceDetectionResult</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"UnaAI_detectFaces\"><value name=\"img\"><block type=\"variables_get\"><field name=\"VAR\">photo</field></block></value></block></value><next><block type=\"UnaAI_FaceDetectionResult_markFaces\"><field name=\"attribute\">FaceAttribute.Smile</field><value name=\"faceDetectionResult\"><block type=\"variables_get\"><field name=\"VAR\">faceDetectionResult</field></block></value><next><block type=\"basic_consoleLogNum\"><value name=\"num\"><block type=\"UnaAI_FaceDetectionResult_countSmile\"><value name=\"faceDetectionResult\"><block type=\"variables_get\"><field name=\"VAR\">faceDetectionResult</field></block></value></block></value></block></next></block></next></block></next></block></statement></block></xml>"}
输出:
寻找具有特定情感和价值的人
人脸检测结果 计算带有情绪的面孔 愤怒 值 > 0
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>photo</variable><variable>faceDetectionResult</variable></variables><block type=\"UnaAI_FaceDetectionResult_countEmotion\" disabled=\"true\" x=\"22\" y=\"248\"><field name=\"emotion\">Emotion.Anger</field><value name=\"faceDetectionResult\"><block type=\"variables_get\" disabled=\"true\"><field name=\"VAR\">faceDetectionResult</field></block></value><value name=\"value\"><shadow type=\"math_number\" disabled=\"true\"><field name=\"NUM\">0</field></shadow></value></block></xml>"}
当人们有不同的情绪时,这用于计算面孔。
参数: AI 结果(来自 Azure 的人脸检测)
条件:
- 愤怒(默认)/轻蔑/厌恶/恐惧/快乐/中性/悲伤/惊讶
- 数字(预设值:0)
输出: AI 结果
示例代码:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>photo</variable><variable>faceDetectionResult</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">photo</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Resources_getPhotoByURL\"><value name=\"url\"><shadow type=\"text\"><field name=\"TEXT\">https://liveboldandbloom.com/wp-content/uploads/2020/04/Untitled-design-14-1.png</field></shadow></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">faceDetectionResult</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"UnaAI_detectFaces\"><value name=\"img\"><block type=\"variables_get\"><field name=\"VAR\">photo</field></block></value></block></value><next><block type=\"UnaAI_FaceDetectionResult_markFaces\"><field name=\"attribute\">FaceAttribute.Emotion</field><value name=\"faceDetectionResult\"><block type=\"variables_get\"><field name=\"VAR\">faceDetectionResult</field></block></value><next><block type=\"basic_consoleLogNum\"><value name=\"num\"><block type=\"UnaAI_FaceDetectionResult_countEmotion\"><field name=\"emotion\">Emotion.Anger</field><value name=\"faceDetectionResult\"><block type=\"variables_get\"><field name=\"VAR\">faceDetectionResult</field></block></value><value name=\"value\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow></value></block></value></block></next></block></next></block></next></block></statement></block></xml>"}
输出:
目录