如何解决从网络摄像头流读取实时图像
`我正在使用gTTS进行语音识别项目。问题是,当我运行代码时,系统没有响应。当图片不包含文字时,代码停止工作(无法阅读文字),据我所知,我尝试了但无法解决。如果有人可以帮助我解决此问题,我将不胜感激。首先十分感谢。这是我的代码:
import pytesseract
import numpy as np
from PIL import ImageGrab
import time
import requests
import io
import json
from gtts import gTTS
import os
import pyttsx3
pytesseract.pytesseract.tesseract_cmd = 'C:\\Program Files (x86)\\Tesseract-OCR\\tesseract.exe'
#img = cv2.imread('screenshotfr.JPG')
#import cv2
# Loading Video
import cv2
frameWidth = 640
frameHeight = 480
cap = cv2.VideoCapture(0)
cap.set(3,frameWidth)
cap.set(4,frameHeight)
cap.set(10,150)
while True:
# Capture frame-by-frame
ret,frame = cap.read()
file = 'live.png'
cv2.imwrite(file,frame)
# print OCR text
fh = open('text.txt','w')
texti = pytesseract.image_to_string(file)
print(texti)
fh.write(texti)
# Display the resulting frame
cv2.imshow('frame',frame)
fh.close()
fh = open('text.txt','r')
my_text = fh.read().replace("\n"," ")
output = gTTS(text=my_text,lang='fr',slow=False)
output.save("output.mp3")
fh.close()
os.system("start output.mp3")
# When everything done,release the capture
cap.release()
cv2.destroyAllWindows()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。