Skip to content

Commit ce9734c

Browse files
Merge pull request #18 from Namyalg/Image-to-Text
Image to Text
2 parents 9bcc766 + 87a52e2 commit ce9734c

File tree

6 files changed

+47
-0
lines changed

6 files changed

+47
-0
lines changed

Image_to_text/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
## Image to text
2+
- This script can be used to convert extract the text in an image and store it in a text file
3+
- The concept of Optical Character Recognition is used
4+
- The pytesseract module has been used for the same
5+
6+
## Working
7+
- Dependencies and Installs:
8+
- pip install pytesseract
9+
- To run the script :
10+
- python3 image-to-text.py "path to image"
11+
12+
- Considering an example :
13+
14+
- This is the image
15+
![Image](assets/image.PNG)
16+
17+
- On running the script
18+
![Image](assets/script.PNG)
19+
20+
- This is the text file that has the extracted text from the image
21+
![Image](assets/text.PNG)

Image_to_text/Text_in_the_image.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
‘Open-source software (OSS) is a type of computer software in which source code is released under a license in which
2+
the copyright holder grants users the rights to use, study, change, and distribute the software to anyone and for any
3+
purpose.!"! Open-source software may be developed in a collaborative public manner. Open-source software is a
4+
prominent example of open collaboration.

Image_to_text/assets/image.PNG

12.1 KB
Loading

Image_to_text/assets/script.PNG

6.66 KB
Loading

Image_to_text/assets/text.PNG

10.7 KB
Loading

Image_to_text/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)