mirror of
https://github.com/open-mmlab/mmocr.git
synced 2025-06-03 21:54:47 +08:00
use mmcv dump instead (#120)
This commit is contained in:
parent
43dcb32d4f
commit
d541de77c7
@ -1,4 +1,3 @@
|
|||||||
import json
|
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
|
|
||||||
import mmcv
|
import mmcv
|
||||||
@ -9,12 +8,6 @@ from mmocr.core.visualize import det_recog_show_result
|
|||||||
from mmocr.datasets.pipelines.crop import crop_img
|
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):
|
def det_and_recog_inference(args, det_model, recog_model):
|
||||||
image_path = args.img
|
image_path = args.img
|
||||||
end2end_res = {'filename': image_path}
|
end2end_res = {'filename': image_path}
|
||||||
@ -109,7 +102,11 @@ def main():
|
|||||||
|
|
||||||
det_recog_result = det_and_recog_inference(args, detect_model, recog_model)
|
det_recog_result = det_and_recog_inference(args, detect_model, recog_model)
|
||||||
print(f'result: {det_recog_result}')
|
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)
|
img = det_recog_show_result(args.img, det_recog_result)
|
||||||
mmcv.imwrite(img, args.out_file)
|
mmcv.imwrite(img, args.out_file)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user