728x90
반응형
import cv2
import pytesseract
from pytesseract import Output
from gtts import gTTS
import pygame
cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_BUFFERSIZE, 1)
while True:
# Capture frame-by-frame
ret, frame = cap.read()
d = pytesseract.image_to_data(frame,output_type=Output.DICT)
n_boxes = len(d['text'])
for i in range(n_boxes):
if int(d['conf'][i]) > 60:
(text, x, y, w, h) = (d['text'][i], d['left'][i], d['top'][i], d['width'][i], d['height'][i])
# don't show empty text
if text and text.strip() != "":
frame = cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
frame = cv2.putText(frame, text, (x, y - 10), cv2.FONT_HERSHEY_SIMPLEX, 1.0, (0, 0, 255), 3)
print(text)
tts = gTTS(text, slow=False)
tts.save("REAL.mp3")
file = "REAL.mp3"
pygame.mixer.init()
pygame.mixer.music.load("/home/pi/ocr_try/REAL.mp3")
pygame.mixer.music.play()
# Display the resulting frame
cv2.imshow('frame', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()
728x90
반응형
'RaspberryPi' 카테고리의 다른 글
[RaspberryPi] 라즈베리파이 터미널에서 화면 캡처 screenshot (0) | 2022.05.17 |
---|---|
Python yolov5(detect.py) (0) | 2022.05.06 |
RaspberryPi4 + YOLOv5 Error 및 추가 설치 (0) | 2022.05.05 |
RaspberryPi + opencv (0) | 2022.05.05 |
RaspberryPi + YOLOv5 (1) | 2022.05.05 |