Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

116
LINES

< > BotCompany Repo | #1006104 // Show & recognize

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (10123L/72K/249K).

1  
!752
2  
3  
concept GrabbedImage {
4  
  long lastScreenshotTime;
5  
  Rect lastRect;
6  
  BWImage image;
7  
  S md5;
8  
  int count;
9  
  
10  
  BWImage visualizedSplit;
11  
  new L<Rect> rects;
12  
  new L<BWImage> characters;
13  
  new L<S> characterMD5s;
14  
  S recognition;
15  
}
16  
17  
concept RecogInfo {
18  
  new L<S> lines;
19  
}
20  
21  
static SimpleRecognizer sr;
22  
static Concepts in;
23  
static JTable table;
24  
  
25  
p {
26  
  in = new Concepts("#1005951").load();
27  
  conceptsAndBot();
28  
  sr = new SimpleRecognizer;
29  
  sr.load(joinLines(uniq(RecogInfo).lines));
30  
31  
  update();
32  
}
33  
34  
svoid update {
35  
  try {
36  
    if (table != null) {
37  
      frameIcon(table, "#1005541");
38  
      setFrameTitle(table, "Calculating - Recognitions");
39  
    }
40  
    new L<L> data;
41  
    for (GrabbedImage gi : sortByFieldDesc(in.list(GrabbedImage), "lastScreenshotTime")) {
42  
      if (gi.visualizedSplit == null) {
43  
        L<Rect> rects = horizontalAutoSplit2ThenAutoCrop(gi.image);
44  
        cset(gi, visualizedSplit := new BWImage(mergeImagePartsHorizontally(gi.image.toRGB(), rects)));
45  
        for (Rect r : rects) {
46  
          BWImage cImg = gi.image.clip(r);
47  
          gi.rects.add(r);
48  
          gi.characters.add(cImg);
49  
          gi.characterMD5s.add(md5OfBWImage(cImg));
50  
        }
51  
      }
52  
      S rec = sr.recognizeCheat(gi.image);
53  
      if (rec != null)
54  
        gi.recognition = "! " + rec;
55  
      else
56  
        gi.recognition = sr.recognize(gi.image);
57  
      data.add(ll(gi.md5, gi.image.getBufferedImage(), gi.recognition, gi.visualizedSplit.getBufferedImage(), join(" ", gi.characterMD5s)));
58  
    }
59  
    
60  
    bool first = table == null;
61  
    table = showTableWithImages("Recognitions", splitAtSlash("MD5/Image/Recognition/Split/Character MD5s"), data, table);
62  
    
63  
    if (!first) ret;
64  
    
65  
    awt {
66  
      table.setRowHeight(25);
67  
      tablePopupMenu(table, voidfunc(JPopupMenu menu, final int row) {
68  
        addMenuItem(menu, "Teach...", r {
69  
          S md5 = cast getTableCell(table, row, 0);
70  
          final GrabbedImage gi = findConcept(in, GrabbedImage, +md5);
71  
          final new JTextField tf;
72  
          final JCheckBox grouped = jCheckBox("grouped", true);
73  
          final JButton btnSubmit = jbutton("Submit", r {
74  
            S s = trim(tf.getText());
75  
            bool group = isChecked(grouped);
76  
            L<Rect> rects = gi.rects;
77  
            if (group) {
78  
              rects = ocr_groupRects(rects, s);
79  
              s = ocr_unmerge(s);
80  
            }
81  
            L<S> characterMD5s = md5OfBWImageParts(gi.image, rects);
82  
            S line = "The images " + quote(join(" ", characterMD5s)) + " are the " + (group ? "grouped " : "") + "characters " + quote(s) + ".";
83  
            print(">> " + line);
84  
            RecogInfo ri = uniq(RecogInfo);
85  
            if (setAdd(ri.lines, line)) {
86  
              sr.load(line);
87  
              ri.change();
88  
            }
89  
            disposeFrame(tf);
90  
          });
91  
          onUpdateAndNow(ll(tf, grouped), r {
92  
            btnSubmit.setEnabled(ocr_charCountDropSpaces(trim(tf.getText()), isChecked(grouped)) == l(gi.characters));
93  
          });
94  
          showFormTitled("Teach",
95  
            "Image:" , new ImageSurface(gi.image.getBufferedImage()),
96  
            "Split:" , new ImageSurface(gi.visualizedSplit.getBufferedImage()),
97  
            "Meaning:", tf,
98  
            "", grouped,
99  
            "", btnSubmit);
100  
        });
101  
        addMenuItem(menu, "Mark on screen", r-thread {
102  
          Rect r;
103  
          pointArrowsToArea(r = parseRect(getTableLine(table, row).get(3)));
104  
          print("Marking: " + r);
105  
        });
106  
      });
107  
    
108  
      gcAndPrintMemoryInfo();
109  
      
110  
      awtCalcOnConceptChanges(table, 1000, 1000, func update, false);
111  
    }
112  
  } finally {
113  
    frameIcon(table, null);
114  
    setFrameTitle(table, "Recognitions");
115  
  }
116  
}

Author comment

Began life as a copy of #1005971

download  show line numbers  debug dex  old transpilations   

Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, sawdedvomwva, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1006104
Snippet name: Show & recognize
Eternal ID of this version: #1006104/1
Text MD5: 3c040049ab45bfb67b803e3765ae2221
Transpilation MD5: 1e2ca71b40b3cbe27099c3bff6a8bf48
Author: stefan
Category: javax / gui / ocr
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-12-22 23:35:51
Source code size: 3787 bytes / 116 lines
Pitched / IR pitched: No / No
Views / Downloads: 629 / 1685
Referenced in: [show references]