make the result json serializable
According to
https://github.com/JaidedAI/EasyOCR/blob/7a685cb8c4ba14f2bc246f89c213f1a56bbc2107/easyocr/recognition.py#L137-L149
the the confidence is numpy.array, and it's not json serializable. It would be great to make it json serializable.
And according to https://github.com/JaidedAI/EasyOCR/blob/7a685cb8c4ba14f2bc246f89c213f1a56bbc2107/easyocr/detection.py#L92-L110
the text box coord is ndarray too.
However, I got some coords return as int, not ndarray. That is wierd. Sorry I could not provide the source image since it contains patient information.
very good idea.
It makes it easier to interface with non-Python programs.
I would like to have read.readtext(filepath, output_format = 'json') like issues #326.
I was getting a serialization error when getting the data from EasyOCR as a Python dict, doing some processing, then later saving it to a JSON file. In case it's helpful for anyone else, I was able to work around it by creating a custom JSON encoder:
class CustomEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, np.integer):
return int(obj)
elif isinstance(obj, np.ndarray):
return obj.tolist()
return super().default(obj)
Then referencing my custom encoder in json.dump():
json.dump(result, f, cls=CustomEncoder)