Reputation: 529
I want to use tesseract.js library to recognize a string like ("رقم العداد") and alert the number that is written after the string like (7038842 رقم العداد) << as you see i want to alert the number after the string from a png picture and copy another number from the picture ("نقطة الخدمة") this is what i have tried and it works fine if the [ text.match ] string was [القراءة] but if i change it to ("رقم العداد") or ("نقطة الخدمة") no alert pops up and gives me this error on console
Uncaught (in promise) TypeError: Cannot read properties of null (reading '1') at (index):25:63
code :-
Tesseract.recognize(
'Uff.png',
'ara',
{ logger: m => console.log(m) }
).then(({ data: { text } }) => {
var number = 'رقم العداد'; or /*'نقطة الخدمة'*/
var result = text.match(new RegExp(number + '\\s+(\\w+)'))[1];
alert(result);
})
</script>
Upvotes: 1
Views: 1262
Reputation: 969
After some testing and observation for the same problem on Jsfiddle. It is the place where I can say that your problem is with the detected text where the tesseract fails to detect some Arabic letters as they are.
In order to solve this, you have to make sure from the strings output and use the same string to get your numbers.
For instance, in the example above I intended to get the number after matching the string
معرف العقار but tesseract does not give the same string. Rather, it gives محر العفار so in such a case you have to filter with respect to this and not the correct text.
var number = 'محر العفار';
var res = text.match(new RegExp(number + '\\s+(\\w+)'))[1];
This is the picture on the web that I am testing image
Upvotes: 1