|
@@ -1021,6 +1021,20 @@ Blockly.Python.ai_lcd_showcarvas_set_display = function (block) {
|
|
Blockly.Python.definitions_['v831_import_camera'] = `from maix import camera`;
|
|
Blockly.Python.definitions_['v831_import_camera'] = `from maix import camera`;
|
|
Blockly.Python.addVariable(`_canvas_x`, `_canvas_x = 0`, true)
|
|
Blockly.Python.addVariable(`_canvas_x`, `_canvas_x = 0`, true)
|
|
Blockly.Python.addVariable(`_canvas_y`, `_canvas_y = 0`, true)
|
|
Blockly.Python.addVariable(`_canvas_y`, `_canvas_y = 0`, true)
|
|
|
|
+ Blockly.Python.definitions_['import_image'] = `image.load_freetype("/root/preset/fonts/simhei.ttf")
|
|
|
|
+if cameraSize==True:
|
|
|
|
+ camera.camera.config(size=(320,240))
|
|
|
|
+else:
|
|
|
|
+ camera.camera.config(size=(240,320))
|
|
|
|
+try:
|
|
|
|
+ if ScreenOrientation==True:
|
|
|
|
+ canvas = image.new(size = (240, 320))
|
|
|
|
+ else:
|
|
|
|
+ canvas = image.new(size = (320, 240))
|
|
|
|
+except:
|
|
|
|
+ canvas = image.new(size = (320, 240))
|
|
|
|
+ pass
|
|
|
|
+`
|
|
Blockly.Python.definitions_[`v831_display_show_canvas`] = `def v831_display_show_canvas(displayShow):
|
|
Blockly.Python.definitions_[`v831_display_show_canvas`] = `def v831_display_show_canvas(displayShow):
|
|
global _canvas_y,_canvas_x,ScreenOrientation,cameraSize
|
|
global _canvas_y,_canvas_x,ScreenOrientation,cameraSize
|
|
CANVASSHOWIMGAGE = ""
|
|
CANVASSHOWIMGAGE = ""
|
|
@@ -2564,10 +2578,14 @@ CAMERATYPE()
|
|
Blockly.Python.definitions_['lcd_invert_init'] = `def lcdRotation(inputImg):
|
|
Blockly.Python.definitions_['lcd_invert_init'] = `def lcdRotation(inputImg):
|
|
global SETVFLIP,SETHMIRROT,cameraSize,ScreenOrientation
|
|
global SETVFLIP,SETHMIRROT,cameraSize,ScreenOrientation
|
|
imageRotationBuffer = inputImg.crop(0, 0, 240, 320)
|
|
imageRotationBuffer = inputImg.crop(0, 0, 240, 320)
|
|
- if ScreenOrientation:
|
|
|
|
- imgRotationAim = image.new(size = (240, 320))
|
|
|
|
- rotationAngle = 180
|
|
|
|
- else:
|
|
|
|
|
|
+ try:
|
|
|
|
+ if ScreenOrientation:
|
|
|
|
+ imgRotationAim = image.new(size = (240, 320))
|
|
|
|
+ rotationAngle = 180
|
|
|
|
+ else:
|
|
|
|
+ imgRotationAim = image.new(size = (320, 240))
|
|
|
|
+ rotationAngle = 90
|
|
|
|
+ except:
|
|
imgRotationAim = image.new(size = (320, 240))
|
|
imgRotationAim = image.new(size = (320, 240))
|
|
rotationAngle = 90
|
|
rotationAngle = 90
|
|
GETROTATION = imageRotationBuffer.rotate(+rotationAngle, adjust=1)
|
|
GETROTATION = imageRotationBuffer.rotate(+rotationAngle, adjust=1)
|
|
@@ -2577,11 +2595,15 @@ CAMERATYPE()
|
|
Blockly.Python.definitions_['lcd_invert_init_new'] = `def lcdRotationNew(inputImg):
|
|
Blockly.Python.definitions_['lcd_invert_init_new'] = `def lcdRotationNew(inputImg):
|
|
global SETVFLIP,SETHMIRROT,cameraSize,ScreenOrientation
|
|
global SETVFLIP,SETHMIRROT,cameraSize,ScreenOrientation
|
|
imageRotationBuffer = inputImg.crop(0, 0, 320, 240)
|
|
imageRotationBuffer = inputImg.crop(0, 0, 320, 240)
|
|
- if ScreenOrientation:
|
|
|
|
- imgRotationAim = image.new(size = (240, 320))
|
|
|
|
- rotationAngle = 90
|
|
|
|
- GETROTATION = imageRotationBuffer.rotate(+rotationAngle, adjust=1)
|
|
|
|
- else:
|
|
|
|
|
|
+ try:
|
|
|
|
+ if ScreenOrientation:
|
|
|
|
+ imgRotationAim = image.new(size = (240, 320))
|
|
|
|
+ rotationAngle = 90
|
|
|
|
+ GETROTATION = imageRotationBuffer.rotate(+rotationAngle, adjust=1)
|
|
|
|
+ else:
|
|
|
|
+ imgRotationAim = image.new(size = (320, 240))
|
|
|
|
+ GETROTATION = imageRotationBuffer
|
|
|
|
+ except:
|
|
imgRotationAim = image.new(size = (320, 240))
|
|
imgRotationAim = image.new(size = (320, 240))
|
|
GETROTATION = imageRotationBuffer
|
|
GETROTATION = imageRotationBuffer
|
|
|
|
|
|
@@ -8755,24 +8777,43 @@ Blockly.Blocks['ai_model_digital'] = {
|
|
init: function () {
|
|
init: function () {
|
|
this.appendDummyInput()
|
|
this.appendDummyInput()
|
|
.appendField(Blockly.Msg.ai_model_digital);
|
|
.appendField(Blockly.Msg.ai_model_digital);
|
|
|
|
+ // this.appendDummyInput()
|
|
|
|
+ // .appendField(new Blockly.FieldDropdown([
|
|
|
|
+ // [Blockly.Msg.ai_models_hand_written_model_number, "digitalResult"],
|
|
|
|
+ // [Blockly.Msg.ai_models_hand_written_model_confidence, "digitalConfidence"],
|
|
|
|
+ // ["检测框", "digitalCheckout"]
|
|
|
|
+ // ]), "digital");
|
|
this.setInputsInline(false);
|
|
this.setInputsInline(false);
|
|
- this.setOutput(true, null);
|
|
|
|
|
|
+ this.setPreviousStatement(true, null);
|
|
|
|
+ this.setNextStatement(true, null);
|
|
this.setColour("#ee783a");
|
|
this.setColour("#ee783a");
|
|
- this.setTooltip(Blockly.Msg.ai_model_digital);
|
|
|
|
|
|
+ this.setTooltip();
|
|
this.setHelpUrl("");
|
|
this.setHelpUrl("");
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
|
|
Blockly.Python.ai_model_digital = function (block) {
|
|
Blockly.Python.ai_model_digital = function (block) {
|
|
- var _code = "boxes";
|
|
|
|
- return [_code, Blockly.Python.ORDER_ATOMIC];
|
|
|
|
|
|
+ Blockly.Python.addVariable("getDigitalResult", `getDigitalResult = []`)
|
|
|
|
+ Blockly.Python.addFunction("digitalShowCanvas",`def digitalShowCanvas():
|
|
|
|
+ global BOXES,getDigitalResult
|
|
|
|
+ getDigitalResult = []
|
|
|
|
+ if len(BOXES):
|
|
|
|
+ for BOXESI, BOXOBJ in enumerate(BOXES):
|
|
|
|
+ canvas.draw_string(0,0, (str(number_recognition.labels[PROBS[BOXESI][0]]) + str(str(":") + str(round(PROBS[BOXESI][1][PROBS[BOXESI][0]]*100, 2)))), scale = 1, color = (255,0,0) , thickness = 1)
|
|
|
|
+ canvas.draw_rectangle(BOXOBJ[0],BOXOBJ[1], BOXOBJ[0]+BOXOBJ[2],BOXOBJ[1]+ BOXOBJ[3], color=(255,0,0), thickness=1)
|
|
|
|
+ getDigitalResult.append({"digitalResult":number_recognition.labels[PROBS[BOXESI][0]],"digitalConfidence":round(PROBS[BOXESI][1][PROBS[BOXESI][0]]*100, 2)})
|
|
|
|
+`)
|
|
|
|
+ var _code = "digitalShowCanvas()\n";
|
|
|
|
+ return _code;
|
|
}
|
|
}
|
|
|
|
|
|
Blockly.Blocks['ai_model_digital_attribute'] = {
|
|
Blockly.Blocks['ai_model_digital_attribute'] = {
|
|
init: function () {
|
|
init: function () {
|
|
this.appendDummyInput()
|
|
this.appendDummyInput()
|
|
.appendField(Blockly.Msg.ai_model_digital_attribute);
|
|
.appendField(Blockly.Msg.ai_model_digital_attribute);
|
|
- this.setOutput(true, null);
|
|
|
|
|
|
+ this.setOutput(false, null);
|
|
|
|
+ this.setNextStatement(true, null);
|
|
|
|
+ this.setPreviousStatement(true, null);
|
|
this.setColour("#ee783a");
|
|
this.setColour("#ee783a");
|
|
this.setTooltip(Blockly.Msg.ai_model_digital_attribute);
|
|
this.setTooltip(Blockly.Msg.ai_model_digital_attribute);
|
|
this.setHelpUrl("");
|
|
this.setHelpUrl("");
|
|
@@ -8782,7 +8823,7 @@ Blockly.Blocks['ai_model_digital_attribute'] = {
|
|
Blockly.Python['ai_model_digital_attribute'] = function (block) {
|
|
Blockly.Python['ai_model_digital_attribute'] = function (block) {
|
|
Blockly.Python.addFunction("",`def ai_model_digital_attribute():`)
|
|
Blockly.Python.addFunction("",`def ai_model_digital_attribute():`)
|
|
var code = 'len(BOXES)';
|
|
var code = 'len(BOXES)';
|
|
- return [code, Blockly.Python.ORDER_NONE];
|
|
|
|
|
|
+ return code;
|
|
};
|
|
};
|
|
|
|
|
|
Blockly.Blocks['ai_model_object_init'] = {
|
|
Blockly.Blocks['ai_model_object_init'] = {
|
|
@@ -9030,7 +9071,8 @@ Blockly.Blocks['ai_model_look_attribute'] = {
|
|
init: function () {
|
|
init: function () {
|
|
this.appendDummyInput()
|
|
this.appendDummyInput()
|
|
.appendField(Blockly.Msg.ai_model_look_attribute);
|
|
.appendField(Blockly.Msg.ai_model_look_attribute);
|
|
- this.setOutput(true, null);
|
|
|
|
|
|
+ this.setNextStatement(true, null);
|
|
|
|
+ this.setPreviousStatement(true, null);
|
|
this.setColour("#ee783a");
|
|
this.setColour("#ee783a");
|
|
this.setTooltip(Blockly.Msg.ai_model_look_attribute);
|
|
this.setTooltip(Blockly.Msg.ai_model_look_attribute);
|
|
this.setHelpUrl("");
|
|
this.setHelpUrl("");
|
|
@@ -9038,8 +9080,15 @@ Blockly.Blocks['ai_model_look_attribute'] = {
|
|
};
|
|
};
|
|
|
|
|
|
Blockly.Python['ai_model_look_attribute'] = function (block) {
|
|
Blockly.Python['ai_model_look_attribute'] = function (block) {
|
|
- var code = 'len(BOXES)';
|
|
|
|
- return [code, Blockly.Python.ORDER_NONE];
|
|
|
|
|
|
+ Blockly.Python.addFunction("objectRecognize",`def objectRecognize():
|
|
|
|
+ global BOXES
|
|
|
|
+ if len(BOXES):
|
|
|
|
+ for BOXESI, BOXOBJ in enumerate(BOXES):
|
|
|
|
+ canvas.draw_string(BOXOBJ[0],(BOXOBJ[1]), ("".join([str(x) for x in [str(labels[PROBS[BOXESI][0]]), ",", round(PROBS[BOXESI][1][PROBS[BOXESI][0]]*100, 2)]])), scale = 1, color = (51,102,255) , thickness = 1)
|
|
|
|
+ canvas.draw_rectangle(BOXOBJ[0],BOXOBJ[1], BOXOBJ[0]+BOXOBJ[2],BOXOBJ[1]+ BOXOBJ[3], color=(255,0,0), thickness=1)
|
|
|
|
+`)
|
|
|
|
+ var code = 'objectRecognize()\n';
|
|
|
|
+ return code;
|
|
};
|
|
};
|
|
// 猜拳识别
|
|
// 猜拳识别
|
|
Blockly.Blocks['ai_model_Guesswork_init'] = {
|
|
Blockly.Blocks['ai_model_Guesswork_init'] = {
|
|
@@ -9081,7 +9130,6 @@ Blockly.Python.ai_model_Guesswork_init = function (block) {
|
|
} else {
|
|
} else {
|
|
a = '["剪刀", "石頭" ,"布"]'
|
|
a = '["剪刀", "石頭" ,"布"]'
|
|
}
|
|
}
|
|
- console.log(language)
|
|
|
|
Blockly.Python.definitions_['v831_import_from_maix_nn'] = `from maix import nn`
|
|
Blockly.Python.definitions_['v831_import_from_maix_nn'] = `from maix import nn`
|
|
Blockly.Python.definitions_['v831_import_from_maixnn_decoder'] = `from maix.nn import decoder`
|
|
Blockly.Python.definitions_['v831_import_from_maixnn_decoder'] = `from maix.nn import decoder`
|
|
Blockly.Python.definitions_.import_Guesswork_init = `class Mora:
|
|
Blockly.Python.definitions_.import_Guesswork_init = `class Mora:
|
|
@@ -9298,16 +9346,25 @@ Blockly.Blocks['ai_model_Guesswork_look'] = {
|
|
this.appendDummyInput()
|
|
this.appendDummyInput()
|
|
.appendField(Blockly.Msg.ai_models_guesswork_model_if);
|
|
.appendField(Blockly.Msg.ai_models_guesswork_model_if);
|
|
this.setInputsInline(false);
|
|
this.setInputsInline(false);
|
|
- this.setOutput(true, null);
|
|
|
|
|
|
+ this.setNextStatement(true, null);
|
|
|
|
+ this.setPreviousStatement(true, null);
|
|
this.setColour("#ee783a");
|
|
this.setColour("#ee783a");
|
|
this.setTooltip(Blockly.Msg.ai_models_guesswork_model_if);
|
|
this.setTooltip(Blockly.Msg.ai_models_guesswork_model_if);
|
|
this.setHelpUrl("");
|
|
this.setHelpUrl("");
|
|
}
|
|
}
|
|
};
|
|
};
|
|
-
|
|
|
|
|
|
+
|
|
Blockly.Python.ai_model_Guesswork_look = function (block) {
|
|
Blockly.Python.ai_model_Guesswork_look = function (block) {
|
|
- var _code = "len(BOXES)";
|
|
|
|
- return [_code, Blockly.Python.ORDER_ATOMIC];
|
|
|
|
|
|
+ Blockly.Python.addFunction("guessworkShowRecognize",`def guessworkShowRecognize():
|
|
|
|
+ global BOXES
|
|
|
|
+ if len(BOXES):
|
|
|
|
+ for BOXESI, BOXOBJ in enumerate(BOXES):
|
|
|
|
+ canvas.draw_string(10,0, (str(str(Mora.labels[PROBS[BOXESI][0]])) + str(str(":") + str(round(PROBS[BOXESI][1][PROBS[BOXESI][0]]*100, 2)))), scale = 1, color = (255,0,0) , thickness = 1)
|
|
|
|
+ canvas.draw_rectangle(BOXOBJ[0],BOXOBJ[1], BOXOBJ[0]+BOXOBJ[2],BOXOBJ[1]+ BOXOBJ[3], color=(255,0,0), thickness=1)
|
|
|
|
+
|
|
|
|
+`)
|
|
|
|
+ var _code = "guessworkShowRecognize()\n";
|
|
|
|
+ return _code;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -9527,7 +9584,8 @@ Blockly.Blocks['ai_model_face'] = {
|
|
this.appendDummyInput()
|
|
this.appendDummyInput()
|
|
.appendField(Blockly.Msg.ai_models_face_model_if);
|
|
.appendField(Blockly.Msg.ai_models_face_model_if);
|
|
this.setInputsInline(false);
|
|
this.setInputsInline(false);
|
|
- this.setOutput(true, null);
|
|
|
|
|
|
+ this.setNextStatement(true, null);
|
|
|
|
+ this.setPreviousStatement(true, null);
|
|
this.setColour("#ee783a");
|
|
this.setColour("#ee783a");
|
|
this.setTooltip(Blockly.Msg.ai_models_face_model_if);
|
|
this.setTooltip(Blockly.Msg.ai_models_face_model_if);
|
|
this.setHelpUrl("");
|
|
this.setHelpUrl("");
|
|
@@ -9535,8 +9593,14 @@ Blockly.Blocks['ai_model_face'] = {
|
|
};
|
|
};
|
|
|
|
|
|
Blockly.Python.ai_model_face = function (block) {
|
|
Blockly.Python.ai_model_face = function (block) {
|
|
- var _code = "len(BOXES)";
|
|
|
|
- return [_code, Blockly.Python.ORDER_ATOMIC];
|
|
|
|
|
|
+ Blockly.Python.addFunction("faceShowDetection",`def faceShowDetection():
|
|
|
|
+ global BOXES
|
|
|
|
+ if len(BOXES):
|
|
|
|
+ for BOXESI, BOXOBJ in enumerate(BOXES):
|
|
|
|
+ canvas.draw_rectangle(BOXOBJ[0],BOXOBJ[1], BOXOBJ[0]+BOXOBJ[2],BOXOBJ[1]+ BOXOBJ[3], color=(255,0,0), thickness=1)
|
|
|
|
+`)
|
|
|
|
+ var _code = "faceShowDetection()\n";
|
|
|
|
+ return _code;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -9866,7 +9930,8 @@ Blockly.Blocks['ai_model_card_xy'] = {
|
|
this.appendDummyInput()
|
|
this.appendDummyInput()
|
|
.appendField(Blockly.Msg.ai_models_card_if_true);
|
|
.appendField(Blockly.Msg.ai_models_card_if_true);
|
|
this.setInputsInline(false);
|
|
this.setInputsInline(false);
|
|
- this.setOutput(true, null);
|
|
|
|
|
|
+ this.setNextStatement(true, null);
|
|
|
|
+ this.setPreviousStatement(true, null);
|
|
this.setColour("#ee783a");
|
|
this.setColour("#ee783a");
|
|
this.setTooltip(Blockly.Msg.ai_models_card_if_true);
|
|
this.setTooltip(Blockly.Msg.ai_models_card_if_true);
|
|
this.setHelpUrl("");
|
|
this.setHelpUrl("");
|
|
@@ -9874,8 +9939,15 @@ Blockly.Blocks['ai_model_card_xy'] = {
|
|
};
|
|
};
|
|
|
|
|
|
Blockly.Python['ai_model_card_xy'] = function (block) {
|
|
Blockly.Python['ai_model_card_xy'] = function (block) {
|
|
- var code = 'len(CARDDATABOEX)';
|
|
|
|
- return [code, Blockly.Python.ORDER_ATOMIC];
|
|
|
|
|
|
+ Blockly.Python.addFunction("cardShowRecognize",`def cardShowRecognize():
|
|
|
|
+ global CARDDATABOEX
|
|
|
|
+ if len(CARDDATABOEX):
|
|
|
|
+ for CARDDATABOEXI in CARDDATABOEX:
|
|
|
|
+ canvas.draw_rectangle(CARDDATABOEXI[0],CARDDATABOEXI[1], CARDDATABOEXI[0]+CARDDATABOEXI[2]-CARDDATABOEXI[0],CARDDATABOEXI[1]+ CARDDATABOEXI[3]-CARDDATABOEXI[1], color=(255,0,0), thickness=1)
|
|
|
|
+ canvas.draw_string(CARDDATABOEXI[0],CARDDATABOEXI[1], (str(LPRCARD.get_card_data(CARDDATABOEXI[4][:6]))), scale = 1, color = (255,255,255) , thickness = 1)
|
|
|
|
+`)
|
|
|
|
+ var code = 'cardShowRecognize()\n';
|
|
|
|
+ return code;
|
|
};
|
|
};
|
|
|
|
|
|
Blockly.Blocks['ai_model_card_result'] = {
|
|
Blockly.Blocks['ai_model_card_result'] = {
|
|
@@ -10180,7 +10252,7 @@ Blockly.Blocks['face_recognition_load'] = {
|
|
this.appendValueInput("class_input")
|
|
this.appendValueInput("class_input")
|
|
.setCheck(null)
|
|
.setCheck(null)
|
|
.appendField(Blockly.Msg.LISTS_CREATE_WITH_CONTAINER_TITLE_ADD + ":")
|
|
.appendField(Blockly.Msg.LISTS_CREATE_WITH_CONTAINER_TITLE_ADD + ":")
|
|
- .appendField(new Blockly.FieldVariable("people_name_list"), "people_name");
|
|
|
|
|
|
+ // .appendField(new Blockly.FieldVariable("people_name_list"), "people_name");
|
|
this.setInputsInline(false);
|
|
this.setInputsInline(false);
|
|
this.setPreviousStatement(true, null);
|
|
this.setPreviousStatement(true, null);
|
|
this.setNextStatement(true, null);
|
|
this.setNextStatement(true, null);
|
|
@@ -10191,7 +10263,7 @@ Blockly.Blocks['face_recognition_load'] = {
|
|
};
|
|
};
|
|
|
|
|
|
Blockly.Python['face_recognition_load'] = function (block) {
|
|
Blockly.Python['face_recognition_load'] = function (block) {
|
|
- var face_list = Blockly.Python.variableDB_.getName(block.getFieldValue('people_name'), Blockly.Variables.NAME_TYPE);
|
|
|
|
|
|
+ // var face_list = Blockly.Python.variableDB_.getName(block.getFieldValue('people_name'), Blockly.Variables.NAME_TYPE);
|
|
var value_class_input = Blockly.Python.valueToCode(block, 'class_input', Blockly.Python.ORDER_ATOMIC);
|
|
var value_class_input = Blockly.Python.valueToCode(block, 'class_input', Blockly.Python.ORDER_ATOMIC);
|
|
Blockly.Python.definitions_['v831_import_from_maix_nn'] = `from maix import nn`
|
|
Blockly.Python.definitions_['v831_import_from_maix_nn'] = `from maix import nn`
|
|
Blockly.Python.definitions_['v831_import_from_maix_nn_face'] = `from maix.nn.app import face`
|
|
Blockly.Python.definitions_['v831_import_from_maix_nn_face'] = `from maix.nn.app import face`
|
|
@@ -10288,8 +10360,7 @@ max_face_num = 4
|
|
detect_threshold = 0.5
|
|
detect_threshold = 0.5
|
|
detect_nms = 0.3
|
|
detect_nms = 0.3
|
|
FEATURES = []
|
|
FEATURES = []
|
|
-${face_list} = ${value_class_input}
|
|
|
|
-CLASSNAMEFACELIST = ${face_list}
|
|
|
|
|
|
+CLASSNAMEFACELIST = ${value_class_input}
|
|
`
|
|
`
|
|
var code = `FACESRECOGNITONRESULT = FACERECGNIZER.get_faces(canvas)
|
|
var code = `FACESRECOGNITONRESULT = FACERECGNIZER.get_faces(canvas)
|
|
`;
|
|
`;
|
|
@@ -10324,7 +10395,8 @@ Blockly.Blocks['face_recognition_if_face'] = {
|
|
this.appendDummyInput()
|
|
this.appendDummyInput()
|
|
.appendField(Blockly.Msg.ai_models_face_model_if_new);
|
|
.appendField(Blockly.Msg.ai_models_face_model_if_new);
|
|
this.setInputsInline(false);
|
|
this.setInputsInline(false);
|
|
- this.setOutput(true, null);
|
|
|
|
|
|
+ this.setNextStatement(true, null);
|
|
|
|
+ this.setPreviousStatement(true, null);
|
|
this.setColour("#ee783a");
|
|
this.setColour("#ee783a");
|
|
this.setTooltip(Blockly.Msg.ai_models_face_model_if_new);
|
|
this.setTooltip(Blockly.Msg.ai_models_face_model_if_new);
|
|
this.setHelpUrl("");
|
|
this.setHelpUrl("");
|
|
@@ -10332,8 +10404,19 @@ Blockly.Blocks['face_recognition_if_face'] = {
|
|
};
|
|
};
|
|
|
|
|
|
Blockly.Python['face_recognition_if_face'] = function (block) {
|
|
Blockly.Python['face_recognition_if_face'] = function (block) {
|
|
- var code = `len(FACESRECOGNITONRESULT)`;
|
|
|
|
- return [code, Blockly.Python.ORDER_ATOMIC];
|
|
|
|
|
|
+ Blockly.Python.addFunction("recognizeShowMessage",`def recognizeShowMessage():
|
|
|
|
+ global FACESRECOGNITONRESULT,isLoadRecoredFace
|
|
|
|
+ if len(FACESRECOGNITONRESULT):
|
|
|
|
+ for FACESRECOGNITONRESULTI in FACESRECOGNITONRESULT:
|
|
|
|
+ if isLoadRecoredFace:
|
|
|
|
+ canvas.draw_rectangle(FACESRECOGNITONRESULTI[1][0],FACESRECOGNITONRESULTI[1][1], FACESRECOGNITONRESULTI[1][0]+FACESRECOGNITONRESULTI[1][2],FACESRECOGNITONRESULTI[1][1]+ FACESRECOGNITONRESULTI[1][3], color=(51,204,0), thickness=1)
|
|
|
|
+ canvas.draw_string(40,0, ("".join([str(x) for x in [FACERECGNIZER.recognize(FACESRECOGNITONRESULTI[3])[0], " : ", round(FACERECGNIZER.recognize(FACESRECOGNITONRESULTI[3])[1], 2)]])), scale = 1, color = (51,204,0) , thickness = 1)
|
|
|
|
+ else:
|
|
|
|
+ FACERECGNIZER.map_face(FACESRECOGNITONRESULTI[1],FACESRECOGNITONRESULTI[2],canvas)
|
|
|
|
+ canvas.draw_rectangle(FACESRECOGNITONRESULTI[1][0],FACESRECOGNITONRESULTI[1][1], FACESRECOGNITONRESULTI[1][0]+FACESRECOGNITONRESULTI[1][2],FACESRECOGNITONRESULTI[1][1]+ FACESRECOGNITONRESULTI[1][3], color=(255,0,0), thickness=1)
|
|
|
|
+`)
|
|
|
|
+ var code = `recognizeShowMessage()\n`;
|
|
|
|
+ return code;
|
|
};
|
|
};
|
|
|
|
|
|
Blockly.Blocks['face_recognition_face_result'] = {
|
|
Blockly.Blocks['face_recognition_face_result'] = {
|
|
@@ -10450,13 +10533,13 @@ Blockly.Python['face_recognition_map_face'] = function (block) {
|
|
Blockly.Blocks['face_recognition_add'] = {
|
|
Blockly.Blocks['face_recognition_add'] = {
|
|
init: function () {
|
|
init: function () {
|
|
this.appendDummyInput()
|
|
this.appendDummyInput()
|
|
- // .appendField(Blockly.Msg.CocoRobo_EVENT_ACTION_OPT1)
|
|
|
|
- // .appendField(new Blockly.FieldDropdown([
|
|
|
|
- // ["A", "A"],
|
|
|
|
- // ["B", "B"],
|
|
|
|
- // ["C", "C"],
|
|
|
|
- // ["D", "D"]
|
|
|
|
- // ]), "button_type")
|
|
|
|
|
|
+ .appendField(Blockly.Msg.CocoRobo_EVENT_ACTION_OPT1)
|
|
|
|
+ .appendField(new Blockly.FieldDropdown([
|
|
|
|
+ ["A", "A"],
|
|
|
|
+ ["B", "B"],
|
|
|
|
+ ["C", "C"],
|
|
|
|
+ ["D", "D"]
|
|
|
|
+ ]), "button_type")
|
|
.appendField(Blockly.Msg.ai_model_face_gather_1);
|
|
.appendField(Blockly.Msg.ai_model_face_gather_1);
|
|
this.setInputsInline(false);
|
|
this.setInputsInline(false);
|
|
this.setPreviousStatement(true, null);
|
|
this.setPreviousStatement(true, null);
|
|
@@ -10468,6 +10551,17 @@ Blockly.Blocks['face_recognition_add'] = {
|
|
};
|
|
};
|
|
|
|
|
|
Blockly.Python['face_recognition_add'] = function (block) {
|
|
Blockly.Python['face_recognition_add'] = function (block) {
|
|
|
|
+ var _type = block.getFieldValue('button_type');
|
|
|
|
+ Blockly.Python.definitions_['v831_import_sys'] = `import sys
|
|
|
|
+sys.path.append("/root/")`
|
|
|
|
+ Blockly.Python.definitions_['v831_import_CocoPi_BUTTON'] = `from CocoPi import BUTTON`
|
|
|
|
+ // Blockly.Python.definitions_['v831_import_CocoPi'] = `sys.path.append("/root/")`
|
|
|
|
+ Blockly.Python.definitions_['import_define_x_v831_button'] = `key_A = BUTTON(14)
|
|
|
|
+key_B = BUTTON(8)
|
|
|
|
+key_C = BUTTON(13)
|
|
|
|
+key_D = BUTTON(7)
|
|
|
|
+`
|
|
|
|
+ // var code = `key_${_type}.is_pressed()`
|
|
Blockly.Python.definitions_['v831_import_os'] = `import os`
|
|
Blockly.Python.definitions_['v831_import_os'] = `import os`
|
|
Blockly.Python.definitions_['v831_import_json'] = `import json`
|
|
Blockly.Python.definitions_['v831_import_json'] = `import json`
|
|
Blockly.Python.addVariable('ai_model_face_gather', `
|
|
Blockly.Python.addVariable('ai_model_face_gather', `
|
|
@@ -10476,31 +10570,46 @@ def _CREATE_TEXT_FILE_WITH_CONTENT(_path, _data, _sep):
|
|
f.write(_data + _sep)
|
|
f.write(_data + _sep)
|
|
f.close()
|
|
f.close()
|
|
`, true);
|
|
`, true);
|
|
- var code = `if NUMBERPERSON < len(CLASSNAMEFACELIST):
|
|
|
|
- NUMBERPERSON = NUMBERPERSON + 1
|
|
|
|
- FACERECGNIZER.add_user(CLASSNAMEFACELIST[len(FACERECGNIZER)], FACESRECOGNITONRESULTI[3])
|
|
|
|
- FEATURES = FACERECGNIZER.features
|
|
|
|
- try:
|
|
|
|
- os.remove("/root/user/model/recorded_face_features.py")
|
|
|
|
- except:
|
|
|
|
- pass
|
|
|
|
- try:
|
|
|
|
- _CREATE_TEXT_FILE_WITH_CONTENT("/root/user/model/recorded_face_features.py", json.dumps(FACERECGNIZER.features), "\\r\\n")
|
|
|
|
- except:
|
|
|
|
- pass
|
|
|
|
|
|
+ var language = localStorage.getItem("handPyLanguage");
|
|
|
|
+ let saveFace = ""
|
|
|
|
+ if(language == "en"){
|
|
|
|
+ saveFace = "Save Face"
|
|
|
|
+ }else if(language == "zh-hant"){
|
|
|
|
+ saveFace = "儲存人臉"
|
|
|
|
+ }else{
|
|
|
|
+ saveFace = "保存人脸"
|
|
|
|
+ }
|
|
|
|
+ var code = `if key_${_type}.is_pressed():
|
|
|
|
+ while not (key_${_type}.is_pressed() == False):
|
|
|
|
+ time.sleep(0.1)
|
|
|
|
+ if NUMBERPERSON < len(CLASSNAMEFACELIST):
|
|
|
|
+ NUMBERPERSON = NUMBERPERSON + 1
|
|
|
|
+ FACERECGNIZER.add_user(CLASSNAMEFACELIST[len(FACERECGNIZER)], FACESRECOGNITONRESULTI[3])
|
|
|
|
+ FEATURES = FACERECGNIZER.features
|
|
|
|
+ try:
|
|
|
|
+ os.remove("/root/user/model/recorded_face_features.py")
|
|
|
|
+ except:
|
|
|
|
+ pass
|
|
|
|
+ try:
|
|
|
|
+ _CREATE_TEXT_FILE_WITH_CONTENT("/root/user/model/recorded_face_features.py", json.dumps(FACERECGNIZER.features), "\\r\\n")
|
|
|
|
+ except:
|
|
|
|
+ pass
|
|
|
|
+ canvas.draw_string(0,0, str("${saveFace}") + str(NUMBERPERSON), scale = 1, color = (51,204,0) , thickness = 1)
|
|
|
|
+ v831_display_show_canvas(canvas)
|
|
|
|
+ time.sleep(1000 / 1000)
|
|
`;
|
|
`;
|
|
return code;
|
|
return code;
|
|
};
|
|
};
|
|
Blockly.Blocks['face_recognition_remove'] = {
|
|
Blockly.Blocks['face_recognition_remove'] = {
|
|
init: function () {
|
|
init: function () {
|
|
this.appendDummyInput()
|
|
this.appendDummyInput()
|
|
- // .appendField(Blockly.Msg.CocoRobo_EVENT_ACTION_OPT1)
|
|
|
|
- // .appendField(new Blockly.FieldDropdown([
|
|
|
|
- // ["A", "A"],
|
|
|
|
- // ["B", "B"],
|
|
|
|
- // ["C", "C"],
|
|
|
|
- // ["D", "D"]
|
|
|
|
- // ]), "button_type")
|
|
|
|
|
|
+ .appendField(Blockly.Msg.CocoRobo_EVENT_ACTION_OPT1)
|
|
|
|
+ .appendField(new Blockly.FieldDropdown([
|
|
|
|
+ ["A", "A"],
|
|
|
|
+ ["B", "B"],
|
|
|
|
+ ["C", "C"],
|
|
|
|
+ ["D", "D"]
|
|
|
|
+ ]), "button_type")
|
|
.appendField(Blockly.Msg.v831_setting_face_data_remove)
|
|
.appendField(Blockly.Msg.v831_setting_face_data_remove)
|
|
// this.appendStatementInput("input")
|
|
// this.appendStatementInput("input")
|
|
// .setCheck(null)
|
|
// .setCheck(null)
|
|
@@ -10516,9 +10625,37 @@ Blockly.Blocks['face_recognition_remove'] = {
|
|
};
|
|
};
|
|
|
|
|
|
Blockly.Python['face_recognition_remove'] = function (block) {
|
|
Blockly.Python['face_recognition_remove'] = function (block) {
|
|
- // Blockly.Python.addFunction('statementsInputFaceRemove', `def statementsInputFaceRemove():
|
|
|
|
- // ${statements_input}`)
|
|
|
|
- var code = `if NUMBERPERSON > 0:
|
|
|
|
|
|
+ var _type = block.getFieldValue('button_type');
|
|
|
|
+ Blockly.Python.definitions_['v831_import_sys'] = `import sys
|
|
|
|
+sys.path.append("/root/")`
|
|
|
|
+ Blockly.Python.definitions_['v831_import_CocoPi_BUTTON'] = `from CocoPi import BUTTON`
|
|
|
|
+ // Blockly.Python.definitions_['v831_import_CocoPi'] = `sys.path.append("/root/")`
|
|
|
|
+ Blockly.Python.definitions_['import_define_x_v831_button'] = `key_A = BUTTON(14)
|
|
|
|
+key_B = BUTTON(8)
|
|
|
|
+key_C = BUTTON(13)
|
|
|
|
+key_D = BUTTON(7)
|
|
|
|
+`
|
|
|
|
+ let language = localStorage.getItem("handPyLanguage");
|
|
|
|
+ let removeFace = ""
|
|
|
|
+ let faceData = ""
|
|
|
|
+ if(language == "en"){
|
|
|
|
+ removeFace = "Remove Face"
|
|
|
|
+ faceData = "Data"
|
|
|
|
+ }else if(language == "zh-hant"){
|
|
|
|
+ removeFace = "刪除人臉"
|
|
|
|
+ faceData = "數據"
|
|
|
|
+ }else{
|
|
|
|
+ removeFace = "删除人脸"
|
|
|
|
+ faceData = "数据"
|
|
|
|
+ }
|
|
|
|
+ var code = `if key_${_type}.is_pressed() and NUMBERPERSON > 0:
|
|
|
|
+ while not (key_${_type}.is_pressed() == False):
|
|
|
|
+ time.sleep(0.1)
|
|
|
|
+
|
|
|
|
+ canvas.draw_rectangle(0,0, 0+320,0+ 20, color=(0,0,0), thickness=-1)
|
|
|
|
+ canvas.draw_string(40,0, ("".join([str(x) for x in ["${removeFace}", NUMBERPERSON, "${faceData}"]])), scale = 1, color = (255,255,255) , thickness = 1)
|
|
|
|
+ v831_display_show_canvas(canvas)
|
|
|
|
+ time.sleep(1000 / 1000)
|
|
NUMBERPERSON = NUMBERPERSON - 1
|
|
NUMBERPERSON = NUMBERPERSON - 1
|
|
FACERECGNIZER.remove_user(CLASSNAMEFACELIST[len(FACERECGNIZER)-1])
|
|
FACERECGNIZER.remove_user(CLASSNAMEFACELIST[len(FACERECGNIZER)-1])
|
|
FEATURES = FACERECGNIZER.features
|
|
FEATURES = FACERECGNIZER.features
|
|
@@ -10542,11 +10679,13 @@ Blockly.Python['face_recognition_data_load'] = function (block) {
|
|
var value_class_input = Blockly.Python.valueToCode(block, 'class_input', Blockly.Python.ORDER_ATOMIC);
|
|
var value_class_input = Blockly.Python.valueToCode(block, 'class_input', Blockly.Python.ORDER_ATOMIC);
|
|
|
|
|
|
Blockly.Python.definitions_['v831_import_json'] = `import json`
|
|
Blockly.Python.definitions_['v831_import_json'] = `import json`
|
|
- Blockly.Python.definitions_['load_face_data'] = `try:
|
|
|
|
|
|
+ Blockly.Python.definitions_['load_face_data'] = `isLoadRecoredFace = False
|
|
|
|
+try:
|
|
with open("/root/user/model/recorded_face_features.py", "r") as file:
|
|
with open("/root/user/model/recorded_face_features.py", "r") as file:
|
|
FACERECGNIZER.features = json.loads(file.read())
|
|
FACERECGNIZER.features = json.loads(file.read())
|
|
|
|
+ isLoadRecoredFace = True
|
|
except:
|
|
except:
|
|
- pass
|
|
|
|
|
|
+ isLoadRecoredFace = False
|
|
`
|
|
`
|
|
var code = ``;
|
|
var code = ``;
|
|
return code;
|
|
return code;
|
|
@@ -10626,12 +10765,12 @@ Blockly.Blocks['ai_model_self_learning_load'] = {
|
|
Blockly.Python['ai_model_self_learning_load'] = function (block) {
|
|
Blockly.Python['ai_model_self_learning_load'] = function (block) {
|
|
Blockly.Python.definitions_['v831_import_from_maix_nn'] = `from maix import nn`
|
|
Blockly.Python.definitions_['v831_import_from_maix_nn'] = `from maix import nn`
|
|
Blockly.Python.definitions_['v831_import_Classifier'] = `from maix.nn.app.classifier import Classifier`
|
|
Blockly.Python.definitions_['v831_import_Classifier'] = `from maix.nn.app.classifier import Classifier`
|
|
|
|
+ Blockly.Python.addVariable("SELFLEARNCOUNT",`SELFLEARNCOUNT = 0`,true)
|
|
var value_class_input = Blockly.Python.valueToCode(block, 'class_input', Blockly.Python.ORDER_ATOMIC);
|
|
var value_class_input = Blockly.Python.valueToCode(block, 'class_input', Blockly.Python.ORDER_ATOMIC);
|
|
Blockly.Python.definitions_.import_self_learning_init = `
|
|
Blockly.Python.definitions_.import_self_learning_init = `
|
|
CLASSNUM = ${JSON.parse(value_class_input).length}
|
|
CLASSNUM = ${JSON.parse(value_class_input).length}
|
|
SAMPLENUM = ${JSON.parse(value_class_input).length * 5}
|
|
SAMPLENUM = ${JSON.parse(value_class_input).length * 5}
|
|
CLASSNAMELIST = ${value_class_input}
|
|
CLASSNAMELIST = ${value_class_input}
|
|
-
|
|
|
|
`
|
|
`
|
|
Blockly.Python.definitions_.self_learing_load = `class Self_learn:
|
|
Blockly.Python.definitions_.self_learing_load = `class Self_learn:
|
|
model = {
|
|
model = {
|
|
@@ -10687,6 +10826,7 @@ Blockly.Python['ai_model_self_learning_recognize_load'] = function (block) {
|
|
Blockly.Python.definitions_['v831_from_nn_import_load'] = `from maix.nn.app.classifier import load`
|
|
Blockly.Python.definitions_['v831_from_nn_import_load'] = `from maix.nn.app.classifier import load`
|
|
Blockly.Python.definitions_['v831_import_os'] = `import os`
|
|
Blockly.Python.definitions_['v831_import_os'] = `import os`
|
|
var value_class_input = Blockly.Python.valueToCode(block, 'class_input', Blockly.Python.ORDER_ATOMIC);
|
|
var value_class_input = Blockly.Python.valueToCode(block, 'class_input', Blockly.Python.ORDER_ATOMIC);
|
|
|
|
+ Blockly.Python.addVariable("SELFLEARNCOUNT",`SELFLEARNCOUNT = 0`,true)
|
|
Blockly.Python.definitions_.import_self_learning_init = `
|
|
Blockly.Python.definitions_.import_self_learning_init = `
|
|
CLASSNUM = ${JSON.parse(value_class_input).length}
|
|
CLASSNUM = ${JSON.parse(value_class_input).length}
|
|
SAMPLENUM = ${JSON.parse(value_class_input).length * 5}
|
|
SAMPLENUM = ${JSON.parse(value_class_input).length * 5}
|
|
@@ -10729,22 +10869,41 @@ SELFLEARN = Self_learn()
|
|
Blockly.Blocks['ai_model_self_learning_add_class'] = {
|
|
Blockly.Blocks['ai_model_self_learning_add_class'] = {
|
|
init: function () {
|
|
init: function () {
|
|
this.appendDummyInput()
|
|
this.appendDummyInput()
|
|
- .appendField(Blockly.Msg.ai_model_self_learning_add_class_category + ',');
|
|
|
|
- this.appendDummyInput()
|
|
|
|
- .appendField(Blockly.Msg.ai_models_init_source)
|
|
|
|
- .appendField(new Blockly.FieldVariable("img_self_learning"), "varitem");
|
|
|
|
|
|
+ .appendField(Blockly.Msg.CocoRobo_EVENT_ACTION_OPT1)
|
|
|
|
+ .appendField(new Blockly.FieldDropdown([
|
|
|
|
+ ["A", "A"],
|
|
|
|
+ ["B", "B"],
|
|
|
|
+ ["C", "C"],
|
|
|
|
+ ["D", "D"]
|
|
|
|
+ ]), "button_type")
|
|
|
|
+ .appendField(Blockly.Msg.ai_model_self_learning_add_class_category+Blockly.Msg.ai_model_self_learning_make_data_set);
|
|
this.setInputsInline(false);
|
|
this.setInputsInline(false);
|
|
this.setPreviousStatement(true, null);
|
|
this.setPreviousStatement(true, null);
|
|
this.setNextStatement(true, null);
|
|
this.setNextStatement(true, null);
|
|
this.setColour("#ee783a");
|
|
this.setColour("#ee783a");
|
|
- this.setTooltip(Blockly.Msg.ai_model_self_learning_add_class_category);
|
|
|
|
|
|
+ this.setTooltip(Blockly.Msg.ai_model_self_learning_add_class_category+Blockly.Msg.ai_model_self_learning_make_data_set);
|
|
this.setHelpUrl("");
|
|
this.setHelpUrl("");
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
|
|
Blockly.Python['ai_model_self_learning_add_class'] = function (block) {
|
|
Blockly.Python['ai_model_self_learning_add_class'] = function (block) {
|
|
- var variable_name = Blockly.Python.variableDB_.getName(block.getFieldValue('varitem'), Blockly.Variables.NAME_TYPE);
|
|
|
|
- var code = `SELFLEARN.classifier.add_class_img(${variable_name})
|
|
|
|
|
|
+ var _type = block.getFieldValue('button_type');
|
|
|
|
+ Blockly.Python.definitions_['v831_import_sys'] = `import sys
|
|
|
|
+sys.path.append("/root/")`
|
|
|
|
+ Blockly.Python.definitions_['v831_import_CocoPi_BUTTON'] = `from CocoPi import BUTTON`
|
|
|
|
+ // Blockly.Python.definitions_['v831_import_CocoPi'] = `sys.path.append("/root/")`
|
|
|
|
+ Blockly.Python.definitions_['import_define_x_v831_button'] = `key_A = BUTTON(14)
|
|
|
|
+key_B = BUTTON(8)
|
|
|
|
+key_C = BUTTON(13)
|
|
|
|
+key_D = BUTTON(7)
|
|
|
|
+`
|
|
|
|
+ var code = `if key_${_type}.is_pressed() and SELFLEARNCOUNT < SELFLEARN.class_num:
|
|
|
|
+ while not (key_${_type}.is_pressed() == False):
|
|
|
|
+ time.sleep(0.1)
|
|
|
|
+ SELFLEARN.classifier.add_class_img(canvas)
|
|
|
|
+ for i in range(5):
|
|
|
|
+ SELFLEARN.classifier.add_sample_img(canvas)
|
|
|
|
+ SELFLEARNCOUNT = SELFLEARNCOUNT + 1
|
|
`;
|
|
`;
|
|
return code;
|
|
return code;
|
|
};
|
|
};
|
|
@@ -10752,9 +10911,6 @@ Blockly.Blocks['ai_model_self_learning_make_data_set'] = {
|
|
init: function () {
|
|
init: function () {
|
|
this.appendDummyInput()
|
|
this.appendDummyInput()
|
|
.appendField(Blockly.Msg.ai_model_self_learning_make_data_set);
|
|
.appendField(Blockly.Msg.ai_model_self_learning_make_data_set);
|
|
- this.appendDummyInput()
|
|
|
|
- .appendField(Blockly.Msg.ai_models_init_source)
|
|
|
|
- .appendField(new Blockly.FieldVariable("img_self_learning"), "varitem");
|
|
|
|
this.setInputsInline(false);
|
|
this.setInputsInline(false);
|
|
this.setPreviousStatement(true, null);
|
|
this.setPreviousStatement(true, null);
|
|
this.setNextStatement(true, null);
|
|
this.setNextStatement(true, null);
|
|
@@ -10765,9 +10921,8 @@ Blockly.Blocks['ai_model_self_learning_make_data_set'] = {
|
|
};
|
|
};
|
|
|
|
|
|
Blockly.Python['ai_model_self_learning_make_data_set'] = function (block) {
|
|
Blockly.Python['ai_model_self_learning_make_data_set'] = function (block) {
|
|
- var variable_name = Blockly.Python.variableDB_.getName(block.getFieldValue('varitem'), Blockly.Variables.NAME_TYPE);
|
|
|
|
var code = `for i in range(5):
|
|
var code = `for i in range(5):
|
|
- SELFLEARN.classifier.add_sample_img(${variable_name})
|
|
|
|
|
|
+ SELFLEARN.classifier.add_sample_img(canvas)
|
|
`;
|
|
`;
|
|
return code;
|
|
return code;
|
|
};
|
|
};
|
|
@@ -10775,19 +10930,39 @@ Blockly.Python['ai_model_self_learning_make_data_set'] = function (block) {
|
|
Blockly.Blocks['ai_model_self_learning_picture'] = {
|
|
Blockly.Blocks['ai_model_self_learning_picture'] = {
|
|
init: function () {
|
|
init: function () {
|
|
this.appendDummyInput()
|
|
this.appendDummyInput()
|
|
- .appendField(Blockly.Msg.ai_model_self_learning_picture);
|
|
|
|
-
|
|
|
|
|
|
+ .appendField(Blockly.Msg.CocoRobo_EVENT_ACTION_OPT1)
|
|
|
|
+ .appendField(new Blockly.FieldDropdown([
|
|
|
|
+ ["A", "A"],
|
|
|
|
+ ["B", "B"],
|
|
|
|
+ ["C", "C"],
|
|
|
|
+ ["D", "D"]
|
|
|
|
+ ]), "button_type")
|
|
|
|
+ .appendField(Blockly.Msg.ai_model_self_learning_picture+Blockly.Msg.ai_model_self_learning_save_modal);
|
|
this.setInputsInline(false);
|
|
this.setInputsInline(false);
|
|
this.setPreviousStatement(true, null);
|
|
this.setPreviousStatement(true, null);
|
|
this.setNextStatement(true, null);
|
|
this.setNextStatement(true, null);
|
|
this.setColour("#ee783a");
|
|
this.setColour("#ee783a");
|
|
- this.setTooltip(Blockly.Msg.ai_model_self_learning_picture);
|
|
|
|
|
|
+ this.setTooltip(Blockly.Msg.ai_model_self_learning_picture+Blockly.Msg.ai_model_self_learning_save_modal);
|
|
this.setHelpUrl("");
|
|
this.setHelpUrl("");
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
|
|
Blockly.Python['ai_model_self_learning_picture'] = function (block) {
|
|
Blockly.Python['ai_model_self_learning_picture'] = function (block) {
|
|
- var code = `SELFLEARN.classifier.train()
|
|
|
|
|
|
+ var _type = block.getFieldValue('button_type');
|
|
|
|
+ Blockly.Python.definitions_['v831_import_sys'] = `import sys
|
|
|
|
+sys.path.append("/root/")`
|
|
|
|
+ Blockly.Python.definitions_['v831_import_CocoPi_BUTTON'] = `from CocoPi import BUTTON`
|
|
|
|
+ // Blockly.Python.definitions_['v831_import_CocoPi'] = `sys.path.append("/root/")`
|
|
|
|
+ Blockly.Python.definitions_['import_define_x_v831_button'] = `key_A = BUTTON(14)
|
|
|
|
+key_B = BUTTON(8)
|
|
|
|
+key_C = BUTTON(13)
|
|
|
|
+key_D = BUTTON(7)
|
|
|
|
+`
|
|
|
|
+ var code = `if key_${_type}.is_pressed() and SELFLEARNCOUNT >= SELFLEARN.class_num:
|
|
|
|
+ while not (key_${_type}.is_pressed() == False):
|
|
|
|
+ time.sleep(0.1)
|
|
|
|
+ SELFLEARN.classifier.train()
|
|
|
|
+ SELFLEARN.classifier.save("/root/module.bin")
|
|
`;
|
|
`;
|
|
return code;
|
|
return code;
|
|
}; Blockly.Blocks['ai_model_self_learning_save_modal'] = {
|
|
}; Blockly.Blocks['ai_model_self_learning_save_modal'] = {
|
|
@@ -10814,11 +10989,6 @@ Blockly.Blocks['ai_model_self_learning_class_verification'] = {
|
|
init: function () {
|
|
init: function () {
|
|
this.appendDummyInput()
|
|
this.appendDummyInput()
|
|
.appendField(Blockly.Msg.ai_model_self_learning_class_verification);
|
|
.appendField(Blockly.Msg.ai_model_self_learning_class_verification);
|
|
-
|
|
|
|
- this.appendDummyInput()
|
|
|
|
- .appendField(Blockly.Msg.ai_models_init_source)
|
|
|
|
- .appendField(new Blockly.FieldVariable("img_self_learning"), "varitem");
|
|
|
|
-
|
|
|
|
this.setInputsInline(false);
|
|
this.setInputsInline(false);
|
|
this.setPreviousStatement(true, null);
|
|
this.setPreviousStatement(true, null);
|
|
this.setNextStatement(true, null);
|
|
this.setNextStatement(true, null);
|
|
@@ -10829,9 +10999,7 @@ Blockly.Blocks['ai_model_self_learning_class_verification'] = {
|
|
};
|
|
};
|
|
|
|
|
|
Blockly.Python['ai_model_self_learning_class_verification'] = function (block) {
|
|
Blockly.Python['ai_model_self_learning_class_verification'] = function (block) {
|
|
- var variable_name = Blockly.Python.variableDB_.getName(block.getFieldValue('varitem'), Blockly.Variables.NAME_TYPE);
|
|
|
|
-
|
|
|
|
- var code = `SELFLEARNidx, SELFLEARNdistance = SELFLEARN.classifier.predict(${variable_name})
|
|
|
|
|
|
+ var code = `SELFLEARNidx, SELFLEARNdistance = SELFLEARN.classifier.predict(canvas)
|
|
`;
|
|
`;
|
|
return code;
|
|
return code;
|
|
};
|
|
};
|
|
@@ -12182,18 +12350,24 @@ Blockly.Blocks['ai_model_customized_if_got'] = {
|
|
init: function () {
|
|
init: function () {
|
|
this.appendDummyInput()
|
|
this.appendDummyInput()
|
|
.appendField(Blockly.Msg.ai_models_customized_if_got);
|
|
.appendField(Blockly.Msg.ai_models_customized_if_got);
|
|
- this.setOutput(true, null);
|
|
|
|
|
|
+ this.setNextStatement(true, null);
|
|
|
|
+ this.setPreviousStatement(true, null);
|
|
this.setColour("#ee783a");
|
|
this.setColour("#ee783a");
|
|
- this.setTooltip(Blockly.Msg.ai_model_customized_if_got_TOOLTIP);
|
|
|
|
|
|
+ this.setTooltip(Blockly.Msg.ai_models_customized_if_got);
|
|
this.setHelpUrl("");
|
|
this.setHelpUrl("");
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
|
|
Blockly.Python['ai_model_customized_if_got'] = function (block) {
|
|
Blockly.Python['ai_model_customized_if_got'] = function (block) {
|
|
- // TODO: Assemble Python into code variable.
|
|
|
|
- var code = 'len(BOXES)';
|
|
|
|
- // TODO: Change ORDER_NONE to the correct strength.
|
|
|
|
- return [code, Blockly.Python.ORDER_NONE];
|
|
|
|
|
|
+ Blockly.Python.addFunction("faceRecognizeShowResult",`def faceRecognizeShowResult():
|
|
|
|
+ global BOXES
|
|
|
|
+ if len(BOXES):
|
|
|
|
+ for BOXESI, BOXOBJ in enumerate(BOXES):
|
|
|
|
+ canvas.draw_string((BOXOBJ[0]),(BOXOBJ[1]), ("".join([str(x) for x in [Yolo.labels[PROBS[BOXESI][0]], ";", str(round((PROBS[BOXESI][1][PROBS[BOXESI][0]]*100), 2)) + str("%")]])), scale = 1, color = (255,0,0) , thickness = 1)
|
|
|
|
+ canvas.draw_rectangle((BOXOBJ[0]),(BOXOBJ[1]), (BOXOBJ[0])+(BOXOBJ[2]),(BOXOBJ[1])+ (BOXOBJ[3]), color=(255,0,0), thickness=1)
|
|
|
|
+`)
|
|
|
|
+ var code = 'faceRecognizeShowResult()\n';
|
|
|
|
+ return code;
|
|
};
|
|
};
|
|
|
|
|
|
Blockly.Blocks['ai_model_customized_attribute'] = {
|
|
Blockly.Blocks['ai_model_customized_attribute'] = {
|
|
@@ -13308,8 +13482,7 @@ Blockly.Blocks['Numpy_Neural_Network_numpy_loading_model_fun'] = {
|
|
// this.appendDummyInput()
|
|
// this.appendDummyInput()
|
|
// .appendField("获取检测结果");
|
|
// .appendField("获取检测结果");
|
|
this.appendDummyInput()
|
|
this.appendDummyInput()
|
|
- .appendField(Blockly.Msg.ai_models_init_source)
|
|
|
|
- .appendField(new Blockly.FieldVariable("img_numpyrecognition"), "varitem");
|
|
|
|
|
|
+ .appendField("在屏幕中显示numpy的检测结果")
|
|
this.setPreviousStatement(true, null);
|
|
this.setPreviousStatement(true, null);
|
|
this.setNextStatement(true, null);
|
|
this.setNextStatement(true, null);
|
|
this.setColour("#ee783a");
|
|
this.setColour("#ee783a");
|
|
@@ -13319,7 +13492,6 @@ Blockly.Blocks['Numpy_Neural_Network_numpy_loading_model_fun'] = {
|
|
};
|
|
};
|
|
|
|
|
|
Blockly.Python['Numpy_Neural_Network_numpy_loading_model_fun'] = function (block) {
|
|
Blockly.Python['Numpy_Neural_Network_numpy_loading_model_fun'] = function (block) {
|
|
- var variable_name = Blockly.Python.variableDB_.getName(block.getFieldValue('varitem'), Blockly.Variables.NAME_TYPE);
|
|
|
|
Blockly.Python.definitions_["v831_import_PIL_image"] = `from PIL import Image`
|
|
Blockly.Python.definitions_["v831_import_PIL_image"] = `from PIL import Image`
|
|
Blockly.Python.definitions_["v831_function_numpy_result"] = `def numpyResult(img):
|
|
Blockly.Python.definitions_["v831_function_numpy_result"] = `def numpyResult(img):
|
|
img_path="/root/user/image_1.png"
|
|
img_path="/root/user/image_1.png"
|
|
@@ -13343,7 +13515,11 @@ Blockly.Python['Numpy_Neural_Network_numpy_loading_model_fun'] = function (block
|
|
return result
|
|
return result
|
|
`
|
|
`
|
|
// TODO: Assemble Python into code variable.
|
|
// TODO: Assemble Python into code variable.
|
|
- var code = `GETNUMPYRESULT = numpyResult(${variable_name})
|
|
|
|
|
|
+ var code = `GETNUMPYRESULT = numpyResult(canvas)
|
|
|
|
+if GETNUMPYRESULT != "":
|
|
|
|
+ canvas.draw_string(0,0, (str(GETNUMPYRESULT)), scale = 3, color = (204,204,204) , thickness = 1)
|
|
|
|
+else:
|
|
|
|
+ canvas.draw_string(0,0, ("None"), scale = 3, color = (204,204,204) , thickness = 1)
|
|
`;
|
|
`;
|
|
// TODO: Change ORDER_NONE to the correct strength.
|
|
// TODO: Change ORDER_NONE to the correct strength.
|
|
return code;
|
|
return code;
|