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

50
LINES

< > BotCompany Repo | #1030553 // OCRCompass - detects orientation of a line at a point in integral image

JavaX fragment (include) [tags: use-pretranspiled]

Transpiled version (6927L) is out of date.

1  
// call clearCache when changing parameters
2  
sclass OCRCompass implements Renderable {
3  
  // compass can look for dark or bright lines, set this flag accordingly:
4  
  bool brightForeground;
5  
  
6  
  IBWIntegralImage image;
7  
  Pt center; // point we're looking at
8  
  double radius = 16; // radius of circle
9  
  int sensorFootprint = 0; // size of each "pixel" (rectangle) to grab - defaults to radius
10  
  int steps = 12; // how many segments of circle (=steps/2 line orientations). should be even
11  
  int blur; // blur width
12  
  double[] values; // brightnesses at each point (low=foreground)
13  
  L<Rect> sensors;
14  
  
15  
  L<Rect> sensors() {
16  
    if (sensors == null)
17  
      sensors = squaresAroundCircle(center, steps, radius, sensorFootprint());
18  
    ret sensors;
19  
  }
20  
  
21  
  int angles() { ret steps/2; }
22  
  
23  
  int sensorFootprint() {
24  
    ret sensorFootprint == 0 ? iceil(radius*12/max(steps, 12)) : sensorFootprint;
25  
  }
26  
  
27  
  void compute {
28  
    L<Rect> sensors = sensors();
29  
    if (l(values) != angles()) values = new double[angles()];
30  
    for i over values: values[i] = avg(
31  
      image.getPixelAverage(sensors.get(i)),
32  
      image.getPixelAverage(sensors.get(i+angles())));
33  
  }
34  
  
35  
  void ensureComputed { if (values == null) compute(); }
36  
  
37  
  double mostLikelyAngle() { ensureComputed();
38  
    ret indexOfMinOrMaxEntryInDoubleArray(brightForeground, values)*twoPi()/steps;
39  
  }
40  
  
41  
  public void renderOn(Graphics2D g, int w, int h) { ensureComputed();
42  
    renderRenderables(g, w, h, zipAndMap(sensors(), repeatList(2, asList(values)),
43  
      (r, value) -> BoxWithColor(r, 0, 0, iround(value))));
44  
    drawRotatedRoundEdgeLine(g, center, mostLikelyAngle(), radius*1.5, Color.green, radius/3f);
45  
  }
46  
  
47  
  void clearCache {
48  
    sensors = null;
49  
  }
50  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt

No comments. add comment

Snippet ID: #1030553
Snippet name: OCRCompass - detects orientation of a line at a point in integral image
Eternal ID of this version: #1030553/20
Text MD5: 250f97dbdca549e9492cc97ab533bc35
Author: stefan
Category: javax / ocr
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-01-10 14:45:01
Source code size: 1763 bytes / 50 lines
Pitched / IR pitched: No / No
Views / Downloads: 278 / 560
Version history: 19 change(s)
Referenced in: [show references]