MCPcopy Index your code
hub / github.com/Layout-Parser/layout-parser / test_viz

Function test_viz

tests/test_visualization.py:24–117  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

22
23
24def test_viz():
25
26 image = cv2.imread("tests/fixtures/ocr/test_gcv_image.jpg")
27 ocr_agent = GCVAgent.with_credential(
28 "tests/fixtures/ocr/test_gcv_credential.json", languages=["en"]
29 )
30 res = ocr_agent.load_response("tests/fixtures/ocr/test_gcv_response.json")
31
32 draw_box(image, Layout([]))
33 draw_text(image, Layout([]))
34
35 layout = Layout(
36 [
37 Interval(0, 10, axis="x"),
38 Rectangle(0, 50, 100, 80),
39 Quadrilateral(np.array([[10, 10], [30, 40], [90, 40], [10, 20]])),
40 ]
41 )
42
43 draw_box(image, layout)
44 draw_text(image, layout)
45
46 # Test colors
47 draw_box(image, layout, box_color=["red", "green", "blue"])
48 draw_box(image, layout, box_color="red")
49
50 draw_text(image, layout, box_color=["red", "green", "blue"])
51 with pytest.raises(ValueError):
52 draw_box(image, layout, box_color=["red", "green", "blue", "yellow"])
53 with pytest.raises(ValueError):
54 draw_text(
55 image,
56 layout,
57 box_color=["red", "green", "blue", "yellow"],
58 with_layout=True,
59 )
60
61 # Test alphas
62 draw_box(image, layout, box_alpha=0)
63 draw_box(image, layout, box_alpha=[0.1, 0.2, 0.3])
64 with pytest.raises(ValueError):
65 draw_box(image, layout, box_color=[0.1, 0.2, 0.3, 0.5])
66 with pytest.raises(ValueError):
67 draw_box(image, layout, box_color=[0.1, 0.2, 0.3, 1.5])
68
69 # Test widths
70 draw_box(image, layout, box_width=1)
71 draw_box(image, layout, box_width=[1, 2, 3])
72 with pytest.raises(ValueError):
73 draw_box(image, layout, box_width=[1, 2, 3, 4])
74
75 draw_box(
76 image,
77 layout,
78 box_alpha=[0.1, 0.2, 0.3],
79 box_width=[1, 2, 3],
80 box_color=["red", "green", "blue"],
81 )

Callers

nothing calls this directly

Calls 9

draw_boxFunction · 0.85
LayoutClass · 0.85
draw_textFunction · 0.85
IntervalClass · 0.85
RectangleClass · 0.85
QuadrilateralClass · 0.85
with_credentialMethod · 0.80
load_responseMethod · 0.45

Tested by

no test coverage detected