Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
yjmm10 committed Aug 13, 2024
1 parent 72c37a6 commit fda7cc3
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,4 @@ venv.bak/

telos/models
output-*
tests/output
18 changes: 9 additions & 9 deletions Telos_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def test_layout():

# Draw detections
combined_img = model.draw_detections(img,mask_alpha=0.2)
cv2.imwrite("output-layout.jpg", combined_img)
cv2.imwrite("tests/output/output-layout.jpg", combined_img)

def test_formula():
import cv2
Expand All @@ -78,7 +78,7 @@ def test_formula():

# Draw detections
combined_img = model.draw_detections(img,mask_alpha=0.2)
cv2.imwrite("output-formula.jpg", combined_img)
cv2.imwrite("tests/output/output-formula.jpg", combined_img)

def test_latexocr():
import cv2
Expand All @@ -101,7 +101,7 @@ def test_latexocr():

# # Draw detections
# combined_img = model.draw_detections(img,mask_alpha=0.2)
# cv2.imwrite("output-formula.jpg", combined_img)
# cv2.imwrite("tests/output/output-formula.jpg", combined_img)
def test_dbnet():
import cv2

Expand All @@ -116,7 +116,7 @@ def test_dbnet():

# Draw detections
combined_img = model.draw_detections(img,mask_alpha=0.2)
cv2.imwrite("output-text.jpg", combined_img)
cv2.imwrite("tests/output/output-text.jpg", combined_img)

def test_crnnnet():
import cv2
Expand All @@ -134,7 +134,7 @@ def test_crnnnet():
print(result)
# # Draw detections
# combined_img = model.draw_detections(img,mask_alpha=0.2)
# cv2.imwrite("output-text.jpg", combined_img)
# cv2.imwrite("tests/output/output-text.jpg", combined_img)

def test_OCR():
import cv2
Expand All @@ -153,7 +153,7 @@ def test_OCR():

# # Draw detections
# combined_img = model.draw_detections(img,mask_alpha=0.2)
# cv2.imwrite("output-text.jpg", combined_img)
# cv2.imwrite("tests/output/output-text.jpg", combined_img)

def test_OCR_wo_det():
import cv2
Expand Down Expand Up @@ -186,7 +186,7 @@ def test_reading_order():

# # Draw detections
# combined_img = model.draw_detections(img,mask_alpha=0.2)
# cv2.imwrite("output-layout.jpg", combined_img)
# cv2.imwrite("tests/output/output-layout.jpg", combined_img)

model = ReadingOrder()
# img = cv2.imread("/home/zyj/project/MOP/test_img/page_p0.png")
Expand All @@ -197,7 +197,7 @@ def test_reading_order():

# # Draw detections
# combined_img = model.draw_detections(img,mask_alpha=0.2)
# cv2.imwrite("output-text.jpg", combined_img)
# cv2.imwrite("tests/output/output-text.jpg", combined_img)

def test_Table():
import cv2
Expand All @@ -216,7 +216,7 @@ def test_Table():

# # Draw detections
# combined_img = model.draw_detections(img,mask_alpha=0.2)
# cv2.imwrite("output-text.jpg", combined_img)
# cv2.imwrite("tests/output/output-text.jpg", combined_img)


if __name__ == "__main__":
Expand Down
45 changes: 44 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ pillow = "^10.4.0"
streamlit = "^1.37.1"
fastapi = "^0.112.0"
uvicorn = {extras = ["standard"], version = "^0.30.5"}
psutil = "^6.0.0"
python-multipart = "^0.0.9"

[tool.poetry.group.dev.dependencies]
pylint = "^2.17.4"
Expand Down
4 changes: 2 additions & 2 deletions telos/core/reading_order/xycut.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def draw_result(self, image, order=None, data=None,filename="output-reading_orde
if order is None:
order = self.result

saved_path = os.path.join(output,filename+".png")
saved_path = os.path.join(output, "tests", "output", filename+".png")
sorted_boxes = data[np.array(order)].tolist()
reading_order_img = self.vis_polygons_with_index(image, [self.bbox2points(it) for it in sorted_boxes])
cv2.imwrite(saved_path, reading_order_img)
Expand All @@ -46,7 +46,7 @@ def __call__(self, image, bbox, visual=True):
self.recursive_xy_cut(np.asarray(data).astype(int), np.arange(len(data)), result)

if visual:
saved_path = os.path.join(self.saved_dir,"output-reading_order.png")
saved_path = os.path.join(self.saved_dir,"tests/output/output-reading_order.png")
sorted_boxes = data[np.array(result)].tolist()
reading_order_img = self.vis_polygons_with_index(image, [self.bbox2points(it) for it in sorted_boxes])
cv2.imwrite(saved_path, reading_order_img)
Expand Down
8 changes: 6 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@

"""Test config"""
from pathlib import Path
from tempfile import TemporaryDirectory

import pytest

import os

@pytest.fixture
def mock_path() -> Path:
"""Mock a path, and clean when unit test done."""
with TemporaryDirectory() as temp_path:
yield Path(temp_path)

@pytest.fixture(scope="session", autouse=True)
def create_output_directory():
output_dir = os.path.join(os.path.dirname(__file__), "output")
os.makedirs(output_dir, exist_ok=True)
8 changes: 4 additions & 4 deletions tests/core/test_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_dbnet():

# Draw detections
combined_img = model.draw_detections(img,mask_alpha=0.2)
cv2.imwrite("output-dbnet.jpg", combined_img)
cv2.imwrite("tests/output/output-dbnet.jpg", combined_img)



Expand Down Expand Up @@ -50,7 +50,7 @@ def test_yolov8():

# Draw detections
combined_img = model.draw_detections(img)
cv2.imwrite("output-yolov8.jpg", combined_img)
cv2.imwrite("tests/output/output-yolov8.jpg", combined_img)

def test_lore():

Expand All @@ -63,7 +63,7 @@ def test_lore():
result = model(img)
show_img = model.visual(img)

cv2.imwrite("output-lore.jpg", show_img)
cv2.imwrite("tests/output/output-lore.jpg", show_img)

def test_lore_ocr():

Expand All @@ -77,5 +77,5 @@ def test_lore_ocr():
result = model(img)

res_table = model.post_process_4ocr(img, result,ocr)
with open(f"output-lore-ocr.html", "w", encoding="utf-8") as f:
with open(f"tests/output/output-lore-ocr.html", "w", encoding="utf-8") as f:
f.write(res_table)
2 changes: 1 addition & 1 deletion tests/modules/test_formula.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_formula_det():

# Draw detections
combined_img = model.draw_detections(img,mask_alpha=0.2)
cv2.imwrite("output-formula-det.jpg", combined_img)
cv2.imwrite("tests/output/output-formula-det.jpg", combined_img)


def test_latexocr():
Expand Down
2 changes: 1 addition & 1 deletion tests/modules/test_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ def test_layout():

# Draw detections
combined_img = model.draw_detections(img,mask_alpha=0.2)
cv2.imwrite("output-layout.jpg", combined_img)
cv2.imwrite("tests/output/output-layout.jpg", combined_img)
2 changes: 1 addition & 1 deletion tests/modules/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ def test_table_ts():
model = Table_TSR()
img = cv2.imread("./tests/test_img/test_lore.jpg")
result = model(img)
with open(f"output-table-tsr.html", "w", encoding="utf-8") as f:
with open(f"tests/output/output-table-tsr.html", "w", encoding="utf-8") as f:
f.write(result)

0 comments on commit fda7cc3

Please sign in to comment.