Transpiled version (6927L) is out of date.
// call clearCache when changing parameters sclass OCRCompass implements Renderable { // compass can look for dark or bright lines, set this flag accordingly: bool brightForeground; IBWIntegralImage image; Pt center; // point we're looking at double radius = 16; // radius of circle int sensorFootprint = 0; // size of each "pixel" (rectangle) to grab - defaults to radius int steps = 12; // how many segments of circle (=steps/2 line orientations). should be even int blur; // blur width double[] values; // brightnesses at each point (low=foreground) L<Rect> sensors; L<Rect> sensors() { if (sensors == null) sensors = squaresAroundCircle(center, steps, radius, sensorFootprint()); ret sensors; } int angles() { ret steps/2; } int sensorFootprint() { ret sensorFootprint == 0 ? iceil(radius*12/max(steps, 12)) : sensorFootprint; } void compute { L<Rect> sensors = sensors(); if (l(values) != angles()) values = new double[angles()]; for i over values: values[i] = avg( image.getPixelAverage(sensors.get(i)), image.getPixelAverage(sensors.get(i+angles()))); } void ensureComputed { if (values == null) compute(); } double mostLikelyAngle() { ensureComputed(); ret indexOfMinOrMaxEntryInDoubleArray(brightForeground, values)*twoPi()/steps; } public void renderOn(Graphics2D g, int w, int h) { ensureComputed(); renderRenderables(g, w, h, zipAndMap(sensors(), repeatList(2, asList(values)), (r, value) -> BoxWithColor(r, 0, 0, iround(value)))); drawRotatedRoundEdgeLine(g, center, mostLikelyAngle(), radius*1.5, Color.green, radius/3f); } void clearCache { sensors = null; } }
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: | 276 / 557 |
Version history: | 19 change(s) |
Referenced in: | [show references] |