File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change
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 ]))
You can’t perform that action at this time.
0 commit comments