离线视频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 参数可以提高精度数字越大越好

相关推荐
老师好,我是刘同学36 分钟前
基数排序原理与Python实现详解
python·排序算法
va学弟9 小时前
Java 网络通信编程(6):视频通话
java·服务器·网络·音视频
Storynone9 小时前
【Day20】LeetCode:39. 组合总和,40. 组合总和II,131. 分割回文串
python·算法·leetcode
小鸡吃米…9 小时前
Python—— 环境搭建
python
chy000019 小时前
视频播放器无法连接网络问题排查与解决总结
网络·音视频
io_T_T10 小时前
python 文件管理库 Path 解析(详细&基础)
python
渔阳节度使11 小时前
SpringAI实时监控+观测性
后端·python·flask
铁手飞鹰11 小时前
Visual Studio创建Cmake工程导出DLL,通过Python调用DLL
android·python·visual studio
飞Link11 小时前
告别盲目找Bug:深度解析 TSTD 异常检测中的预测模型(Python 实战版)
开发语言·python·算法·bug
7yewh12 小时前
jetson_yolo_deployment 02_linux_dev_skills
linux·python·嵌入式硬件·yolo·嵌入式