mirror of https://github.com/open-mmlab/mmocr.git
use mmcv dump instead (#120)
parent
43dcb32d4f
commit
d541de77c7
|
@ -1,4 +1,3 @@
|
|||
import json
|
||||
from argparse import ArgumentParser
|
||||
|
||||
import mmcv
|
||||
|
@ -9,12 +8,6 @@ from mmocr.core.visualize import det_recog_show_result
|
|||
from mmocr.datasets.pipelines.crop import crop_img
|
||||
|
||||
|
||||
def write_json(obj, fpath):
|
||||
"""Write json object to file."""
|
||||
with open(fpath, 'w') as f:
|
||||
json.dump(obj, f, indent=4, separators=(',', ': '), ensure_ascii=False)
|
||||
|
||||
|
||||
def det_and_recog_inference(args, det_model, recog_model):
|
||||
image_path = args.img
|
||||
end2end_res = {'filename': image_path}
|
||||
|
@ -109,7 +102,11 @@ def main():
|
|||
|
||||
det_recog_result = det_and_recog_inference(args, detect_model, recog_model)
|
||||
print(f'result: {det_recog_result}')
|
||||
write_json(det_recog_result, args.out_file + '.json')
|
||||
mmcv.dump(
|
||||
det_recog_result,
|
||||
args.out_file + '.json',
|
||||
ensure_ascii=False,
|
||||
indent=4)
|
||||
|
||||
img = det_recog_show_result(args.img, det_recog_result)
|
||||
mmcv.imwrite(img, args.out_file)
|
||||
|
|
Loading…
Reference in New Issue