I write on ABAP, but now I have a personal problem in JS, I stumble over the syntax.
There is a photo taken from the camera:
startbutton.addEventListener('click', function(ev){
takepicture();
ev.preventDefault();
}, false);
clearphoto();
}
function clearphoto() {
var context = canvas.getContext('2d');
context.fillStyle = "#AAA";
context.fillRect(0, 0, canvas.width, canvas.height);
var data = canvas.toDataURL('image/png');
photo.setAttribute('src', data);
}
function takepicture() {
var context = canvas.getContext('2d');
if (width && height) {
canvas.width = width;
canvas.height = height;
context.drawImage(video, 0, 0, width, height);
var data = canvas.toDataURL('image/png');
photo.setAttribute('src', data);
} else {
clearphoto();
}
}
and there is also further processing of the photo, but the script was written through file upload. That is, in the script, I need to assign the value of the photo to the value of the file (to avoid loading the user, instead <input type="file" id="file"/>
).
Subsequent work with the file:
function recognize(file, lang, logger) {
return Tesseract.recognize(file, lang, { logger }).
then(({ data: { text } }) => {
return text;
});
}
const log = document.getElementById('log');
function updateProgress(data) {
log.innerHTML = '';
const statusText = document.createTextNode(data.status);
const progress = document.createElement('progress');
progress.max = 1;
progress.value = data.progress;
log.appendChild(statusText);
log.appendChild(progress);
}
function setResult(text) {
log.innerHTML = '';
text = text.replace(/
s*
/g, '
');
const pre = document.createElement('pre');
pre.innerHTML = text;
log.appendChild(pre);
}
document.getElementById('start').addEventListener('click', () => {
const file = document.getElementById('file').files[0];
if (!file) return;
const lang = document.getElementById('langs').value;
recognize(file, lang, updateProgress).
then(setResult);
});
Please tell me how to do it correctly?
question from:
https://stackoverflow.com/questions/65862045/value-input-file-equalize-photos 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…