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

93
LINES

< > BotCompany Repo | #1006242 // Record browser's URL box with feedback [works]

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

Libraryless. Click here for Pure Java version (9737L/69K/231K).

1  
!7
2  
3  
static int sleepTimeWhenNotFound = 5000;
4  
5  
static JFrame frame;
6  
static SingleComponentPanel scp;
7  
static ImageSurface imageSurface;
8  
static FindURLBox1 finder;
9  
10  
static BoxShot shot;
11  
static TimeRange timeRange;
12  
13  
concept BoxShot {
14  
  S imageMD5;
15  
  byte[] png;
16  
  new RefL<TimeRange> timeRanges;
17  
}
18  
19  
concept Evaluation {
20  
  new Ref<BoxShot> shot;
21  
  S comment;
22  
}
23  
24  
Evaluation > WrongResult {}
25  
Evaluation > GoodResult {}
26  
27  
p {
28  
  conceptsAndBot(60*1000);
29  
  
30  
  awt {
31  
    finder = new FindURLBox1;
32  
    JComponent feedback = jRightAlignedLine(
33  
      jlabel("Is this the right box?"), jbutton("Yes", "yes"), jbutton("No", "no"));
34  
    scp = new SingleComponentPanel(jcenteredLabel("-"));
35  
    frame = showFrame("Find URL Box", centerAndSouth(scp, feedback));
36  
    frameIcon(frame, #1005541);
37  
    frameInnerSize(frame, 500, 100);
38  
    moveToBottomRightCorner(frame);
39  
    frame.setAlwaysOnTop(true);
40  
    
41  
    awtCalcRegularly(frame, 200, 0, r {
42  
      final bool b = finder.go();
43  
      awt {
44  
        if (b) {
45  
          RGBImage img = finder.bestImage();
46  
          S since = "";
47  
          if (shot != null && timeRange != null)
48  
            since = ", since " + (now()-timeRange.from)/1000 + "s, " + nth(l(shot.timeRanges)) + " appearance)";
49  
          S text = "URL box found in " + finder.recogTime + " ms (" + img.w() + "*" + img.h() + " px" + since + ")";
50  
          if (imageSurface == null) {
51  
            imageSurface = new ImageSurface(img);
52  
            scp.setComponent(jSection(text, new JScrollPane(imageSurface)));
53  
          } else {
54  
            imageSurface.setImage(img);
55  
            setSectionTitle(imageSurface, text);
56  
          }
57  
          
58  
          S imageMD5 = md5OfRGBImage(img);
59  
          shot = uniq(BoxShot, +imageMD5);
60  
          if (shot.png == null) shot.png = rgbImageToPNG(img);
61  
          if (shot.timeRanges.contains(timeRange))
62  
            timeRange.addNow();
63  
          else
64  
            shot.timeRanges.add(timeRange = new TimeRange(now()));
65  
          shot.change();
66  
        } else {
67  
          shot = null;
68  
          timeRange = null;
69  
          if (imageSurface != null) {
70  
            imageSurface = null;
71  
            scp.setComponent(jcenteredLabel("URL box not found (" + finder.recogTime + " ms)"));
72  
          }
73  
        }
74  
      }
75  
      if (!b) sleep(sleepTimeWhenNotFound);
76  
    });
77  
  }
78  
}
79  
80  
svoid yes {
81  
  print("yes");
82  
  feedback(new GoodResult);
83  
}
84  
85  
svoid no {
86  
  feedback(new WrongResult);
87  
}
88  
89  
svoid feedback(Evaluation ev) {
90  
  cset(ev, +shot);
91  
  infoMessage("Thank you, " + (ev << WrongResult ? "negative" : "positive") + " feedback recorded. (id=" + ev.id + ")");
92  
  mainConcepts.save();
93  
}

Author comment

Began life as a copy of #1006232

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1006242
Snippet name: Record browser's URL box with feedback [works]
Eternal ID of this version: #1006242/1
Text MD5: e2decbe68cf9cd2db2691ae8632ef0d3
Transpilation MD5: f4829c6a92a52283101c2229f22e8163
Author: stefan
Category: javax / ocr
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-12-25 21:31:34
Source code size: 2685 bytes / 93 lines
Pitched / IR pitched: No / No
Views / Downloads: 573 / 662
Referenced in: [show references]