src: load uploaded image
This commit is contained in:
parent
5dafe543a4
commit
c00532ce74
@ -43,17 +43,21 @@ 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);
|
const {grid, gridWidth, gridHeight} = findTextRegions(image);
|
||||||
console.log(grid, gridWidth, gridHeight);
|
console.log(grid, gridWidth, gridHeight);
|
||||||
|
|
||||||
|
image.src = "";
|
||||||
|
URL.revokeObjectURL(url);
|
||||||
|
|
||||||
if (!grid) {
|
if (!grid) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
debugger;
|
|
||||||
|
|
||||||
let g = grid[0][0];
|
let g = grid[0][0];
|
||||||
let ot = document.createElement('canvas');
|
let ot = document.createElement('canvas');
|
||||||
ot.width = g.w;
|
ot.width = g.w;
|
||||||
@ -61,6 +65,7 @@ export default class App extends React.Component {
|
|||||||
ot.getContext('2d')?.putImageData(g.data, 0, 0);
|
ot.getContext('2d')?.putImageData(g.data, 0, 0);
|
||||||
document.body.appendChild(ot);
|
document.body.appendChild(ot);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
renderAnswers(): Array<JSX.Element> {
|
renderAnswers(): Array<JSX.Element> {
|
||||||
return this.game.solutions.map(s => s.key).map(k =>
|
return this.game.solutions.map(s => s.key).map(k =>
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user