Skip to content

Commit

Permalink
fix: use cropped width in buffer size fragment
Browse files Browse the repository at this point in the history
  • Loading branch information
marcincichocki authored Apr 23, 2021
1 parent 3871deb commit 1688437
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 8 deletions.
Binary file added src/bp-registry/3440x1440/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions src/bp-registry/registry.json
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,27 @@
"bufferSize": 7
}
],
"3440x1440": [
{
"fileName": "1.png",
"daemons": [
["BD", "BD"],
["1C", "1C"],
["1C", "FF"],
["FF", "1C"]
],
"grid": [
"FF", "7A", "55", "FF", "55", "7A", "FF",
"7A", "1C", "1C", "E9", "1C", "BD", "1C",
"7A", "55", "1C", "1C", "E9", "1C", "7A",
"7A", "55", "7A", "E9", "BD", "BD", "BD",
"55", "1C", "FF", "E9", "1C", "1C", "FF",
"7A", "1C", "1C", "7A", "E9", "1C", "1C",
"FF", "7A", "E9", "1C", "55", "1C", "1C"
],
"bufferSize": 8
}
],
"3840x2160": [
{
"fileName": "1.png",
Expand Down
9 changes: 6 additions & 3 deletions src/core/ocr/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export interface BreachProtocolFragmentBoundingBox {
top: number;
outerWidth: number;
outerHeight: number;
innerWidth: number;
innerHeight: number;
}

export class BreachProtocolFragmentResult<D, S, C> {
Expand Down Expand Up @@ -58,14 +60,15 @@ export abstract class BreachProtocolFragment<D, S, C> {
const { p1, p2 } = this;
const { width, height, left, top } = this.container.getCroppedBoundingBox();

// NOTE: this does not return cropped with and height!
return {
left: left + Math.round(p1.x * width),
top: top + Math.round(p1.y * height),
width: Math.round((p2.x - p1.x) * width),
height: Math.round((p2.y - p1.y) * height),
outerWidth: width + 2 * left,
outerHeight: height + 2 * top,
innerWidth: width,
innerHeight: height,
} as BreachProtocolFragmentBoundingBox;
}
}
Expand Down Expand Up @@ -176,9 +179,9 @@ export abstract class BreachProtocolOCRFragment<

/** Get closest treshold value for given resolution. */
protected getThreshold() {
const { height } = this.container.getCroppedBoundingBox();
const { innerHeight } = this.boundingBox;
const list = [...this.thresholds.keys()];
const value = getClosest(height, list);
const value = getClosest(innerHeight, list);

return this.thresholds.get(value);
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/ocr/buffer-size-trim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ export class BreachProtocolBufferSizeTrimFragment<
}

private async getBufferSizeFromPixels(width: number) {
const { outerWidth } = this.boundingBox;
const { innerWidth } = this.boundingBox;

let size = width / outerWidth;
let size = width / innerWidth;
let bufferSize = 0;

size -= 2 * this.padding;
Expand Down
4 changes: 2 additions & 2 deletions src/core/ocr/buffer-size.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ export class BreachProtocolBufferSizeFragment<C> extends BreachProtocolFragment<
}

private getBufferSizeFromPixels(pixels: Buffer) {
const { width, outerWidth } = this.boundingBox;
let size = this.getSizeOfBufferBox(pixels, width) / outerWidth;
const { width, innerWidth } = this.boundingBox;
let size = this.getSizeOfBufferBox(pixels, width) / innerWidth;
let bufferSize = 0;

size -= 2 * this.padding;
Expand Down
9 changes: 8 additions & 1 deletion src/core/ocr/ocr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interface RegistryEntry {
bufferSize: BufferSize;
}

type Resolution = '1920x1080' | '2560x1440' | '3840x2160';
type Resolution = '1920x1080' | '2560x1440' | '3440x1440' | '3840x2160';
type Registry = Record<Resolution, RegistryEntry[]>;

describe('image container', () => {
Expand Down Expand Up @@ -188,6 +188,13 @@ describe('ocr', () => {
}
);

it.each(getRegistryFor('3440x1440'))(
'should correctly ocr 3440x1440/%s',
async (f: string, entry: RegistryEntry) => {
await compareOcrToJson(entry, '3440x1440');
}
);

it.each(getRegistryFor('3840x2160'))(
'should correctly ocr 3840x2160/%s',
async (f: string, entry: RegistryEntry) => {
Expand Down

0 comments on commit 1688437

Please sign in to comment.