Skip to content

Commit 5975918

Browse files
author
namrun
committed
Script to store the text in an image to a text file added
1 parent 81ba2d1 commit 5975918

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

image-to-text.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#Imports and dependencies
2+
#These packages are used for OCR(Optical character recognition)
3+
import pytesseract
4+
from PIL import Image
5+
import sys
6+
7+
'''The script can be run by passing the path of the image as a Command Line argument as,
8+
9+
python3 image-to-text.py "/path_of_image"
10+
11+
'''
12+
13+
def convert_image_to_text(image_path):
14+
text = ""
15+
#image_path = input("Enter the path of the image: ")
16+
text = pytesseract.image_to_string(Image.open(image_path))
17+
with open("Text_in_the_image.txt", "w") as file:
18+
file.write(text)
19+
return("Text in the image is successfully written to a text file in the same directory")
20+
21+
if __name__ == "__main__":
22+
print(convert_image_to_text(sys.argv[1]))

0 commit comments

Comments
 (0)