use mmcv dump instead ()

pull/121/head
Hongbin Sun 2021-04-23 10:27:12 +08:00 committed by GitHub
parent 43dcb32d4f
commit d541de77c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 8 deletions

View File

@ -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)