Project Overview :

● Read the image using ocr find the text and write it in the separate .txt file. Here we using easyocr module to read the text from the image. EasyOCR will automatically download the required model files.
● Depending on your hardware, this might take a few seconds to load the model into memory. Once it's finished, you may continue reading photos without having to execute this code again.
● There are various optional parameters we may send here in addition to the list of language code.
● Save the traffic signs images as .png format. Read the write the text from those images.

Note: Code and images should be in the same folder.

 
Requirements :
 

● Python
● VS code
● Library – easyocr

Input file :




Code :
 

import easyocr f = open('Traffic_Signs.txt', 'w') reader = easyocr.Reader(['ch_sim','en'], gpu= True) result1 = reader. readtext('Image1.png', detail=0) result2 = reader. readtext('Image2.png',detail=0) result3 = reader. readtext('Image3.png',detail=0) result4 = reader. readtext('Image4.png',detail=0) result5 = reader. readtext('Image5.png',detail=0) result6 = reader. readtext('Image6.png',detail=0) print('Success') a=[result1,result2,result3,result4,result5,result6] print("Traffic Signs : ") f.write("Traffic Signs : "+"\n") for i in a: print(i) f.write(str(i)+"\n") f.close()
 
Code Explanation :
 

● import easyocr -> Import Library
● f = open('Traffic_Signs.txt', 'w') -> Open the text file named 'Traffic_Signs.txt'
● reader = easyocr.Reader(['ch_sim','en'], gpu= True) # need to run only once to load model into memory
● Read the text from the images
● result1 = reader. readtext('Image1.png', detail=0)
● result2 = reader. readtext('Image2.png',detail=0)
● result3 = reader. readtext('Image3.png',detail=0)
● result4 = reader. readtext('Image4.png',detail=0)
● result5 = reader. readtext('Image5.png',detail=0)
● result6 = reader. readtext('Image6.png',detail=0)
● print('Success')
● Get all the results as a list
● a=[result1,result2,result3,result4,result5,result6]
● Write text using for loop.

for i in a:
print(i)
f.write(str(i)+"\n")
f.close()

● Once write all the data, then close the file.
● Run the code.

 
Output :

● After running the code, all the texts were read from images,




● Also text file was generated in the same folder.👉🏻 Click For JSON File !!!


« Home

×