sudo apt-get install libleptonica-dev libtesseract-dev
sudo apt-get install tesseract-ocr-chi-sim
python -m pip install video-ocr
windows安装方法:
下载安装
https://digi.bib.uni-mannheim.de/tesseract/tesseract-ocr-w64-setup-5.3.3.20231005.exe
下载
wget https://github.com/simonflueckiger/tesserocr-windows_build/releases/download/tesserocr-v2.6.0-tesseract-5.3.1/tesserocr-2.6.0-cp311-cp311-win_amd64.whl
pip install tesserocr-2.6.0-cp311-cp311-win_amd64.whl
git clone https://github.com/PinkFloyded/video-ocr.git
cd video-ocr
notepad setup.py
去掉版本依赖,修改如下:
install_requires=[
"tesserocr",
"scipy",
"opencv-python",
"numpy",
"tqdm",
"click",
"Pillow",
],
之后安装
python setup.py install
如果遇到
RuntimeError: Failed to init API, possibly an invalid tessdata path: ./
则需要设置环境变量TESSDATA_PREFIX为C:\Program Files\Tesseract-OCR\tessdata\
默认只能识别英文,所以要把包改掉
查看默认位置:
Python 3.10.12 (main, Jun 11 2023, 05:26:28) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import video_ocr
>>> video_ocr.__file__
'/home/catcatyu/.local/lib/python3.10/site-packages/video_ocr.py'
>>>
nano /home/catcatyu/.local/lib/python3.10/site-packages/video_ocr.py
修改124行添加lang=chi_sim 参数。
def _ocr(frame):
pil_image = Image.fromarray(frame.image)
text = tesserocr.image_to_text(pil_image,lang="chi_sim") #这行
frame.text = text
pbar.update()
return frame
之后使用
video-ocr --sample_rate 10 1.mp4
即可识别。
效果:
使用--sample_rate
参数可以提高精度数字越大越好