Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 53a5c68

Browse files
Real-time Text Extraction
1 parent b6adc71 commit 53a5c68

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
'''
2+
For using this code your machine had already installed OpenCV, pytesseract and PIL.
3+
For capturing a image press 'SPACE' when web-cam is on.
4+
'''
5+
#importing required libraries
6+
7+
import cv2
8+
import pytesseract
9+
from PIL import Image
10+
11+
#Put the path where you stored the tesseract.exe file in your machine
12+
pytesseract.pytesseract.tesseract_cmd = r"C:\Users91769円\AppData\Local\Programs\Tesseract-OCR\tesseract.exe"
13+
14+
15+
cam = cv2.VideoCapture(0) #Starting your webcam
16+
17+
while True:
18+
ret, img = cam.read() #Capturing the image
19+
#img= cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) Can convert colour image to grayscale
20+
21+
cv2.imshow("Original",img)
22+
#Removing noise from the image
23+
ret, thresh = cv2.threshold(img,1010, 200, cv2.THRESH_OTSU, cv2.THRESH_BINARY)
24+
cv2.imshow("After removing noise", thresh)
25+
26+
if not ret:
27+
break
28+
29+
k=cv2.waitKey(1) #Taking input from you
30+
31+
if k%256==27: #Press Esc for exit
32+
#For Esc key
33+
print("Close")
34+
break
35+
36+
elif k%256==32: #Press Space for capture the image
37+
#For Space key
38+
print("Image saved")
39+
#Put the path where you want to store the captured image in your machine
40+
path=r'C:\Users91769円\Desktop\images'+'\img.jpg'
41+
cv2.imwrite(path, thresh)
42+
break
43+
44+
src= Image.open(r"C:\Users91769円\Desktop\images\img.jpg")
45+
46+
text= pytesseract.image_to_string(src) #Extracting the text from image
47+
print(text)
48+
49+
cam.release
50+
cv2.destroyAllWindows

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /