从网络摄像头流读取实时图像

问题描述

`我正在使用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 (将#修改为@)