src: wrap operations on grid in case its null
This commit is contained in:
parent
638594aab4
commit
67da4b217c
@ -157,8 +157,8 @@ export default class Recognizer extends React.Component<IRecognizerProps, IRecog
|
|||||||
coordinates: [],
|
coordinates: [],
|
||||||
});
|
});
|
||||||
|
|
||||||
console.debug(this.state.cells);
|
console.log(this.state.cells);
|
||||||
console.debug(solutions);
|
console.log(solutions);
|
||||||
|
|
||||||
this.props.onRecognitionFinished({
|
this.props.onRecognitionFinished({
|
||||||
...this.state,
|
...this.state,
|
||||||
|
@ -201,10 +201,17 @@ export function findTextRegions(image, maxWhiteSpace, maxFontLineWidth, minTextW
|
|||||||
let s = foundSegments[segmentOffset + i];
|
let s = foundSegments[segmentOffset + i];
|
||||||
let croppedData = ctx.getImageData(s.x, s.y, s.w, s.h);
|
let croppedData = ctx.getImageData(s.x, s.y, s.w, s.h);
|
||||||
let croppedCanvas = document.createElement('canvas');
|
let croppedCanvas = document.createElement('canvas');
|
||||||
|
let croppedContext = croppedCanvas.getContext('2d');
|
||||||
croppedCanvas.width = s.w;
|
croppedCanvas.width = s.w;
|
||||||
croppedCanvas.height = s.h;
|
croppedCanvas.height = s.h;
|
||||||
croppedCanvas.getContext('2d')?.putImageData(croppedData, 0, 0);
|
|
||||||
grid[j][indexMap[s.x]] = {data: croppedData, canvas: croppedCanvas, ...s}
|
if (!croppedContext) {
|
||||||
|
croppedData = croppedCanvas = null;
|
||||||
|
} else {
|
||||||
|
croppedContext.putImageData(croppedData, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
grid[j][indexMap[s.x]] = {data: croppedData, canvas: croppedCanvas, ...s};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +38,11 @@ export async function recognizeTextOnImageGrid(grid: any[][]): Promise<any[][]>
|
|||||||
// no parallelization for now, we can always Promise it all() later
|
// no parallelization for now, we can always Promise it all() later
|
||||||
for (let line of grid) {
|
for (let line of grid) {
|
||||||
for (let g of line) {
|
for (let g of line) {
|
||||||
|
if (g.canvas) {
|
||||||
g.text = await recognize(CHAR_WORKER, g.canvas);
|
g.text = await recognize(CHAR_WORKER, g.canvas);
|
||||||
|
} else {
|
||||||
|
g.text = '?';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user