mirror of
https://github.com/RapidAI/RapidOCR.git
synced 2026-11-11 21:40:52 +08:00
Optim unit tests
This commit is contained in:
1 parent
86daf3d9d8
commit
ed9da13292
10 files changed
+124
-97
No files matched your search
+6
-8
@@ -61,7 +61,7 @@
|
||||
|
||||
rapid_ocr = RapidOCR()
|
||||
|
||||
img = cv2.imread('test_images/ch_en_num.jpg')
|
||||
img = cv2.imread('tests/test_files/ch_en_num.jpg')
|
||||
|
||||
result = rapid_ocr(img)
|
||||
print(result)
|
||||
@@ -111,12 +111,10 @@
|
||||
│ ├── ch_ppocr_mobile_v2.0_cls_infer.onnx
|
||||
│ └── ch_PP-OCRv3_rec_infer.onnx
|
||||
├── requirements.txt
|
||||
├── resources
|
||||
│ └── fonts
|
||||
│ └── FZYTK.TTF
|
||||
└── test_images
|
||||
├── ch_en_num.jpg
|
||||
└── single_line_text.jpg
|
||||
└── resources
|
||||
└── fonts
|
||||
└── FZYTK.TTF
|
||||
|
||||
```
|
||||
|
||||
3. 安装运行环境
|
||||
@@ -178,7 +176,7 @@
|
||||
|
||||
- `min_height`是用来过滤只有一行文本的图像(如下图),这类图像不会进入文本检测模块,直接进入后续过程。
|
||||
|
||||

|
||||

|
||||
|
||||
- `Det`部分
|
||||
| 参数名称 | 取值范围 | 默认值 | 作用 |
|
||||
|
||||
+2
-1
@@ -90,8 +90,9 @@ def visualize(image_path, result, font_path="resources/fonts/FZYTK.TTF"):
|
||||
if __name__ == '__main__':
|
||||
rapid_ocr = RapidOCR()
|
||||
|
||||
image_path = 'test_images/ch_en_num.jpg'
|
||||
image_path = 'tests/test_files/ch_en_num.jpg'
|
||||
img = cv2.imread(image_path)
|
||||
img = np.zeros([640, 640, 3])
|
||||
result, elapse_list = rapid_ocr(img)
|
||||
print(result)
|
||||
print(elapse_list)
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 5.3 KiB |
@@ -13,6 +13,7 @@ class BaseModule():
|
||||
self.package_name = package_name
|
||||
self.root_dir = Path(__file__).resolve().parent.parent
|
||||
self.package_dir = self.root_dir / self.package_name
|
||||
self.tests_dir = self.root_dir / 'tests'
|
||||
|
||||
sys.path.append(str(self.root_dir))
|
||||
sys.path.append(str(self.package_dir))
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# @Author: SWHL
|
||||
# @Contact: liekkaskono@163.com
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import numpy as np
|
||||
import cv2
|
||||
import pytest
|
||||
|
||||
|
||||
root_dir = Path(__file__).resolve().parent.parent
|
||||
sys.path.append(str(root_dir))
|
||||
|
||||
from rapidocr_onnxruntime import RapidOCR
|
||||
|
||||
rapid_ocr = RapidOCR()
|
||||
tests_dir = root_dir / 'test_files'
|
||||
|
||||
|
||||
def test_normal():
|
||||
image_path = tests_dir / 'ch_en_num.jpg'
|
||||
img = cv2.imread(str(image_path))
|
||||
result, _ = rapid_ocr(img)
|
||||
assert result[0][1] == '正品促销'
|
||||
assert len(result) == 17
|
||||
|
||||
|
||||
def test_empty():
|
||||
img = None
|
||||
with pytest.raises(AttributeError) as exc_info:
|
||||
rapid_ocr(img)
|
||||
raise AttributeError
|
||||
assert exc_info.type is AttributeError
|
||||
|
||||
|
||||
def test_zeros():
|
||||
img = np.zeros([640, 640, 3])
|
||||
result, _ = rapid_ocr(img)
|
||||
assert result is None
|
||||
@@ -0,0 +1,41 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# @Author: SWHL
|
||||
# @Contact: liekkaskono@163.com
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import numpy as np
|
||||
import cv2
|
||||
import pytest
|
||||
|
||||
|
||||
root_dir = Path(__file__).resolve().parent.parent
|
||||
sys.path.append(str(root_dir))
|
||||
|
||||
from rapidocr_openvino import RapidOCR
|
||||
|
||||
rapid_ocr = RapidOCR()
|
||||
|
||||
tests_dir = root_dir / 'test_files'
|
||||
|
||||
|
||||
def test_normal():
|
||||
image_path = tests_dir / 'ch_en_num.jpg'
|
||||
img = cv2.imread(str(image_path))
|
||||
result, _ = rapid_ocr(img)
|
||||
assert result[0][1] == '正品促销'
|
||||
assert len(result) == 17
|
||||
|
||||
|
||||
def test_empty():
|
||||
img = None
|
||||
with pytest.raises(AttributeError) as exc_info:
|
||||
rapid_ocr(img)
|
||||
raise AttributeError
|
||||
assert exc_info.type is AttributeError
|
||||
|
||||
|
||||
def test_zeros():
|
||||
img = np.zeros([640, 640, 3])
|
||||
result, _ = rapid_ocr(img)
|
||||
assert result is None
|
||||
+12
-29
@@ -1,15 +1,20 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# @Author: SWHL
|
||||
# @Contact: liekkaskono@163.com
|
||||
from base_module import BaseModule
|
||||
import cv2
|
||||
import pytest
|
||||
from base_module import BaseModule
|
||||
|
||||
|
||||
class TestONNXRuntime():
|
||||
@pytest.mark.parametrize(
|
||||
'package_name',
|
||||
['rapidocr_onnxruntime', 'rapidocr_openvino']
|
||||
)
|
||||
def test_cls(package_name: str):
|
||||
module_name = 'ch_ppocr_v2_cls'
|
||||
class_name = 'TextClassifier'
|
||||
|
||||
base = BaseModule(package_name='rapidocr_onnxruntime')
|
||||
base = BaseModule(package_name=package_name)
|
||||
|
||||
TextClassifier = base.init_module(module_name, class_name)
|
||||
|
||||
@@ -19,29 +24,7 @@ class TestONNXRuntime():
|
||||
|
||||
text_cls = TextClassifier(config)
|
||||
|
||||
def test_cls(self):
|
||||
img_path = 'test_files/text_cls.jpg'
|
||||
img = cv2.imread(img_path)
|
||||
result = self.text_cls([img])
|
||||
assert result[1][0][0] == '180'
|
||||
|
||||
|
||||
class TestOpenVINO():
|
||||
module_name = 'ch_ppocr_v2_cls'
|
||||
class_name = 'TextClassifier'
|
||||
|
||||
base = BaseModule(package_name='rapidocr_openvino')
|
||||
|
||||
TextClassifier = base.init_module(module_name, class_name)
|
||||
|
||||
yaml_path = base.package_dir / module_name / 'config.yaml'
|
||||
config = base.read_yaml(str(yaml_path))
|
||||
config['model_path'] = str(base.package_dir / config['model_path'])
|
||||
|
||||
text_cls = TextClassifier(config)
|
||||
|
||||
def test_cls(self):
|
||||
img_path = 'test_files/text_cls.jpg'
|
||||
img = cv2.imread(img_path)
|
||||
result = self.text_cls([img])
|
||||
assert result[1][0][0] == '180'
|
||||
img_path = base.tests_dir / 'test_files' / 'text_cls.jpg'
|
||||
img = cv2.imread(str(img_path))
|
||||
result = text_cls([img])
|
||||
assert result[1][0][0] == '180'
|
||||
+11
-32
@@ -2,14 +2,19 @@
|
||||
# @Author: SWHL
|
||||
# @Contact: liekkaskono@163.com
|
||||
import cv2
|
||||
import pytest
|
||||
from base_module import BaseModule
|
||||
|
||||
|
||||
class TestONNXRuntime():
|
||||
@pytest.mark.parametrize(
|
||||
'package_name',
|
||||
['rapidocr_onnxruntime', 'rapidocr_openvino']
|
||||
)
|
||||
def test_det(package_name):
|
||||
module_name = 'ch_ppocr_v3_det'
|
||||
class_name = 'TextDetector'
|
||||
|
||||
base = BaseModule(package_name='rapidocr_onnxruntime')
|
||||
base = BaseModule(package_name)
|
||||
TextDetector = base.init_module(module_name, class_name)
|
||||
|
||||
yaml_path = base.package_dir / module_name / 'config.yaml'
|
||||
@@ -17,33 +22,7 @@ class TestONNXRuntime():
|
||||
config['model_path'] = str(base.package_dir / config['model_path'])
|
||||
|
||||
text_det = TextDetector(config)
|
||||
|
||||
def test_det(self):
|
||||
img_path = 'test_files/text_det.jpg'
|
||||
|
||||
img = cv2.imread(img_path)
|
||||
|
||||
dt_boxes, elapse = self.text_det(img)
|
||||
assert dt_boxes.shape == (18, 4, 2)
|
||||
|
||||
|
||||
class TestOpenVINO():
|
||||
module_name = 'ch_ppocr_v3_det'
|
||||
class_name = 'TextDetector'
|
||||
|
||||
base = BaseModule(package_name='rapidocr_openvino')
|
||||
TextDetector = base.init_module(module_name, class_name)
|
||||
|
||||
yaml_path = base.package_dir / module_name / 'config.yaml'
|
||||
config = base.read_yaml(str(yaml_path))
|
||||
config['model_path'] = str(base.package_dir / config['model_path'])
|
||||
|
||||
text_det = TextDetector(config)
|
||||
|
||||
def test_det(self):
|
||||
img_path = 'test_files/text_det.jpg'
|
||||
|
||||
img = cv2.imread(img_path)
|
||||
|
||||
dt_boxes, elapse = self.text_det(img)
|
||||
assert dt_boxes.shape == (18, 4, 2)
|
||||
img_path = base.tests_dir / 'test_files' / 'text_det.jpg'
|
||||
img = cv2.imread(str(img_path))
|
||||
dt_boxes, elapse = text_det(img)
|
||||
assert dt_boxes.shape == (18, 4, 2)
|
||||
File renamed without changes.
|
Before Width: | Height: | Size: 69 KiB After Width: | Height: | Size: 69 KiB |
+11
-27
@@ -2,14 +2,19 @@
|
||||
# @Author: SWHL
|
||||
# @Contact: liekkaskono@163.com
|
||||
import cv2
|
||||
import pytest
|
||||
from base_module import BaseModule
|
||||
|
||||
|
||||
class TestONNXRuntime():
|
||||
@pytest.mark.parametrize(
|
||||
'package_name',
|
||||
['rapidocr_onnxruntime', 'rapidocr_openvino']
|
||||
)
|
||||
def test_det(package_name):
|
||||
module_name = 'ch_ppocr_v3_rec'
|
||||
class_name = 'TextRecognizer'
|
||||
|
||||
base = BaseModule(package_name='rapidocr_onnxruntime')
|
||||
base = BaseModule(package_name)
|
||||
TextRecognizer = base.init_module(module_name, class_name)
|
||||
|
||||
yaml_path = base.package_dir / module_name / 'config.yaml'
|
||||
@@ -18,28 +23,7 @@ class TestONNXRuntime():
|
||||
|
||||
text_rec = TextRecognizer(config)
|
||||
|
||||
def test_rec(self):
|
||||
img_path = 'test_files/text_rec.jpg'
|
||||
img = cv2.imread(img_path)
|
||||
rec_res, elapse = self.text_rec([img])
|
||||
assert rec_res[0][0] == '韩国小馆'
|
||||
|
||||
|
||||
class TestOpenVINO():
|
||||
module_name = 'ch_ppocr_v3_rec'
|
||||
class_name = 'TextRecognizer'
|
||||
|
||||
base = BaseModule(package_name='rapidocr_openvino')
|
||||
TextRecognizer = base.init_module(module_name, class_name)
|
||||
|
||||
yaml_path = base.package_dir / module_name / 'config.yaml'
|
||||
config = base.read_yaml(str(yaml_path))
|
||||
config['model_path'] = str(base.package_dir / config['model_path'])
|
||||
|
||||
text_rec = TextRecognizer(config)
|
||||
|
||||
def test_rec(self):
|
||||
img_path = 'test_files/text_rec.jpg'
|
||||
img = cv2.imread(img_path)
|
||||
rec_res, elapse = self.text_rec([img])
|
||||
assert rec_res[0][0] == '韩国小馆'
|
||||
img_path = base.tests_dir / 'test_files' / 'text_rec.jpg'
|
||||
img = cv2.imread(str(img_path))
|
||||
rec_res, elapse = text_rec([img])
|
||||
assert rec_res[0][0] == '韩国小馆'
|
||||
Reference in new issue
Block a user