chao 1 年之前
父节点
当前提交
372b91b3d5

+ 96 - 61
blockly/blocks/python/ai.js

@@ -570,17 +570,14 @@ Blockly.Blocks['ai_lcd_rotation'] = {
 Blockly.Python.ai_lcd_rotation = function (block) {
     // var variable_name = Blockly.Python.variableDB_.getName(block.getFieldValue('varitem'), Blockly.Variables.NAME_TYPE);
     var dropdown_name = block.getFieldValue('DEGREE');
-    Blockly.Python.definitions_['v831_rotation_fun'] = `
-def screenShow(inputImg,rotationAngle):
-    #global img_drop
-    
+    Blockly.Python.addFunction('v831_rotation_fun', `def screenShow(inputImg,rotationAngle):
     if rotationAngle==90 or rotationAngle == 270:
         screenCapture=inputImg.crop(0,0,240,320)
     else:
         screenCapture=inputImg.crop(0,0,320,240)
     canvas_screenShow = screenCapture.rotate(-rotationAngle,adjust=1)
     display.show(canvas_screenShow)
-`
+`)
     let w = ''
     let h = ''
     if (dropdown_name == 90 || dropdown_name == 270) {
@@ -3650,7 +3647,9 @@ Blockly.Blocks['ai_vision_find_apriltag'] = {
             .appendField(Blockly.Msg.ai_vision_get_canvas+Blockly.Msg.ai_vision_apriltag_detected_result)
             // .appendField(new Blockly.FieldVariable("canvas"), "varitem")
             // .appendField();
-        this.setOutput(true, null);
+        // this.setOutput(true, null);
+        this.setNextStatement(true, null);
+        this.setPreviousStatement(true, null);
         this.setColour("#f0983e");
         this.setTooltip(Blockly.Msg.ai_vision_find_apriltag_TOOLTIP);
         this.setHelpUrl("");
@@ -3660,37 +3659,31 @@ Blockly.Blocks['ai_vision_find_apriltag'] = {
 Blockly.Python['ai_vision_find_apriltag'] = function (block) {
     // var variable_name = Blockly.Python.variableDB_.getName(block.getFieldValue('varitem'), Blockly.Variables.NAME_TYPE);
     // TODO: Assemble Python into code variable.
-    var code = 'canvas.find_apriltags(families = 16,fx = (6/5.76)*320,fy = (6/3.24)*240,cx = 160,cy = 120)';
+    var code = 'findApriltags = canvas.find_apriltags(families = 16,fx = (6/5.76)*320,fy = (6/3.24)*240,cx = 160,cy = 120)';
     // TODO: Change ORDER_NONE to the correct strength.
-    return [code, Blockly.Python.ORDER_NONE];
+    return code;
 };
 
-
 Blockly.Blocks['ai_vision_apriltag_get_info'] = {
     init: function () {
         this.appendDummyInput()
-            .appendField(Blockly.Msg.ai_vision_from)
-            .appendField(new Blockly.FieldVariable("i"), "varitem")
             .appendField(Blockly.Msg.ai_vision_apriltag_get_result)
             .appendField(new Blockly.FieldDropdown([
-                // [Blockly.Msg.ai_vision_pattern_detection_content, "payload"],
-                [Blockly.Msg.ai_vision_pattern_detection_type_id, "id"],
-                [Blockly.Msg.ai_vision_pattern_detection_type_family, "family"],
-                [Blockly.Msg.ai_vision_pattern_detection_x, "x"],
-                [Blockly.Msg.ai_vision_pattern_detection_y, "y"],
-                [Blockly.Msg.ai_vision_pattern_detection_w, "w"],
-                [Blockly.Msg.ai_vision_pattern_detection_h, "h"],
-                [Blockly.Msg.ai_vision_pattern_distance, "distance"]
+                [Blockly.Msg.ai_vision_pattern_detection_content, "ApriltagId"],
+                // [Blockly.Msg.ai_vision_pattern_detection_type_id, "id"],
+                [Blockly.Msg.ai_vision_pattern_detection_type_family, "ApriltagCheckout"]
             ]), "get_info");
         this.setInputsInline(false);
-        this.setOutput(true, null);
+        // this.setOutput(true, null);
+        this.setNextStatement(true, null);
+        this.setPreviousStatement(true, null);
         this.setColour("#f0983e");
         var thisBlock = this;
         this.setTooltip(function () {
             var mode = thisBlock.getFieldValue('get_info');
             var TOOLTIPS = {
                 'payload': Blockly.Msg.ai_vision_apriltag_get_info_TOOLTIP.replace('%1', Blockly.Msg.ai_vision_pattern_detection_content),
-                'id': Blockly.Msg.ai_vision_apriltag_get_info_TOOLTIP.replace('%1', Blockly.Msg.ai_vision_pattern_detection_type_id),
+                'id': Blockly.Msg.ai_vision_apriltag_get_info_TOOLTIP.replace('%1', Blockly.Msg.ai_vision_pattern_detection_content),
                 'family': Blockly.Msg.ai_vision_apriltag_get_info_TOOLTIP.replace('%1', Blockly.Msg.ai_vision_pattern_detection_type_family),
                 'x': Blockly.Msg.ai_vision_apriltag_get_info_TOOLTIP.replace('%1', Blockly.Msg.ai_vision_pattern_detection_x),
                 'y': Blockly.Msg.ai_vision_apriltag_get_info_TOOLTIP.replace('%1', Blockly.Msg.ai_vision_pattern_detection_y),
@@ -3706,13 +3699,22 @@ Blockly.Blocks['ai_vision_apriltag_get_info'] = {
 Blockly.Python['ai_vision_apriltag_get_info'] = function (block) {
     var variable_name = Blockly.Python.variableDB_.getName(block.getFieldValue('varitem'), Blockly.Variables.NAME_TYPE);
     var dropdown_name = block.getFieldValue('get_info');
+    let apriltagAllBlock = getBlocksByTypeName("ai_vision_apriltag_get_info")
+    let findQrcodeStr = apriltagAllBlock[0].innerText
+    let ApriltagId = findQrcodeStr.indexOf("ApriltagId") != -1?"True":"False"
+    let ApriltagCheckout = findQrcodeStr.indexOf("ApriltagCheckout") != -1?"True":"False"
+    Blockly.Python.addFunction("getApriltagCanvasResult", `def getApriltagCanvasResult(ApriltagId,ApriltagCheckout):
+    global findApriltags
+    for i in findApriltags:
+        if apriltagId:
+            canvas.draw_string((i["x"]),(i["y"]), (i["id"]), scale = 1, color = (255,0,0) , thickness = 1)
+        if ApriltagCheckout:
+            canvas.draw_rectangle((i["x"]),(i["y"]), (i["x"])+(i["w"]),(i["y"])+ (i["h"]), color=(255,0,0), thickness=1)
+    )`)
     // TODO: Assemble Python into code variable.
-    var code = `${variable_name}["${dropdown_name}"]`;
-    if (dropdown_name == "distance") {
-        code = `int((${variable_name}['x_translation']*${variable_name}['x_translation']+${variable_name}['y_translation']*${variable_name}['y_translation']+${variable_name}['z_translation']*${variable_name}['z_translation']**0.5)*3.0649-2)`
-    }
+    var code = `getApriltagCanvasResult(${ApriltagId},${ApriltagCheckout})`;
     // TODO: Change ORDER_NONE to the correct strength.
-    return [code, Blockly.Python.ORDER_NONE];
+    return code;
 };
 
 
@@ -3721,11 +3723,7 @@ Blockly.Python['ai_vision_apriltag_get_info'] = function (block) {
 Blockly.Blocks['ai_vision_find_datamatrices'] = {
     init: function () {
         this.appendDummyInput()
-            .appendField(new Blockly.FieldImage("blockly/media/ai_vision_datamatrix_.png", 45, 45, { alt: "*", flipRtl: "FALSE" }));
-        this.appendDummyInput()
-            .appendField(Blockly.Msg.ai_vision_get_canvas)
-            .appendField(new Blockly.FieldVariable("canvas"), "varitem")
-            .appendField(Blockly.Msg.ai_vision_datamatrices_detected_result);
+            .appendField(Blockly.Msg.ai_vision_get_canvas+Blockly.Msg.ai_vision_apriltag_detected_result);
         this.setOutput(true, null);
         this.setColour("#f0983e");
         this.setTooltip(Blockly.Msg.ai_vision_find_datamatrices_TOOLTIP);
@@ -3734,9 +3732,14 @@ Blockly.Blocks['ai_vision_find_datamatrices'] = {
 };
 
 Blockly.Python['ai_vision_find_datamatrices'] = function (block) {
-    var variable_name = Blockly.Python.variableDB_.getName(block.getFieldValue('varitem'), Blockly.Variables.NAME_TYPE);
-    // TODO: Assemble Python into code variable.
-    var code = variable_name + '.find_datamatrices()';
+    Blockly.Python.addFunction("getApriltagResult", `def getApriltagResult():
+        global findApriltags
+        if len(findApriltags):
+            return findApriltags[0]["id"]
+        else:
+            return ""
+        )`)
+    var code = `getApriltagResult()`;
     // TODO: Change ORDER_NONE to the correct strength.
     return [code, Blockly.Python.ORDER_NONE];
 };
@@ -3800,7 +3803,8 @@ Blockly.Blocks['ai_vision_find_barcodes'] = {
             .appendField(Blockly.Msg.ai_vision_get_canvas+Blockly.Msg.ai_vision_barcode_detected_result)
             // .appendField(new Blockly.FieldVariable("canvas"), "varitem")
             // .appendField();
-        this.setOutput(true, null);
+        this.setNextStatement(true);
+        this.setPreviousStatement(true);
         this.setColour("#f0983e");
         this.setTooltip(Blockly.Msg.ai_vision_find_barcodes_TOOLTIP);
         this.setHelpUrl("");
@@ -3810,35 +3814,31 @@ Blockly.Blocks['ai_vision_find_barcodes'] = {
 Blockly.Python['ai_vision_find_barcodes'] = function (block) {
     // var variable_name = Blockly.Python.variableDB_.getName(block.getFieldValue('varitem'), Blockly.Variables.NAME_TYPE);
     // TODO: Assemble Python into code variable.
-    var code = 'canvas.find_barcodes()';
+    var code = 'findBarcodes = canvas.find_barcodes() \n';
     // TODO: Change ORDER_NONE to the correct strength.
-    return [code, Blockly.Python.ORDER_NONE];
+    return code;
 };
 
 
 Blockly.Blocks['ai_vision_barcodes_get_info'] = {
     init: function () {
         this.appendDummyInput()
-            .appendField(Blockly.Msg.ai_vision_from_canvas)
-            .appendField(new Blockly.FieldVariable("i"), "varitem")
-            .appendField(Blockly.Msg.ai_vision_barcode_matrices_get_result)
+            .appendField("屏幕显示条形码")
             .appendField(new Blockly.FieldDropdown([
-                [Blockly.Msg.ai_vision_pattern_detection_content, "payload"],
-                [Blockly.Msg.ai_vision_pattern_detection_type, "type"],
-                [Blockly.Msg.ai_vision_pattern_detection_x, "x"],
-                [Blockly.Msg.ai_vision_pattern_detection_y, "y"],
-                [Blockly.Msg.ai_vision_pattern_detection_w, "w"],
-                [Blockly.Msg.ai_vision_pattern_detection_h, "h"]
+                [Blockly.Msg.ai_vision_pattern_detection_content, "barcodesPayload"],
+                [Blockly.Msg.ai_models_face_model_rect, "barcodesCorners"]
             ]), "get_info");
         this.setInputsInline(false);
-        this.setOutput(true, null);
+        this.setOutput(false, null);
+        this.setNextStatement(true);
+        this.setPreviousStatement(true);
         this.setColour("#f0983e");
         var thisBlock = this;
         this.setTooltip(function () {
             var mode = thisBlock.getFieldValue('get_info');
             var TOOLTIPS = {
                 'payload': Blockly.Msg.ai_vision_barcodes_get_info_TOOLTIP.replace('%1', Blockly.Msg.ai_vision_pattern_detection_content),
-                'type': Blockly.Msg.ai_vision_barcodes_get_info_TOOLTIP.replace('%1', Blockly.Msg.ai_vision_pattern_detection_type),
+                'corners': Blockly.Msg.ai_models_face_model_rect.replace('%1', Blockly.Msg.ai_models_face_model_rect),
                 'x': Blockly.Msg.ai_vision_barcodes_get_info_TOOLTIP.replace('%1', Blockly.Msg.ai_vision_pattern_detection_x),
                 'y': Blockly.Msg.ai_vision_barcodes_get_info_TOOLTIP.replace('%1', Blockly.Msg.ai_vision_pattern_detection_y),
                 'w': Blockly.Msg.ai_vision_barcodes_get_info_TOOLTIP.replace('%1', Blockly.Msg.ai_vision_pattern_detection_w),
@@ -3851,27 +3851,61 @@ Blockly.Blocks['ai_vision_barcodes_get_info'] = {
 };
 
 Blockly.Python['ai_vision_barcodes_get_info'] = function (block) {
-    var variable_name = Blockly.Python.variableDB_.getName(block.getFieldValue('varitem'), Blockly.Variables.NAME_TYPE);
     var dropdown_name = block.getFieldValue('get_info');
+    let qrcodeResultAllBlock = getBlocksByTypeName("ai_vision_barcodes_get_info")
+    // console.log("qrcode_result",qrcodeResultAllBlock[0].innerText)
+    let findQrcodeStr = qrcodeResultAllBlock[0].innerText
+    let barcodesPayload = findQrcodeStr.indexOf("barcodesPayload") != -1?"True":"False"
+    let barcodesCorners = findQrcodeStr.indexOf("barcodesCorners") != -1?"True":"False"
+    Blockly.Python.addFunction("showBarcodesResult", `def showBarcodesResult(type1,type2):
+    global findBarcodes
+    for i in findBarcodes:
+        if type1:
+            canvas.draw_string((i["corners"][0][0]),(i["corners"][0][1]), (i["payload"]), scale = 1, color = (255,0,0) , thickness = 1)
+        if type2:
+            x1,y1 = i['corners'][0]   #访问字典的列表
+            x2,y2 = i['corners'][1]
+            x3,y3 = i['corners'][2]
+            x4,y4 = i['corners'][3]
+            canvas.draw_line(x1, y1, x2, y2, color = (0, 255, 0), thickness = 3)  
+            canvas.draw_line(x2, y2, x3, y3, color = (0, 255, 0), thickness = 3)  
+            canvas.draw_line(x3, y3, x4, y4, color = (0, 255, 0), thickness = 3)  
+            canvas.draw_line(x4, y4, x1, y1, color = (0, 255, 0), thickness = 3)
+`)
     // TODO: Assemble Python into code variable.
-    var code = variable_name + '["' + dropdown_name + '"]';
-    if (dropdown_name == "x") {
-        code = `${variable_name}["corners"][0][0]`
-    } else if (dropdown_name == "y") {
-        code = `${variable_name}["corners"][0][1]`
-    } else if (dropdown_name == "w") {
-        code = `${variable_name}["corners"][2][0] - ${variable_name}["corners"][0][0]`
-    } else if (dropdown_name == "h") {
-        code = `${variable_name}["corners"][2][1] - ${variable_name}["corners"][0][1]`
-    } else {
-        code = `${variable_name}["${dropdown_name}"]`
+    let code = ""
+    if(qrcodeResultAllBlock[0].id == block.id){
+        code =`showBarcodesResult(${barcodesPayload},${barcodesCorners})
+`
     }
-    // TODO: Change ORDER_NONE to the correct strength.
+    return code
+};
+Blockly.Blocks['ai_vision_barcodes_get_info_result'] = {
+    init: function () {
+        this.appendDummyInput()
+            .appendField(Blockly.Msg.uav_bar_code)
+        this.setInputsInline(false);
+        this.setOutput(true, null);
+        this.setColour("#f0983e");
+        this.setTooltip(Blockly.Msg.uav_bar_code);
+    }
+};
+
+Blockly.Python['ai_vision_barcodes_get_info_result'] = function (block) {
+    Blockly.Python.addFunction("getBarcodesResult", `def getBarcodesResult():
+    global findBarcodes
+    if len(findBarcodes)>0:
+        return findBarcodes[0]["payload"]
+    else:
+        return ""
+`)
+    var code = `getBarcodesResult()`;
     return [code, Blockly.Python.ORDER_NONE];
 };
 
 
 
+
 Blockly.Blocks['ai_vision_get_circles'] = {
     init: function () {
         this.appendDummyInput()
@@ -8746,6 +8780,7 @@ Blockly.Blocks['ai_model_digital_attribute'] = {
 };
 
 Blockly.Python['ai_model_digital_attribute'] = function (block) {
+    Blockly.Python.addFunction("",`def ai_model_digital_attribute():`)
     var code = 'len(BOXES)';
     return [code, Blockly.Python.ORDER_NONE];
 };

+ 7 - 1
blockly/blocks/python/esp32.js

@@ -263,9 +263,15 @@ sys.path.append("/root/")`
         code = `digitalRead("${value_name}")`
     }
     else {
+        Blockly.Python.addFunction("convert",`def BooleraConvertNum(value):
+    if value:
+        return 1
+    else:
+        return 0
+`)
         Blockly.Python.definitions_['v831_import_CocoPi_BUTTON'] = `from CocoPi import BUTTON `;
         Blockly.Python.addVariable('_Math_gpio_' + value_name, `_Math_gpio_${value_name} = BUTTON(${value_name})`, true);
-        code = `_Math_gpio_${value_name}.is_pressed()`;
+        code = `BooleraConvertNum(_Math_gpio_${value_name}.is_pressed())`;
     }
 
     // TODO: Change ORDER_NONE to the correct strength.

+ 1 - 1
blockly/msg/js/en.js

@@ -5122,7 +5122,7 @@ Blockly.Msg.uav_black_spots = "Black spots";
 Blockly.Msg.uav_black_line = "The black line";
 Blockly.Msg.uav_black_label = "The label";
 Blockly.Msg.uav_code = "Qr code";
-Blockly.Msg.uav_bar_code = "Bar code";
+Blockly.Msg.uav_bar_code = "Get Barcode Results";
 Blockly.Msg.uav_electromagnet = "Electromagnet";
 Blockly.Msg.uav_servo_ctrl = "The steering gear of a drone";
 Blockly.Msg.uav_role_ctrl = "Drone orders";

+ 1 - 1
blockly/msg/js/zh-hans.js

@@ -5075,7 +5075,7 @@ Blockly.Msg.uav_black_line = "黑线";
 Blockly.Msg.uav_black_line = "黑线";
 Blockly.Msg.uav_black_label = "标签";
 Blockly.Msg.uav_code = "二维码";
-Blockly.Msg.uav_bar_code = "条形码";
+Blockly.Msg.uav_bar_code = "获取条形码结果";
 Blockly.Msg.uav_electromagnet = "电磁铁";
 Blockly.Msg.uav_servo_ctrl = "无人机的舵机";
 Blockly.Msg.uav_role_ctrl = "无人机的命令";

+ 1 - 1
blockly/msg/js/zh-hant.js

@@ -5536,7 +5536,7 @@ Blockly.Msg.uav_black_spots = "黑点";
 Blockly.Msg.uav_black_line = "黑線";
 Blockly.Msg.uav_black_label = "標籤";
 Blockly.Msg.uav_code = "二維碼";
-Blockly.Msg.uav_bar_code = "條形碼";
+Blockly.Msg.uav_bar_code = "獲取條形碼結果";
 Blockly.Msg.uav_electromagnet = "電磁鐵";
 Blockly.Msg.uav_servo_ctrl = "無人機的舵機";
 Blockly.Msg.uav_role_ctrl = "無人機的命令";

+ 2 - 1
src/editor.js

@@ -2556,10 +2556,11 @@ BlockPyEditor.CATEGORY_MAP = {
         '<block type="ai_vision_qrcode_get_info"></block>' +
         '<block type="ai_vision_find_apriltag"></block>' +
         '<block type="ai_vision_apriltag_get_info"></block>' +
-        // '<block type="ai_vision_find_datamatrices"></block>' +
+        '<block type="ai_vision_find_datamatrices"></block>' +
         // '<block type="ai_vision_datamatrices_get_info"></block>' +
         '<block type="ai_vision_find_barcodes"></block>' +
         '<block type="ai_vision_barcodes_get_info"></block>' +
+        '<block type="ai_vision_barcodes_get_info_result"></block>' +
         '</category>' +
 
 

+ 35 - 0
src/python/图像处理/获取条形码.xml

@@ -0,0 +1,35 @@
+<xml xmlns="http://www.w3.org/1999/xhtml" type="IoT">
+  <block type="controls_repeat_forever" id="MiF-ngsfEtU#I{-EVeK]" x="354" y="129">
+    <statement name="DO">
+      <block type="ai_camera_snapshot" id="YkGz:}!-V$Tx%raRdt{h">
+        <next>
+          <block type="ai_vision_find_barcodes" id="O#!u#-Bdq*wOS7cRCIS3">
+            <next>
+              <block type="ai_vision_barcodes_get_info" id="e=zLTxk$F^fUxI_GZX;(">
+                <field name="get_info">barcodesPayload</field>
+                <next>
+                  <block type="ai_vision_barcodes_get_info" id="2kNym?z+-K{I$E%H$`oH">
+                    <field name="get_info">barcodesCorners</field>
+                    <next>
+                      <block type="serial_comm_print" id="X=qBcY4CIot9Ly~=l)sO">
+                        <value name="serial_comm_input">
+                          <shadow type="text" id="VS^6lZWUd=EU6M3ev1E|">
+                            <field name="TEXT">Hello World!</field>
+                          </shadow>
+                          <block type="ai_vision_barcodes_get_info_result" id="rN5d,WIIBzrh5tjOeX5-"></block>
+                        </value>
+                        <next>
+                          <block type="ai_lcd_showcarvas_set_display" id="%{.l-j]~4_!Nt$-VF:.*"></block>
+                        </next>
+                      </block>
+                    </next>
+                  </block>
+                </next>
+              </block>
+            </next>
+          </block>
+        </next>
+      </block>
+    </statement>
+  </block>
+</xml>