第八节课 字幕提取

1、/usr/local/Cellar/tesseract/4.1.1/share/tessdata

2、pip3 install pytesseract

export TESSDATA_PREFIX=/usr/local/Cellar/tesseract/4.1.1/share/tessdata
export PATH=$PATH:$TESSDATA_PREFIX

字幕识别

import pytesseract
import cv2
import numpy as np
from scipy import stats
import os
import matplotlib.pyplot as plt
 
 
if __name__=='__main__':
    path="20210701.mp4"
    print(path)
    cap=cv2.VideoCapture(path)
    frame_count=int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
    print(frame_count)
    i=0
    while i
img=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
        cv2.imshow("Frame-2:Gray", img)
        _,img=cv2.threshold(img,220,225,cv2.THRESH_BINARY)
        tessdata_dir_config='--tessdata-dir "/usr/local/Cellar/tesseract/4.1.1/share/tessdata" --psm 7 -c preserve_interword_spaces=1'
        word=pytesseract.image_to_string(img,lang='chi_sim',config=tessdata_dir_config)
        print(word)
        
        if cv2.waitKey(10)&0xff==ord("q"):
            break
        
    cap.release()
    cv2.destroyAllWindows()

你可能感兴趣的:(linux,centos,运维)