easyocr script?

frostieff

New Member
May 12, 2021
21
3
3
Does anyone have an easyocr script? The tutorial posted on here is outdated and im not really good with python.
 
An easyOCR script to do what exactly?

If you look at the github page and read the usage section of the readme: https://github.com/JaidedAI/EasyOCR

This is all you need to do to ocr 1 image:
Code:
import easyocr
reader = easyocr.Reader(['ch_sim','en']) # this needs to run only once to load the model into memory
result = reader.readtext('chinese.jpg')

If you're talking about this tutorial: https://www.akiba-online.com/thread...-english-movies-hardsub.2005149/#post-4272870
Then it uses more than just easyOCR, it also makes use of videosubfinder to grab an image of each subtitle lines in a video and the guy wrote a custom script to make use of both automatically.

That custom script has
Code:
import easyocr
    reader = easyocr.Reader( args.langs.replace(" ","").split(",") )
which loads the parameter you specify in the command to run that script which is "ch_tra" in his example so looks right for the first 2 lines of easyOCR usage.

Next you have
Code:
result = reader.readtext(fileImage,detail=0, paragraph=True)
a little later inside a loop that goes through all the images created by videosubfinder.

fileImage seems to contain the current file the loop found from what I can understand so that matches with the only parameter easyOCR needs.

For the extra 2, if you look at the api doc for easyOCR, you can see "detail (int, default = 1) - Set this to 0 for simple output" and "paragraph (bool, default = False) - Combine result into paragraph" so those are both valid options.


So, if you mean to say that the custom script from the guy who wrote the tutorial I linked isn't working for you, you're going to have to give more details as to what error message you're getting and what version of softwares you're using since everything seems fine with the easyOCR section on that one.
 
Thank you for your time. Im using Sublime Text to run the code. Installed all the modules.

This is the error code I'm getting:

C:\Users\user\AppData\Local\Programs\Python\Python39\python.exe: can't find '__main__' module in ''
[Finished in 800ms with exit code 1]
[cmd: ['py', '-u', '']]
[dir: C:\Program Files\Sublime Text]
[path: C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Users\user\AppData\Local\Programs\Python\Python39\Scripts\;C:\Users\user\AppData\Local\Programs\Python\Python39\;C:\Users\user\AppData\Local\Microsoft\WindowsApps;]
 
To run what code?

From that error message, sounds like you're not providing a file to it, you've got '' which is empty:
Code:
can't find '__main__' module in ''
 'py', '-u', ''
 
So for example the picture i want it to translate is chinese.jpg. This file is stored on C:\Users\user\Downloads

What is the full code/script would i put into sublime text?
 
I don't really know python but my educated guess would be something like this at its most basic form:
Code:
import easyocr
def main():
reader = easyocr.Reader(['ch_sim']) # this needs to run only once to load the model into memory
result = reader.readtext('C:\Users\user\Downloads\chinese.jpg')
And to write the result in a text file I assume you should add the following 2 lines after that, stolen from the tutorial script since I don't know python much
Code:
with open("C:\Users\user\Downloads\Result.txt", "w", encoding="utf-8") as f:
            f.write( " ".join(result) )

You might want to put the path in a variable like the tutorial guy did though instead of hardcoding it everywhere in the script.

And might need
Code:
if __name__ == "__main__":
    main()
at the end
 
Can you put a copy of your script here and the command you use to call it?
 
I saved a picture inside the python folder and named it 'pic1.png'

And i was able to successfully translate it :D

So i guess i gotta save all the subtitle pics from VideoSubFinder into pythn folder?
 
Or point the script to the videosubfinder folder instead, it should work if you use the full path and not just the filename, python should have read access to pretty much anywhere on your pc.

Hard to say without knowing what the script looks like.