离线视频ocr识别

bash 复制代码
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

下载

bash 复制代码
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

去掉版本依赖,修改如下:

bash 复制代码
 install_requires=[
        "tesserocr",
        "scipy",
        "opencv-python",
        "numpy",
        "tqdm",
        "click",
        "Pillow",
    ],

之后安装

bash 复制代码
python setup.py install

如果遇到

RuntimeError: Failed to init API, possibly an invalid tessdata path: ./

则需要设置环境变量TESSDATA_PREFIX为C:\Program Files\Tesseract-OCR\tessdata\

默认只能识别英文,所以要把包改掉

查看默认位置:

python 复制代码
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'
>>>
powershell 复制代码
nano /home/catcatyu/.local/lib/python3.10/site-packages/video_ocr.py

修改124行添加lang=chi_sim 参数。

python 复制代码
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

之后使用

bash 复制代码
video-ocr --sample_rate 10  1.mp4

即可识别。

效果:


使用--sample_rate 参数可以提高精度数字越大越好

相关推荐
笨笨聊运维5 分钟前
CentOS官方不维护版本,配置python升级方法,无损版
linux·python·centos
Gerardisite8 分钟前
如何在微信个人号开发中有效管理API接口?
java·开发语言·python·微信·php
小毛驴85038 分钟前
软件设计模式-装饰器模式
python·设计模式·装饰器模式
闲人编程1 小时前
Python的导入系统:模块查找、加载和缓存机制
java·python·缓存·加载器·codecapsule·查找器
weixin_457760001 小时前
Python 数据结构
数据结构·windows·python
合作小小程序员小小店2 小时前
web网页,在线%抖音,舆情,线性回归%分析系统demo,基于python+web+echart+nlp+线性回归,训练,数据库mysql
python·自然语言处理·回归·nlp·线性回归
q***2512 小时前
Python中的简单爬虫
爬虫·python·信息可视化
最晚的py2 小时前
Python Matplotlib
python·数据分析
柳鲲鹏2 小时前
OpenCV:文件视频防抖,python版
python·opencv·音视频