Skip to content

Commit 8ef6411

Browse files
Extract the text from a image and isolate words
1 parent ebfd55d commit 8ef6411

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Extract_Text_from_image.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# extract text from a img and its coordinates using the pytesseract module
2+
import cv2
3+
import pytesseract
4+
# You need to add tesseract binary dependency to system variable for this to work
5+
6+
img =cv2.imread('img.png')
7+
#We need to convert the img into RGB format
8+
img=cv2.cvtColor(img,cv2.COLOR_BGR2RGB)
9+
10+
hI,wI,k=img.shape
11+
print(pytesseract.image_to_string(img))
12+
boxes=pytesseract.image_to_boxes(img)
13+
for b in boxes.splitlines():
14+
b=b.split(' ')
15+
x,y,w,h=int(b[1]),int(b[2]),int(b[3]),int(b[4])
16+
cv2.rectangle(img,(x,hI-y),(w,hI-h),(0,0,255),0.2)
17+
18+
cv2.imshow('img',img)
19+
cv2.waitKey(0)

0 commit comments

Comments
 (0)