-
Notifications
You must be signed in to change notification settings - Fork 8.1k
/
Copy pathtest_paddleocr.py
78 lines (58 loc) · 2.06 KB
/
test_paddleocr.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# -*- encoding: utf-8 -*-
from pathlib import Path
from typing import Any
import pytest
from paddleocr import PaddleOCR
cur_dir = Path(__file__).resolve().parent
test_file_dir = cur_dir / "test_files"
IMAGE_PATHS_OCR = [str(test_file_dir / "254.jpg"), str(test_file_dir / "img_10.jpg")]
@pytest.fixture(params=["en", "ch"])
def ocr_engine(request: Any) -> PaddleOCR:
"""
Initialize PaddleOCR engine with different languages.
Args:
request: pytest fixture request object.
Returns:
An instance of PaddleOCR.
"""
return PaddleOCR(lang=request.param)
def test_ocr_initialization(ocr_engine: PaddleOCR) -> None:
"""
Test PaddleOCR initialization.
Args:
ocr_engine: An instance of PaddleOCR.
"""
assert ocr_engine is not None
@pytest.mark.parametrize("image_path", IMAGE_PATHS_OCR)
def test_ocr_function(ocr_engine: PaddleOCR, image_path: str) -> None:
"""
Test PaddleOCR OCR functionality with different images.
Args:
ocr_engine: An instance of PaddleOCR.
image_path: Path to the image to be processed.
"""
result = ocr_engine.ocr(image_path)
assert result is not None
assert isinstance(result, list)
@pytest.mark.parametrize("image_path", IMAGE_PATHS_OCR)
def test_ocr_det_only(ocr_engine: PaddleOCR, image_path: str) -> None:
"""
Test PaddleOCR OCR functionality with detection only.
Args:
ocr_engine: An instance of PaddleOCR.
image_path: Path to the image to be processed.
"""
result = ocr_engine.ocr(image_path, det=True, rec=False)
assert result is not None
assert isinstance(result, list)
@pytest.mark.parametrize("image_path", IMAGE_PATHS_OCR)
def test_ocr_rec_only(ocr_engine: PaddleOCR, image_path: str) -> None:
"""
Test PaddleOCR OCR functionality with recognition only.
Args:
ocr_engine: An instance of PaddleOCR.
image_path: Path to the image to be processed.
"""
result = ocr_engine.ocr(image_path, det=False, rec=True)
assert result is not None
assert isinstance(result, list)