Skip to content

Commit

Permalink
feat(core): update correction map
Browse files Browse the repository at this point in the history
Updated correction map for better recognition when running 
Cyberpunk 2077 with language that uses custom font.

Correction map is now exposed on `BreachProtocolOCRFragment`.

fixes #54
  • Loading branch information
marcincichocki authored Jun 15, 2021
1 parent 4403944 commit b7645ec
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 7 deletions.
Binary file added src/bp-registry/1024x768/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions src/bp-registry/registry.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
{
"1024x768": [
{
"fileName": "1.png",
"daemons": [
["7A", "55", "7A"],
["7A", "1C"]
],
"grid": [
"7A", "55", "1C", "E9", "E9", "7A", "7A",
"FF", "1C", "7A", "1C", "7A", "E9", "7A",
"7A", "FF", "7A", "7A", "55", "1C", "1C",
"E9", "1C", "55", "55", "55", "BD", "7A",
"1C", "55", "E9", "55", "55", "E9", "1C",
"55", "FF", "1C", "7A", "55", "BD", "1C",
"1C", "7A", "55", "7A", "7A", "FF", "55"
],
"bufferSize": 9
}
],
"1920x1080": [
{
"fileName": "1.png",
Expand Down
10 changes: 7 additions & 3 deletions src/core/ocr/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,14 @@ export abstract class BreachProtocolOCRFragment<
> extends BreachProtocolFragment<TData, TImage, TId> {
// Tesseract may report mixed symbols on smaller resolutions.
// This map contains some common errors.
protected readonly correctionMap = new Map<string, HexNumber>([
public static readonly correctionMap = new Map<string, HexNumber>([
['1E', '1C'],
['EE', '1C'],
['DE', '1C'],
['AC', '1C'],
['EB', 'E9'],
['F9', 'E9'],
['57', 'E9'],
['ED', 'BD'],
]);

Expand Down Expand Up @@ -211,8 +215,8 @@ export abstract class BreachProtocolOCRFragment<
}

protected amendSymbol(symbol: string) {
if (this.correctionMap.has(symbol)) {
return this.correctionMap.get(symbol);
if (BreachProtocolOCRFragment.correctionMap.has(symbol)) {
return BreachProtocolOCRFragment.correctionMap.get(symbol);
}

return symbol as HexNumber;
Expand Down
31 changes: 27 additions & 4 deletions src/core/ocr/ocr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ interface RegistryEntry {
bufferSize: BufferSize;
}

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

describe('image container', () => {
Expand Down Expand Up @@ -180,6 +185,14 @@ describe('ocr', () => {
await BreachProtocolOCRFragment.terminateScheduler();
});

it.each(getRegistryFor('1024x768'))(
'should correctly ocr 1024x768/%s',
async (f: string, entry: RegistryEntry) => {
// This resolution requires fixed thresholds.
await compareOcrToJson(entry, '1024x768', { grid: 155, daemons: 140 });
}
);

it.each(getRegistryFor('1920x1080'))(
'should correctly ocr 1920x1080/%s',
async (f: string, entry: RegistryEntry) => {
Expand Down Expand Up @@ -210,11 +223,21 @@ describe('ocr', () => {
});

function getRegistryFor(resolution: Resolution) {
return (registry as Registry)[resolution].map((e) => [e.fileName, e]);
return (registry as Registry)[resolution].map(
(e) => [e.fileName, e] as [string, RegistryEntry]
);
}

async function compareOcrToJson(entry: RegistryEntry, resolution: Resolution) {
const [ocr, trim] = await recognizeRegistryEntry(entry, resolution);
async function compareOcrToJson(
entry: RegistryEntry,
resolution: Resolution,
thresholds?: Partial<Record<FragmentId, number>>
) {
const [ocr, trim] = await recognizeRegistryEntry(
entry,
resolution,
thresholds
);

expect(ocr.rawData.grid).toEqual(entry.grid);
expect(ocr.rawData.daemons).toEqual(entry.daemons);
Expand Down

0 comments on commit b7645ec

Please sign in to comment.