src: load uploaded image

This commit is contained in:
Artur Tamborski 2021-01-17 14:02:59 +01:00
parent 5dafe543a4
commit c00532ce74
2 changed files with 20 additions and 15 deletions

View File

@ -43,23 +43,28 @@ export default class App extends React.Component {
handleTakePhoto(pictures: any[], _: any[]): void { handleTakePhoto(pictures: any[], _: any[]): void {
console.log("handleTakePhoto: loading image...") console.log("handleTakePhoto: loading image...")
const image = pictures[0]; const url = URL.createObjectURL(pictures[0]);
const image = document.createElement('img');
image.src = url;
image.onload = () => {
console.log("handleTakePhoto: finding text regions...")
const {grid, gridWidth, gridHeight} = findTextRegions(image);
console.log(grid, gridWidth, gridHeight);
const {grid, gridWidth, gridHeight} = findTextRegions(image); image.src = "";
console.log(grid, gridWidth, gridHeight); URL.revokeObjectURL(url);
if (!grid) { if (!grid) {
return; return;
}
let g = grid[0][0];
let ot = document.createElement('canvas');
ot.width = g.w;
ot.height = g.h;
ot.getContext('2d')?.putImageData(g.data, 0, 0);
document.body.appendChild(ot);
} }
debugger;
let g = grid[0][0];
let ot = document.createElement('canvas');
ot.width = g.w;
ot.height = g.h;
ot.getContext('2d')?.putImageData(g.data, 0, 0);
document.body.appendChild(ot);
} }
renderAnswers(): Array<JSX.Element> { renderAnswers(): Array<JSX.Element> {

View File

@ -179,7 +179,7 @@ export function findTextRegions(image, maxWhiteSpace, maxFontLineWidth, minTextW
// hopefully we matched every letter in the grid // hopefully we matched every letter in the grid
if (gridWidth * gridHeight !== segments.length) { if (gridWidth * gridHeight !== segments.length) {
console.warning("findTextRegions(): Dimensions are not equal to the number of matches"); console.warn("findTextRegions(): Dimensions are not equal to the number of matches");
} }
// prepare grid for letters // prepare grid for letters