Demo¶
OCR End2End Demo¶
End-to-End Test Image Demo¶
To end-to-end test a single image with text detection and recognition simutaneously:
python demo/ocr_image_demo.py demo/demo_text_det.jpg demo/output.jpg
The default config for text detection and recognition are PSENet_ICDAR2015 and SAR, respectively.
The predicted result will be saved as
demo/output.jpg
.To use other algorithms of text detection and recognition, please set arguments:
--det-config
,--det-ckpt
,--recog-config
,--recog-ckpt
.To use batch mode for text recognition, please set arguments:
--batch-mode
,--batch-size
.
Remarks¶
If
--imshow
is specified, the demo will also show the image with OpenCV.The
ocr_image_demo.py
script only supports GPU and so the--device
parameter cannot take cpu as an argument.(Experimental) By specifying
--ocr-in-lines
, the ocr results will be grouped and presented in lines.
Text Detection Demo¶
Text Detection Single Image Demo¶
We provide a demo script to test a single image for text detection with a single GPU.
Text Detection Model Preparation: The pre-trained text detection model can be downloaded from model zoo. Take PANet as an example:
python demo/image_demo.py ${TEST_IMG} ${CONFIG_FILE} ${CHECKPOINT_FILE} ${SAVE_PATH} [--imshow] [--device ${GPU_ID}]
Example:
python demo/image_demo.py demo/demo_text_det.jpg configs/textdet/panet/panet_r18_fpem_ffm_600e_icdar2015.py https://download.openmmlab.com/mmocr/textdet/panet/panet_r18_fpem_ffm_sbn_600e_icdar2015_20210219-42dbe46a.pth demo/demo_text_det_pred.jpg
The predicted result will be saved as demo/demo_text_det_pred.jpg
.
Text Detection Multiple Image Demo¶
We provide a demo script to test multi-images in batch mode for text detection with a single GPU.
Text Detection Model Preparation: The pre-trained text detection model can be downloaded from model zoo. Take PANet as an example:
python demo/batch_image_demo.py ${CONFIG_FILE} ${CHECKPOINT_FILE} ${SAVE_PATH} --images ${IMAGE1} ${IMAGE2} [--imshow] [--device ${GPU_ID}]
Example:
python demo/batch_image_demo.py configs/textdet/panet/panet_r18_fpem_ffm_600e_icdar2015.py https://download.openmmlab.com/mmocr/textdet/panet/panet_r18_fpem_ffm_sbn_600e_icdar2015_20210219-42dbe46a.pth save_results --images demo/demo_text_det.jpg demo/demo_text_det.jpg
The predicted result will be saved in folder save_results
.
Text Detection Webcam Demo¶
We also provide live demos from a webcam as in mmdetection.
python demo/webcam_demo.py \
${CONFIG_FILE} \
${CHECKPOINT_FILE} \
[--device ${GPU_ID}] \
[--camera-id ${CAMERA-ID}] \
[--score-thr ${SCORE_THR}]
Examples:
python demo/webcam_demo.py \
configs/textdet/panet/panet_r18_fpem_ffm_600e_icdar2015.py \ https://download.openmmlab.com/mmocr/textdet/panet/panet_r18_fpem_ffm_sbn_600e_icdar2015_20210219-42dbe46a.pth
Remarks¶
If
--imshow
is specified, the demo will also show the image with OpenCV.The
image_demo.py
script only supports GPU and so the--device
parameter cannot take cpu as an argument.
Text Recognition Demo¶
Text Recognition Single Image Demo¶
We provide a demo script to test a single demo image for text recognition with a single GPU.
Text Recognition Model Preparation: The pre-trained text recognition model can be downloaded from model zoo. Take SAR as an example:
python demo/image_demo.py ${TEST_IMG} ${CONFIG_FILE} ${CHECKPOINT_FILE} ${SAVE_PATH} [--imshow] [--device ${GPU_ID}]
Example:
python demo/image_demo.py demo/demo_text_recog.jpg configs/textrecog/sar/sar_r31_parallel_decoder_academic.py https://download.openmmlab.com/mmocr/textrecog/sar/sar_r31_parallel_decoder_academic-dba3a4a3.pth demo/demo_text_recog_pred.jpg
The predicted result will be saved as demo/demo_text_recog_pred.jpg
.
Text Recognition Multiple Image Demo¶
We provide a demo script to test multi-images in batch mode for text recognition with a single GPU.
Text Recognition Model Preparation: The pre-trained text recognition model can be downloaded from model zoo. Take SAR as an example:
python demo/batch_image_demo.py ${CONFIG_FILE} ${CHECKPOINT_FILE} ${SAVE_PATH} --images ${IMAGE1} ${IMAGE2} [--imshow] [--device ${GPU_ID}]
Example:
python demo/image_demo.py configs/textrecog/sar/sar_r31_parallel_decoder_academic.py https://download.openmmlab.com/mmocr/textrecog/sar/sar_r31_parallel_decoder_academic-dba3a4a3.pth save_results --images demo/demo_text_recog.jpg demo/demo_text_recog.jpg
The predicted result will be saved in folder save_results
.
Text Recognition Webcam Demo¶
We also provide live demos from a webcam as in mmdetection.
python demo/webcam_demo.py \
${CONFIG_FILE} \
${CHECKPOINT_FILE} \
[--device ${GPU_ID}] \
[--camera-id ${CAMERA-ID}] \
[--score-thr ${SCORE_THR}]
Examples:
python demo/webcam_demo.py \
configs/textrecog/sar/sar_r31_parallel_decoder_academic.py \
https://download.openmmlab.com/mmocr/textrecog/sar/sar_r31_parallel_decoder_academic-dba3a4a3.pth
Remarks¶
If
--imshow
is specified, the demo will also show the image with OpenCV.The
image_demo.py
script only supports GPU and so the--device
parameter cannot take cpu as an argument.