Skip to content

Commit 9b7e449

Browse files
committed
find_text fixed
1 parent bca3b0b commit 9b7e449

File tree

7 files changed

+18
-74
lines changed

7 files changed

+18
-74
lines changed

camera.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -329,15 +329,18 @@ def find_color(self, s_color):
329329
#print "object: " + str(time.time() - ts)
330330
return [dist, angle]
331331

332-
def find_text(self, accept, back_color):
332+
def find_text(self):
333+
t1 = time.time()
333334
text = None
334-
color = (int(back_color[1:3], 16), int(back_color[3:5], 16), int(back_color[5:7], 16))
335+
#color = (int(back_color[1:3], 16), int(back_color[3:5], 16), int(back_color[5:7], 16))
335336
img = self.get_image()
336-
rec_image = img.find_rect(color=color)
337-
if rec_image:
338-
logging.info("image: %s", str(rec_image))
339-
bin_image = rec_image.binarize().invert()
340-
text = bin_image.find_text(accept)
337+
#rec_image = img.find_rect(color=color)
338+
text = img.find_text()
339+
logging.info("find_text fps: " + str(1.0/(time.time() - t1)))
340+
#if rec_image:
341+
# logging.info("image: %s", str(rec_image))
342+
# bin_image = rec_image.binarize().invert()
343+
# text = bin_image.find_text(accept)
341344
return text
342345

343346
def find_qr_code(self):

coderbot.cfg

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1 @@
1-
{
2-
"move_power_angle_3":"60",
3-
"cnn_default_model":"generic_fast_low",
4-
"prog_maxblocks":"-1",
5-
"camera_jpeg_quality":"5",
6-
"show_page_control":"true",
7-
"camera_framerate":"30",
8-
"prog_scrollbars":"true",
9-
"move_fw_speed":"100",
10-
"prog_level":"adv",
11-
"move_motor_trim":"1",
12-
"move_motor_mode":"dc",
13-
"cv_image_factor":"2",
14-
"move_power_angle_1":"45",
15-
"camera_path_object_size_min":"4000",
16-
"button_func":"none",
17-
"camera_color_object_size_min":"4000",
18-
"camera_jpeg_bitrate":"1000000",
19-
"move_fw_elapse":"1",
20-
"show_control_move_commands":"true",
21-
"camera_color_object_size_max":"160000",
22-
"show_page_prefs":"true",
23-
"camera_exposure_mode":"auto",
24-
"ctrl_tr_elapse":"-1",
25-
"show_page_program":"true",
26-
"move_tr_elapse":"0.5",
27-
"camera_path_object_size_max":"160000",
28-
"sound_shutter":"$shutter.mp3",
29-
"ctrl_fw_elapse":"-1",
30-
"sound_stop":"$shutdown.mp3",
31-
"ctrl_tr_speed":"80",
32-
"ctrl_fw_speed":"100",
33-
"move_tr_speed":"85",
34-
"move_power_angle_2":"60",
35-
"ctrl_hud_image":"",
36-
"load_at_start":"",
37-
"sound_start":"$startup.mp3",
38-
"encoder":"True"
39-
}
1+
{"move_power_angle_3": "60", "cnn_default_model": "generic_fast_low", "prog_maxblocks": "-1", "camera_jpeg_quality": "5", "show_page_control": "true", "camera_framerate": "30", "prog_scrollbars": "true", "move_fw_speed": "100", "prog_level": "adv", "move_motor_trim": "1", "move_motor_mode": "dc", "cv_image_factor": "2", "move_power_angle_1": "45", "camera_path_object_size_min": "4000", "button_func": "none", "camera_color_object_size_min": "4000", "camera_jpeg_bitrate": "1000000", "move_fw_elapse": "1", "show_control_move_commands": "true", "camera_color_object_size_max": "160000", "show_page_prefs": "true", "camera_exposure_mode": "auto", "ctrl_tr_elapse": "-1", "show_page_program": "true", "move_tr_elapse": "0.5", "camera_path_object_size_max": "160000", "sound_shutter": "$shutter.mp3", "ctrl_fw_elapse": "-1", "sound_stop": "$shutdown.mp3", "ctrl_tr_speed": "80", "ctrl_fw_speed": "100", "move_tr_speed": "85", "move_power_angle_2": "60", "ctrl_hud_image": "", "load_at_start": "", "sound_start": "$startup.mp3", "encoder": "True"}

cv/image.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,6 @@
2525
import cv.blob as blob
2626
import pytesseract
2727

28-
tesseract_whitelists = {
29-
'alpha': "ABCDEFGHIJKLMNOPQRSTUVXYZ ",
30-
'num': "1234567890 ",
31-
'alphanum': "ABCDEFGHIJKLMNOPQRSTUVXYZ1234567890 ",
32-
'unspec': "abcdefghijklmnopqrstuvxyzABCDEFGHIJKLMNOPQRSTUVXYZ1234567890 ",
33-
}
34-
35-
#try:
36-
# ocr = cv2.text.OCRTesseract_create(language="eng", char_whitelist=tesseract_whitelists['unspec'], oem=0, psmode=cv2.text.OCR_LEVEL_TEXTLINE)
37-
#except:
38-
# logging.info("tesseract not availabe")
39-
4028
MIN_MATCH_COUNT = 10
4129

4230
try:
@@ -247,7 +235,7 @@ def find_rect(self, color):
247235
int(min(image_size[0], -border+center[1]+(size[1]-5)/2)))
248236
return rect_image
249237

250-
def find_text(self, accept):
238+
def find_text(self):
251239
#wlist = tesseract_whitelists.get(accept, None)
252240
#ocr.setWhiteList(wlist)
253241
#text = ocr.run(self._data, 60)

