|
@@ -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];
|
|
|
};
|