Tutorial OCR Chinese(english) movies hardsub

Was this tutorial helpful?


  • Total voters
    15
Sep 21, 2016
24
35

Optical Character Recognition (OCR) for natural images/scenes​

RBD-186-C_001_4655.jpg
他也不是故意要那么做的

Another option to recognize text from images, it can recognize directly from natural images, and it recognizes better than tesseract


Requirements:​

Windows 10 64 bits
3 GB hard disk
8 GB RAM
Internet connection, to download the required languages only once

Software​

Python

Pytorch

EasyOCR (IA)

videosubfinder




Installation​


Download and Install Python 3.9.4 in C:\python39
python-3.9.4

Run PIP for Python
Open line command win+R and "cmd"
Bash:
C:\Python29\Scripts\pip.exe install easyocr


There are two options, if you have the Nvidia video card run step a), if you have only AMD/intel video card run step b)
a) Only for video cards CUDA/NVIDIA 11.1
Bash:
C:\Python29\Scripts\pip3.exe install torch==1.8.1+cu111 torchvision==0.9.1+cu111 torchaudio===0.8.1 -f https://download.pytorch.org/whl/torch_stable.html
b) FOR CPU (not video cards CUDA/NVIDIA)
Code:
C:\Python29\Scripts\pip3.exe install torch==1.8.1+cpu torchvision==0.9.1+cpu torchaudio===0.8.1 -f https://download.pytorch.org/whl/torch_stable.html


Download and install in C:\VideoSubFinder5x64 (rename of release_x64)
VideoSubfinder 5.5
For working of this program will be required "Microsoft Visual C++ Redistributable for Visual Studio 2015, 2017 and 2019"



Usage​

Run VideoSubFinderWXW.exe
Open video and ajust area video(optional, but fast)
Press Button "Run Search"
videosubfinder.jpg
Optional.- Manually delete images (explorer windows) that do not have text in folder C:\VideoSubFinder5x64\RGBImages

Run script ( Download )
Bash:
C:\Python29\python.exe easyOcrImage.py
or
Code:
easyOcrImage.py -l ch_tra -d "c:\youDirectoyImages"

At the end of the script, the text files(OCR) are generated in the folder TXTResults
And now just
Press the button "Create Sub From TXTResults" (save subtitle srt)

videosubfinder_createEmpty.jpg

Python:
directoryDefault=r'C:\VideoSubFinder5x64\RGBImages'
extensions=[".jpg",".png",".jpeg",".bmp"]
languagesDefault="ch_tra"
import os
import argparse
def main():
    parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter,description=r"easyOcrImage.py -l en,ch_tra -d " + directoryDefault,epilog=codeLanguages)
    parser.add_argument('-l','--langs',dest="langs",default=languagesDefault,help="Separated by (,) \"en,ch_tra\" for mix langs english & Traditional Chinese")
    parser.add_argument('-d','--directory',dest="directory", default=directoryDefault,help='directory help')
    args = parser.parse_args()
    if not os.path.isdir(args.directory):
        print ("Not exists directory: " + args.directory )
        return
    parentDirectory = os.path.dirname(args.directory)
    directoryTXTResults = os.path.join(parentDirectory, "TXTResults")
    if os.path.isdir( directoryTXTResults ):
        directoryTxt=directoryTXTResults
    else:
        directoryTxt=args.directory
    os.system("title OCR for " + args.directory + " - " + args.langs)
    import easyocr
    reader = easyocr.Reader( args.langs.replace(" ","").split(",") )

    files = [x for x in os.listdir(args.directory) if os.path.splitext(x)[1] in extensions]
    for i,x in enumerate(files):
        os.system("title OCR {}/{} Processed".format(i,len(files)) )
        fileImage = os.path.join(args.directory,x)
        fileTxt = os.path.join(directoryTxt,x)
        result = reader.readtext(fileImage,detail=0, paragraph=True)
        with open(fileTxt+".txt", "w", encoding="utf-8") as f:
            f.write( " ".join(result) )

codeLanguages="""Languages
Code Name
--- ----
abq    Abaza
ady    Adyghe
af    Afrikaans
ang    Angika
ar    Arabic
as    Assamese
ava    Avar
az    Azerbaijani
be    Belarusian
bg    Bulgarian
bh    Bihari
bho    Bhojpuri
bn    Bengali
bs    Bosnian
ch_sim    Simplified Chinese
ch_tra    Traditional Chinese
che    Chechen
cs    Czech
cy    Welsh
da    Danish
dar    Dargwa
de    German
en    English
es    Spanish
et    Estonian
fa    Persian (Farsi)
fr    French
ga    Irish
gom    Goan Konkani
hi    Hindi
hr    Croatian
hu    Hungarian
id    Indonesian
inh    Ingush
is    Icelandic
it    Italian
ja    Japanese
kbd    Kabardian
kn    Kannada
ko    Korean
ku    Kurdish
la    Latin
lbe    Lak
lez    Lezghian
lt    Lithuanian
lv    Latvian
mah    Magahi
mai    Maithili
mi    Maori
mn    Mongolian
mr    Marathi
ms    Malay
mt    Maltese
ne    Nepali
new    Newari
nl    Dutch
no    Norwegian
oc    Occitan
pl    Polish
pt    Portuguese
ro    Romanian
ru    Russian
rs_cyrillic    Serbian (cyrillic)
rs_latin    Serbian (latin)
sck    Nagpuri
sk    Slovak (need revisit)
sl    Slovenian
sq    Albanian
sv    Swedish
sw    Swahili
ta    Tamil
tab    Tabassaran
te    Telugu
th    Thai
tl    Tagalog
tr    Turkish
ug    Uyghur
uk    Ukranian
ur    Urdu
uz    Uzbek
vi    Vietnamese (need revisit)"""
if __name__ == "__main__":
    main()


