add_face_blocks
This commit is contained in:
@@ -1037,6 +1037,25 @@ Blockly.Blocks['datamap_recieved'] = {
|
||||
}
|
||||
};
|
||||
|
||||
Blockly.Blocks['face_recognized'] = {
|
||||
init: function() {
|
||||
this.setColour(datamap_HUE);
|
||||
this.appendDummyInput().appendField(Blockly.MIXLY_MICROBIT_JS_CURRENT);
|
||||
this.appendValueInput("name").setCheck("String");
|
||||
this.appendDummyInput().appendField(Blockly.FACE_RECOGNIZED);
|
||||
this.appendDummyInput().appendField(Blockly.Msg.PROCEDURES_CALL_BEFORE_PARAMS+"id, status, faceName, isMouthOpen, faceProbability, happy, sad, angry, surprised, disgusted, fearful");
|
||||
this.setInputsInline(true);
|
||||
this.appendStatementInput('DO0').appendField(Blockly.Msg.CONTROLS_REPEAT_INPUT_DO);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setTooltip("");
|
||||
},
|
||||
getVars:function(){
|
||||
return ["clientid","long","lat","message"];
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Blockly.Blocks['datamap_send'] = {
|
||||
init: function() {
|
||||
this.appendDummyInput().appendField(Blockly.TO);
|
||||
@@ -2500,6 +2519,13 @@ Blockly.JavaScript.datamap_recieved=function(block) {
|
||||
return code;
|
||||
};
|
||||
|
||||
Blockly.JavaScript.face_recognized =function(block) {
|
||||
var name = Blockly.JavaScript.valueToCode(this, 'name', Blockly.JavaScript.ORDER_ATOMIC);
|
||||
var code="MixIO.getInstance("+name+",MixIO.typeTags.FACE)\n"+".bind(MixIO.eventTags.FACE_RECOGNIZED, function(event,id,status,faceName,isMouthOpen,faceProbability,happy,sad,angry,surprised,disgusted,fearful){\n"
|
||||
+Blockly.JavaScript.statementToCode(block, "DO0" )+"\n"+"})\n"
|
||||
return code;
|
||||
};
|
||||
|
||||
Blockly.JavaScript.datamap_send=function(block) {
|
||||
var name = Blockly.JavaScript.valueToCode(this, 'name', Blockly.JavaScript.ORDER_ATOMIC);
|
||||
var long = Blockly.JavaScript.valueToCode(this, 'long', Blockly.JavaScript.ORDER_ATOMIC);
|
||||
@@ -3412,6 +3438,7 @@ Blockly.DATAMAP_LAT="纬度";
|
||||
Blockly.DATAMAP_SEND_MESSAGE="发送消息列表";
|
||||
Blockly.CLEAR_DATAMAP="数据地图清空";
|
||||
Blockly.CLEAR_PIXEL="点阵屏清空画布";
|
||||
Blockly.FACE_RECOGNIZED = "人脸识别组件识别到人脸时"
|
||||
|
||||
Blockly.WS_UPDATED="气象仪更新数据时";
|
||||
Blockly.WS_SEND="气象仪发送数据时";
|
||||
|
||||
@@ -1090,7 +1090,15 @@
|
||||
</value>
|
||||
</block>
|
||||
</category>
|
||||
<category name="人脸识别" colour="#4e73df" css-icon="customIcon fa fa-smile-o"></category>
|
||||
<category name="人脸识别" colour="#4e73df" css-icon="customIcon fa fa-smile-o">
|
||||
<block type="face_recognized">
|
||||
<value name="name">
|
||||
<shadow type="text">
|
||||
<field name="TEXT">name</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
</category>
|
||||
<category name="蜂鸣器" colour="#4e73df" css-icon="customIcon fa fa-bell-o"></category>
|
||||
<category name="二维码识别" colour="#4e73df" css-icon="customIcon fa fa-qrcode"></category>
|
||||
</xml>
|
||||
|
||||
11
js/MixIO.js
11
js/MixIO.js
@@ -86,13 +86,14 @@ var MixIO = {
|
||||
CAMERA: 17,
|
||||
MIC: 18,
|
||||
SELECT: 19,
|
||||
PIXEL: 20
|
||||
PIXEL: 20,
|
||||
FACE: 21
|
||||
},
|
||||
|
||||
oldTags: ["input_button", "input_slider", "input_keyboard", "input_controller", "input_rgb", "output_bulb", "output_text",
|
||||
"output_chart", "output_bar", "table", "output_dashboard", "output_map", "input_weather", "timer", "trigger", "ble", "camera", "input_mic", "tinydb", "pixel"
|
||||
"output_chart", "output_bar", "table", "output_dashboard", "output_map", "input_weather", "timer", "trigger", "ble", "camera", "input_mic", "tinydb", "pixel", "face"
|
||||
],
|
||||
zhcnTags: ["按键/开关", "滑杆", "文本输入", "摇杆手柄", "RGB色盘", "指示灯", "文本显示屏", "折线图表", "柱状图表", "数据表格", "仪表盘", "数据地图", "实时气象仪", "定时触发器", "条件触发器", "蓝牙转发器", "摄像头", "语音识别", "下拉选项", "点阵屏"],
|
||||
zhcnTags: ["按键/开关", "滑杆", "文本输入", "摇杆手柄", "RGB色盘", "指示灯", "文本显示屏", "折线图表", "柱状图表", "数据表格", "仪表盘", "数据地图", "实时气象仪", "定时触发器", "条件触发器", "蓝牙转发器", "摄像头", "语音识别", "下拉选项", "点阵屏", "人脸识别"],
|
||||
|
||||
/*合法的MixIO事件种类*/
|
||||
eventTags: {
|
||||
@@ -140,7 +141,9 @@ var MixIO = {
|
||||
|
||||
MIC_SENT: "1811",
|
||||
|
||||
SELECT_SENT: "1911"
|
||||
SELECT_SENT: "1911",
|
||||
|
||||
FACE_RECOGNIZED: "2111"
|
||||
|
||||
},
|
||||
|
||||
|
||||
@@ -6631,10 +6631,17 @@ function add_face(user_title, user_topic, user_content, user_style, title_style)
|
||||
}
|
||||
if(!lastPublishTime || new Date().getTime() - lastFacePublishTime >= interval)
|
||||
{
|
||||
// Aug 2025
|
||||
if(min_index == -1)
|
||||
{
|
||||
publish(user_topic, JSON.stringify({id: min_index, status: (min_index==-1?0:1), name: "Unknown", isMouthOpen: isMouthOpen, faceProbability: resizedDetections[0].detection.score.toFixed(3), happy: resizedDetections[0].expressions.happy.toFixed(3), sad: resizedDetections[0].expressions.sad.toFixed(3), angry: resizedDetections[0].expressions.angry.toFixed(3), surprised: resizedDetections[0].expressions.surprised.toFixed(3), disgusted: resizedDetections[0].expressions.disgusted.toFixed(3), fearful: resizedDetections[0].expressions.fearful.toFixed(3)}))
|
||||
itemdiv.trigger(MixIO.eventTags.FACE_RECOGNIZED, [min_index, (min_index==-1?0:1), "Unknown", isMouthOpen, resizedDetections[0].detection.score.toFixed(3), resizedDetections[0].expressions.happy.toFixed(3), resizedDetections[0].expressions.sad.toFixed(3), resizedDetections[0].expressions.angry.toFixed(3), resizedDetections[0].expressions.surprised.toFixed(3), resizedDetections[0].expressions.disgusted.toFixed(3), resizedDetections[0].expressions.fearful.toFixed(3)])
|
||||
}
|
||||
else
|
||||
{
|
||||
publish(user_topic, JSON.stringify({id: min_index, status: (min_index==-1?0:1), name: user_data[min_index]["name"], isMouthOpen: isMouthOpen, faceProbability: resizedDetections[0].detection.score.toFixed(3), happy: resizedDetections[0].expressions.happy.toFixed(3), sad: resizedDetections[0].expressions.sad.toFixed(3), angry: resizedDetections[0].expressions.angry.toFixed(3), surprised: resizedDetections[0].expressions.surprised.toFixed(3), disgusted: resizedDetections[0].expressions.disgusted.toFixed(3), fearful: resizedDetections[0].expressions.fearful.toFixed(3)}))
|
||||
itemdiv.trigger(MixIO.eventTags.FACE_RECOGNIZED, [min_index, (min_index==-1?0:1), user_data[min_index]["name"], isMouthOpen, resizedDetections[0].detection.score.toFixed(3), resizedDetections[0].expressions.happy.toFixed(3), resizedDetections[0].expressions.sad.toFixed(3), resizedDetections[0].expressions.angry.toFixed(3), resizedDetections[0].expressions.surprised.toFixed(3), resizedDetections[0].expressions.disgusted.toFixed(3), resizedDetections[0].expressions.fearful.toFixed(3)])
|
||||
}
|
||||
lastFacePublishTime = new Date().getTime()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user