this is the code i'm trying to execute for extracting text from image and save in a path.
def main():
path =r"D drive where images are stored"
fullTempPath =r"D drive where extracted texts are stored in xls file"
for imageName in os.listdir(path):
inputPath = os.path.join(path, imageName)
img = Image.open(inputPath)
text = pytesseract.image_to_string(img, lang ="eng")
file1 = open(fullTempPath, "a+")
file1.write(imageName+"\n")
file1.write(text+"\n")
file1.close()
file2 = open(fullTempPath, 'r')
file2.close()
if __name__ == '__main__':
main()
I'm getting the below error, and can someone help me on this
UnicodeEncodeError Traceback (most recent call last)
<ipython-input-7-fb69795bce29> in <module>
13 file2.close()
14 if __name__ == '__main__':
---> 15 main()
<ipython-input-7-fb69795bce29> in main()
8 file1 = open(fullTempPath, "a+")
9 file1.write(imageName+"\n")
---> 10 file1.write(text+"\n")
11 file1.close()
12 file2 = open(fullTempPath, 'r')
~\anaconda3\lib\encodings\cp1252.py in encode(self, input, final)
17 class IncrementalEncoder(codecs.IncrementalEncoder):
18 def encode(self, input, final=False):
---> 19 return codecs.charmap_encode(input,self.errors,encoding_table)[0]
20
21 class IncrementalDecoder(codecs.IncrementalDecoder):
UnicodeEncodeError: 'charmap' codec can't encode character '\ufb01' in position 2090: character maps to <undefined>