-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Description
Tesseract.js version (version number for npm/GitHub release, or specific commit for repo)
https://cdn.jsdelivr.net/npm/tesseract.js@5/dist/tesseract.min.js
Describe the bug
When uploading pictures that are either rotated to the left, right og upside down, TesseractJS successfully reports 90, 180 or 270 degrees in most cases. But when reading the text, it only writes "rubbish" like this:
1a1e1014321psåuniuep) ) av 1uaDrpodå 12 134e1hu10.] HLISJAPuf 'NYN NNN NNN 21095 2pusv$oopLs UejEpundg 00'20'0€ (...)
The same image uploaded with correct rotation gives this output, which is great:
FOR VIDEREGÅENDE OPPLÆRING Navn: — Wilhelm Khalid Tjemsland Sletvold Fødselsnummer : 21126423464 har gjennomført opplæring som omfatter i utdanningsprogram for MEMOK ]1---- Medjer og konunuqikasjon, lår Studiespesialisering bestått MEMOK2---- — Medier og kommunikasjon, 2. år Studiespesialisering bestått MEMOK3---- — Medier og kommunikasjon, 3. år Studiespesialisering fullført (...)
To Reproduce
Save the following code in a .html file, and load it in the browser. Upload the image below.
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/tesseract.js@5/dist/tesseract.min.js"></script>
</head>
<body>
<input type="file" id="uploader" multiple />
<script type="module">
const worker = await Tesseract.createWorker("nor", 2, {
legacyCore: true,
legacyLang: true,
});
worker.setParameters({ tessedit_pageseg_mode: "3" });
const recognize = async function (evt) {
const files = evt.target.files;
for (let i = 0; i < files.length; i++) {
const ret = await worker.recognize(
files[i],
{ rotateAuto: true },
{ osd: true }
);
const osdAngle =
parseFloat(
ret.data.osd.match(/Orientation in degrees: (\d+)/)?.[1]
) || 0;
const autoRotateAngle = ret.data.rotateRadians * (180 / Math.PI) * -1;
const totalAngle = osdAngle + autoRotateAngle;
console.log("osdAngle: " + osdAngle + " (degrees)");
console.log("autoRotateAngle: " + autoRotateAngle + " (degrees)");
console.log("totalAngle: " + totalAngle + " (degrees)");
console.log(ret.data.text);
}
};
const elm = document.getElementById("uploader");
elm.addEventListener("change", recognize);
</script>
</body>
</html>
Expected behavior
Uploading the image gives this:
osdAngle: 270 (degrees)
autoRotateAngle: 0 (degrees)
totalAngle: 270 (degrees)
Which is the correct angle. But should TesseractJS be able to turn the image to 0 degrees and then perform OCR and get a more correct output?
Device Version:
- macOS 14.5
- Google Chrome
