日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

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

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

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

import cv2,copy,os

import time

class Ocr():

def __init__(self,mobile):

if mobile=='否':

# 加載移動端預訓練模型

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

else:

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

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], # 圖片數據,ndarray.shape 為 [H, W, C],BGR格式;

use_gpu=gpu, # 是否使用 GPU;若使用GPU,請先設置CUDA_VISIBLE_DEVICES環境變量

output_dir='ocr_result', # 圖片的保存路徑,默認設為 ocr_result;

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

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('識別結果保存目錄:', testPath)

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

print('精準識別:', 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)

#返回所有幀數

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時取幀保存,圖片,即隔timeS保存一次圖片

#運算時間

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:#判斷是否重復

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

last_text=copy.copy(now_text)

print(text,f'用時:{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'全部完成用時:{time_stop-time_start}')

總結

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

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。