日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

视频识别成文字php,视频字幕和文字提取器-本地识别模型-人工智能文字识别源码交流...

發(fā)布時(shí)間:2024/3/24 63 豆豆
生活随笔 收集整理的這篇文章主要介紹了 视频识别成文字php,视频字幕和文字提取器-本地识别模型-人工智能文字识别源码交流... 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

[Python] 純文本查看 復(fù)制代碼import paddlehub as hub

import cv2,copy,os

import time

class Ocr():

def __init__(self,mobile):

if mobile=='否':

# 加載移動端預(yù)訓(xùn)練模型

self.ocr = hub.Module(name="chinese_ocr_db_crnn_mobile")

else:

# 服務(wù)端可以加載大模型,效果更好

self.ocr = hub.Module(name="chinese_ocr_db_crnn_server")

def get_text(self,image,visualization,gpu):

if gpu ==True:

os.environ["CUDA_VISIBLE_DEVICES"] = "1"

text=''

results = self.ocr.recognize_text(

images=[image], # 圖片數(shù)據(jù),ndarray.shape 為 [H, W, C],BGR格式;

use_gpu=gpu, # 是否使用 GPU;若使用GPU,請先設(shè)置CUDA_VISIBLE_DEVICES環(huán)境變量

output_dir='ocr_result', # 圖片的保存路徑,默認(rèn)設(shè)為 ocr_result;

visualization=visualization, # 是否將識別結(jié)果保存為圖片文件;

box_thresh=0.5, # 檢測文本框置信度的閾值;

text_thresh=0.5) # 識別中文文本置信度的閾值;

data=results[0]['data']

save_path = results[0]['save_path']

for infomation in data:

text=text+' '+infomation['text']

return text,save_path

if __name__ == '__main__':

time_start=time.time()

with open('配置.txt', 'r',encoding='utf-8')as f:

setting = f.read()

setting = setting.split('\n')

voidPath=setting[0].split('"')[1]

timeS = int(setting[1].split('"')[1])

testPath = setting[2].split('"')[1]

show=setting[3].split('"')[1]

mobile=setting[4].split('"')[1]

gpu=setting[5].split('"')[1]

print("視頻地址:", voidPath)

print('判斷幀間隔:', timeS)

print('識別結(jié)果保存目錄:', testPath)

print('是否可視化:', show)

print('精準(zhǔn)識別:', mobile)

print('GPU:', gpu)

if gpu=='是':

gpu=True

else:

gpu=False

c = 0

cap = cv2.VideoCapture(voidPath)

last_text = ''

now_text = ''

text = ''

orc=Ocr(mobile)

#返回所有幀數(shù)

fps=int(cap.get(cv2.CAP_PROP_FPS))

#frames_num = cap.get(7)

try:

while (cap.isOpened()):

t1=time.time()

now_text = ''

c = c + 1

ret, frame = cap.read()

if c % timeS == 0: # c除盡timeS時(shí)取幀保存,圖片,即隔timeS保存一次圖片

#運(yùn)算時(shí)間

m, s = divmod(c//fps, 60)

h, m = divmod(m, 60)

if show=='是':

now_text, save_path = orc.get_text(frame, True,gpu)

try:

image = cv2.imread(save_path)

x, y = image.shape[0:2]

image=cv2.resize(image, (int(y / 2), int(x / 2)))

cv2.imshow('Video Subtitle Extraction', image)

k = cv2.waitKey(60)

# q鍵退出

if (k & 0xff == ord('q')):

break

except:

pass

else:

now_text, save_path = orc.get_text(frame,False )

if now_text!=last_text:#判斷是否重復(fù)

text=now_text +f'[{h}:{m}:{s}]'+ '\n'

last_text=copy.copy(now_text)

print(text,f'用時(shí):{time.time()-t1}')

with open(testPath, 'a+')as f:

f.write(text)

except Exception as err:

print(err)

cap.release()

cv2.destroyAllWindows()

time_stop = time.time()

input(f'全部完成用時(shí):{time_stop-time_start}')

總結(jié)

以上是生活随笔為你收集整理的视频识别成文字php,视频字幕和文字提取器-本地识别模型-人工智能文字识别源码交流...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。