Skip to content

Commit a575e7a

Browse files
Added Optical Text Recognition (OCR) to J.A.R.V.I.S
1 parent fb3dee0 commit a575e7a

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

OCR.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import cv2
2+
import pytesseract
3+
4+
pytesseract.pytesseract.tesseract_cmd="C:\Program Files\Tesseract-OCR\\tesseract.exe"
5+
6+
7+
def OCR():
8+
frameWidth= 640 # CAMERA RESOLUTION
9+
frameHeight = 480
10+
brightness = 180
11+
12+
cap=cv2.VideoCapture(0)
13+
cap.set(3, frameWidth)
14+
cap.set(4, frameHeight)
15+
cap.set(10, brightness)
16+
17+
18+
# forlive video testing
19+
while True:
20+
success, img = cap.read()
21+
imgT = img.copy()
22+
textRecongized = pytesseract.image_to_string(img,lang='eng');textRecongized=textRecongized.replace("\n\x0c", "");
23+
print(textRecongized)
24+
imgT=cv2.putText(imgT,textRecongized,(img.shape[0]+120,img.shape[1]+120), cv2.FONT_HERSHEY_SIMPLEX, 1.2, (0,255,0), 1, cv2.LINE_AA)
25+
cv2.imshow("Image", imgT)
26+
27+
if cv2.waitKey(1) and 0xFF == ord('q'):
28+
break

jarvis.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import sys
88
import smtplib
99
from news import speak_news, getNewsUrl
10+
from OCR import OCR
1011
from diction import translate
1112
from helpers import *
1213
from youtube import youtube
@@ -69,7 +70,10 @@ def execute_query(self, query):
6970
speak(results)
7071
elif 'youtube downloader' in query:
7172
exec(open('youtube_downloader.py').read())
72-
73+
74+
elif 'Optical Text Recognition' or 'Text Recognition' in query:
75+
OCR()
76+
7377
elif 'voice' in query:
7478
if 'female' in query:
7579
engine.setProperty('voice', voices[1].id)

0 commit comments

Comments
 (0)