반응형


pyttsx 패키지 설치

$ sudo pip install pyttsx



태스트를 위한 간단한 예제


import pyttsx

engine = pyttsx.init()


engine.say('Greetings!')

engine.say('How are you today?')


engine.runAndWait()





영상으로부터 문자를 추출해냈던 태스트 프로그램에 적용시켜봤습니다.


[그래픽스&컴퓨터비전/opencv 프로그래밍] - pytesseract와 opencv를 이용하여 문자 인식 태스트 ( OCR )



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import cv2
import PIL
import pytesseract
import pyttsx
 
 
capture = cv2.VideoCapture(0)  
print 'image width %d' % capture.get(3)
print 'image height %d' % capture.get(4)  
  
capture.set(3320)
capture.set(4240)
 
engine = pyttsx.init()
engine.startLoop(False)
  
while(1):  
    ret,frame = capture.read()  
  
 
 
    # Grayscale
    img = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
 
    # Black and White
    ret, img_binary = cv2.threshold(img, 100255, cv2.THRESH_BINARY)
 
    # resizing image
    img = cv2.resize(img_binary, (00), fx=2.5, fy=3)
 
    # Convert to PIL image and use pytesseract to extract text.
    img = PIL.Image.fromarray(img)
    txt = pytesseract.image_to_string(img)
 
 
 
    if len(txt) > 3:
        print(txt)
        engine.say(txt.decode('utf-8'))
        engine.iterate()
     # engine.runAndWait()
 
 
    cv2.imshow('webcam', frame)
    cv2.imshow('bianry', img_binary )
 
 
    if cv2.waitKey(1)&0xFF == ord('q'):  
        break;
 
engine.stop()
engine.endLoop()
capture.release()  
cv2.destroyAllWindows() 
cs





참고

https://github.com/parente/pyttsx




반응형

문제 발생시 지나치지 마시고 댓글 남겨주시면 가능한 빨리 답장드립니다.


제가 쓴 책도 한번 검토해보세요 ^^

+ Recent posts