Reminder, Download link 28,000+ Subtitle pack! (2001-2021)
https://www.akiba-online.com/thread...not-a-sub-request-thread.1920331/post-4193115
 

Attachments

  • easyOcrImage.zip
    14.4 KB · Views: 712
Last edited:

frostieff

New Member
May 12, 2021
21
3
thank you soo much for taking the time to create this tutorial however im new to python and im facing issues when im trying to run the bash or the script.

C:\Python39\python.exe: can't open file 'C:\Users\easyOcrImage.py': [Errno 2] No such file or directory

I have downloaded the latest python, pip and easyocr have been installed when i used C:\Python39\Scripts\pip.exe install easyocr

Any help will be much appreciated.
 
Last edited:

ironfevers

Active Member
Nov 9, 2019
37
157
Nice guide. Do you have a recommended image viewer to delete blanks? It's kinda tedious to manually delete blanks. I was thinking you can click Create TXTImages which automatically detects blanks. Then you can run a script to compare to see if the RGBImage filename is in the same list as TXTImages, if they're the same then keep the image. If not in the list, then move it to a BlankImages folder to manually double check.
 
Sep 21, 2016
24
35
thank you soo much for taking the time to create this tutorial however im new to python and im facing issues when im trying to run the bash or the script.

C:\Python39\python.exe: can't open file 'C:\Users\fadyf\easyOcrImage.py': [Errno 2] No such file or directory

I have downloaded the latest python, pip and easyocr have been installed when i used C:\Python39\Scripts\pip.exe install easyocr

Any help will be much appreciated.
you can put screenshots of your command line
 
Sep 21, 2016
24
35
Nice guide. Do you have a recommended image viewer to delete blanks? It's kinda tedious to manually delete blanks. I was thinking you can click Create TXTImages which automatically detects blanks. Then you can run a script to compare to see if the RGBImage filename is in the same list as TXTImages, if they're the same then keep the image. If not in the list, then move it to a BlankImages folder to manually double check.
The old photo viewer is very good at removing images (fast). It is only a matter of activating it in windows 10 through the registry
https://www.howtogeek.com/225844/ho...ewer-your-default-image-viewer-on-windows-10/

And the other is to eliminate the subtitle lines, I use aegisub, it is very fast to eliminate and make corrections
 

mei2

Well-Known Member
Dec 6, 2018
246
406
Nice tutorial. Thanks for the good job!
Are Chinese subtitles (say in Sukebei) in simplified or traditional Chinese mostly?
 

Taako

Akiba Citizen
May 25, 2017
1,335
940
I guess you have to be familiar with Python?
The steps should be clearer if you run into an issue.
It's possible also that it's need updating. Those are my only issue with this. Meanwhile, I'm still making subs regardless.
Also remember guys, just because it didn't work for me... doesn't mean it won't work :p
 
Last edited:

maload

Active Member
Jul 1, 2008
697
145
hmm. red text mean its no good
 

Attachments

  • 888888888888888888888888888.jpg
    888888888888888888888888888.jpg
    50.2 KB · Views: 242

frostieff

New Member
May 12, 2021
21
3
Have no idea, bro. Personally gave up on it. The instructions for noobs who don't know python makes it difficult to learn.
I suppose the original creator had good intentions but it hasn't help increased subs. I think only a select few can run it :confused:
The... tech support might be able to help you :) Good luck https://www.akiba-online.com/forums/tech-support.88/
Reddit (python for new comers) or StackExhcange is where we will have to go and ask
 
  • Like
Reactions: Taako

faebladezzz

New Member
Dec 16, 2012
10
3
is it just me or the total run time of the original JAV vs JAV that have chinese hardsub was different?
for example case for SPRD-1454 the original run time is 01:56:10 but the chinese hardsub version run time is 01:55:42.

i've try this method to extact the subtitle just now, but there is some problem here. If we use the sub (that we extract) with the chinese hardsub version video the timing was great, but when i use it at the original version the subtitle timing always miss -1 (increase every 3 minutes)

are they decreasing the frame rate of the video for the chinese hardsub version ?
is there's a way to fix it ?

Thank you in advance
 

SamKook

