-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsection-4.py
72 lines (60 loc) · 1.44 KB
/
section-4.py
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import os
from tkinter.filedialog import askopenfilename
import pyttsx3
import PyPDF2
from pdf2image import convert_from_path
from gtts import gTTS
from googletrans import Translator, constants
from PIL import Image
import pytesseract
import cv2,sys
from playsound import playsound
import platform
import time
from fpdf import FPDF
import shutil
# creating dir
cwd = os.getcwd()
dir = "converter"
parent_dir = cwd
path = os.path.join(parent_dir, dir)
# initialization
img_count =1
dir_count = 1
file_count = 0
# camera open
camera = cv2.VideoCapture(0)
while True:
_,frame = camera.read()
cv2.imshow('test',frame)
k = cv2.waitKey(1)
if k%256 == 27:
print('Escape hit,close')
break
elif k%256 == 32:
if dir_count == 1:
os.mkdir(path)
dir_count+=1
img_name = "{}/{}/img{}.jpg".format(cwd,dir,img_count)
cv2.imwrite(img_name,frame)
print('screenshot taken')
img_count+=1
camera.release()
cv2.destroyAllWindows()
# file_count and dir_path
file_dir = '{}/{}/'.format(cwd,dir)
width ,height = 0,0
cdir = "{}/".format(file_dir)
for pat in os.listdir(cdir):
if os.path.isfile(os.path.join(cdir, pat)):
file_count += 1
print(file_count)
# camera close
time.sleep(10)
i = 1
while i <= file_count:
file_img = Image.open(file_dir +'img%.d.jpg' % i)
text = pytesseract.image_to_string(file_img, lang="eng")
print(text.strip())
i +=1
print('\n')