static/js/blockly/blocks.js

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -659,25 +659,16 @@ Blockly.Blocks['coderbot_adv_findText'] = {
659659
this.setHelpUrl(Blockly.Msg.LOGIC_BOOLEAN_HELPURL);
660660
this.setColour(250);
661661
this.appendDummyInput()
662-
.appendField(Blockly.Msg.CODERBOT_SENSOR_FINDTEXT_FIND)
663-
.appendField(new Blockly.FieldDropdown([[Blockly.Msg.CODERBOT_SENSOR_FINDTEXT_ACCEPT_ALPHA, 'alpha'],
664-
[Blockly.Msg.CODERBOT_SENSOR_FINDTEXT_ACCEPT_NUM, 'num'],
665-
[Blockly.Msg.CODERBOT_SENSOR_FINDTEXT_ACCEPT_ALPHANUM,'alphanum'],
666-
[Blockly.Msg.CODERBOT_SENSOR_FINDTEXT_ACCEPT_UNSPEC,'unspec']]), 'ACCEPT')
667-
.appendField(Blockly.Msg.CODERBOT_SENSOR_FINDTEXT_COLOR);
668-
this.appendValueInput('COLOR')
669-
.setCheck(['Colour','String']);
662+
.appendField(Blockly.Msg.CODERBOT_SENSOR_FINDTEXT_FIND);
670663
this.setInputsInline(true);
671-
this.setOutput(true, ['Number', 'Array']);
664+
this.setOutput(true, 'String');
672665
this.setTooltip(Blockly.Msg.LOGIC_BOOLEAN_TOOLTIP);
673666
}
674667
};
675668

676669
Blockly.Python['coderbot_adv_findText'] = function(block) {
677670
// Boolean values true and false.
678-
var accept = block.getFieldValue('ACCEPT');
679-
var color = Blockly.Python.valueToCode(block, 'COLOR', Blockly.Python.ORDER_NONE);
680-
var code = 'get_cam().find_text(accept="' + accept + '", back_color=' + color + ')';
671+
var code = 'get_cam().find_text()';
681672
return [code, Blockly.Python.ORDER_ATOMIC];
682673
};
683674

static/js/blockly/bot_en.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Blockly.Msg.CODERBOT_SENSOR_AVERAGE_HUE = "Hue";
5656
Blockly.Msg.CODERBOT_SENSOR_AVERAGE_SATURATION = "Saturation";
5757
Blockly.Msg.CODERBOT_SENSOR_AVERAGE_VALUE = "Value (brightness)";
5858
Blockly.Msg.CODERBOT_SENSOR_AVERAGE_ALL = "HSV (as list)";
59-
Blockly.Msg.CODERBOT_SENSOR_FINDTEXT_FIND = "find text of kind";
59+
Blockly.Msg.CODERBOT_SENSOR_FINDTEXT_FIND = "find text";
6060
Blockly.Msg.CODERBOT_SENSOR_FINDTEXT_ACCEPT_ALPHA = "Alpha (A..Z)";
6161
Blockly.Msg.CODERBOT_SENSOR_FINDTEXT_ACCEPT_NUM = "Numeric (0..9)";
6262
Blockly.Msg.CODERBOT_SENSOR_FINDTEXT_ACCEPT_ALPHANUM = "Alphanumeric (A..Z;0..9)";

static/js/blockly/bot_fr.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Blockly.Msg.CODERBOT_SENSOR_AVERAGE_VALUE = "Value (brightness)";
5353
Blockly.Msg.CODERBOT_SENSOR_AVERAGE_ALL = "HSV (as list)";
5454
Blockly.Msg.CODERBOT_SENSOR_FINDLOGO = "trouve le logo";
5555
Blockly.Msg.CODERBOT_SENSOR_FINDCLASS = "trouve le class";
56-
Blockly.Msg.CODERBOT_SENSOR_FINDTEXT_FIND = "find text of kind";
56+
Blockly.Msg.CODERBOT_SENSOR_FINDTEXT_FIND = "trouve le text";
5757
Blockly.Msg.CODERBOT_SENSOR_FINDTEXT_ACCEPT_ALPHA = "Alpha (A..Z)";
5858
Blockly.Msg.CODERBOT_SENSOR_FINDTEXT_ACCEPT_NUM = "Numeric (0..9)";
5959
Blockly.Msg.CODERBOT_SENSOR_FINDTEXT_ACCEPT_ALPHANUM = "Alphanumeric (A..Z;0..9)";

static/js/blockly/bot_it.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Blockly.Msg.CODERBOT_SENSOR_AVERAGE_HUE = "Tinta";
5656
Blockly.Msg.CODERBOT_SENSOR_AVERAGE_SATURATION = "Saturazione";
5757
Blockly.Msg.CODERBOT_SENSOR_AVERAGE_VALUE = "Luminosità";
5858
Blockly.Msg.CODERBOT_SENSOR_AVERAGE_ALL = "HSV (come lista)";
59-
Blockly.Msg.CODERBOT_SENSOR_FINDTEXT_FIND = "trova testo formato da";
59+
Blockly.Msg.CODERBOT_SENSOR_FINDTEXT_FIND = "trova testo";
6060
Blockly.Msg.CODERBOT_SENSOR_FINDTEXT_ACCEPT_ALPHA = "Lettere (A..Z)";
6161
Blockly.Msg.CODERBOT_SENSOR_FINDTEXT_ACCEPT_NUM = "Numeri (0..9)";
6262
Blockly.Msg.CODERBOT_SENSOR_FINDTEXT_ACCEPT_ALPHANUM = "Lettere e numeri (A..Z;0..9)";

0 commit comments

Comments
 (0)