Grand Wizard
Staff member
Super Moderator
Uploader
May 10, 2009
3,755
5,154
Subtitles use time to sync themselves to the video so even if the framerate was different, it wouldn't matter and still work.

With that said, it could be an issue during encoding if the encoder duplicated frames during encoding or stuff like that. The time difference could also be that the video is cut in a different way, like removing end credits or ads, stuff like that.

Can't say much more than that without more details.
 

whiteknightlulw

New Member
Dec 19, 2020
2
0
I noticed that recent chinese hardsub release have the sub appear in a scrolling manner moving from left to right making the detection kinda inaccurate. It also has different colored text that seems to also affect its accuracy. Any workarounds for this?
 

mei2

Well-Known Member
Dec 6, 2018
246
406
For those who are interested to tackle Rainbow+Karaoke hardsubs, here is my VSF settings that works reasonably well [the key word being reasonably ;) ]::

Sub detection (RGBImages):
- I have added ca 10 colour filters --it should work well with the current set of colours used;​
- I have adjusted the frame rate and text timing to manage the current karaoke/typewriter speed;​
- It uses gpu flag for nvidia. If you don't need it, juts deselect it in the settings menu;​
- The good: I have tested it on 5 new releases. The sub detection generated about 90% of hardsubs right;​
- The bad: the timing is not accurate --because I had to play with the frame rate timing to get the entire moving subs. In general ech sub line needs to be adjusted to start earlier about 100ms per character.​
- The ugly: cleaning up RGBImages is still a pain / manual. Though this version of cfg has produced least amount of garbage for me;​
Image OCR (TextImages):
- Using VSF inbuilt OCR has not produced the best results for me --about 80%;​
- VSF specially fails when white background​
- I have had the best results with Google Docs. But too manual so far for me. If someone has a good OCR solution, please let me know.​
- PaddleOCR has been rather good too, but I don't have a good script for it yet --I tested the toolbox so far.​
A big thank you to @MrKid to push me to get it done. Hope the others can share your settings and workarounds so we can speed up the (soft)sub production.
 

Attachments

  • VSF_Rainbow+Karaoke_MZ_V5_wcuda.zip
    1.3 KB · Views: 197

superman4207

JAV Perv Enthusiast
Jul 4, 2022
49
88
I think the problem people are running into with following these instructions is because the OP forgets to mention to download his custom script that he attached to his post: "easyOcrImage.zip." as a STEP.

Follow his instructions until after you've used VideoSubFinder to extract the images of the text.
- Then download his file and unzip to your C: drive (this is just easier, trust me).
- Open cmd.exe.
- Type
Code:
/cd
(if you need to) and press Enter. Just make sure you're at the C; drive.
Code:
C:\>
- Copy and paste his command, updating the directory to match whatever yours is actually called:
Code:
C:\>easyOcrImage.py -l ch_tra -d "c:\VideoSubFinder\RGBImages\"

And it will start to OCR scan your files that were extracted. With his instructions and script, you don't need to locate the directory of anything except for where your RGBImages are.

Important Note: If you are using VideoSubFinder's Create Cleared Text Images (RGBImages->TXTImages) feature, make sure to change the path to point easyOCR to the TXTImages directory instead.
Code:
C:\>easyOcrImage.py -l ch_tra -d "c:\VideoSubFinder\TXTImages\"
 
Last edited:
  • Like
Reactions: Taako

hobbies

New Member
Apr 3, 2023
22
2
I think the problem people are running into with following these instructions is because the OP forgets to mention to download his custom script that he attached to his post: "easyOcrImage.zip." as a STEP.

Follow his instructions until after you've used VideoSubFinder to extract the images of the text.
- Then download his file and unzip to your C: drive (this is just easier, trust me).
- Open cmd.exe.
- Type
Code:
/cd
(if you need to) and press Enter. Just make sure you're at the C; drive.
Code:
C:\>
- Copy and paste his command, updating the directory to match whatever yours is actually called:
Code:
C:\>easyOcrImage.py -l ch_tra -d "c:\VideoSubFinder\RGBImages\"

And it will start to OCR scan your files that were extracted. With his instructions and script, you don't need to locate the directory of anything except for where your RGBImages are.

Important Note: If you are using VideoSubFinder's Create Cleared Text Images (RGBImages->TXTImages) feature, make sure to change the path to point easyOCR to the TXTImages directory instead.
Code:
C:\>easyOcrImage.py -l ch_tra -d "c:\VideoSubFinder\TXTImages\"
i follow your instructions but i get
'/cd' is not recognized as an internal or external command,
operable program or batch file.


'C:\' is not recognized as an internal or external command,
operable program or batch file.
 

SamKook

Grand Wizard
Staff member
Super Moderator
Uploader
May 10, 2009
3,755
5,154
The "C:\>" is not part of the command, it's the command prompt telling you where it's pointing to.

And the "\cd" I assume they meant type "cd \" to go to the root of the c drive since the default usually is "C:\Windows\system32>" meaning you're in the system32 folder in the Windows folder that's located in the C drive.