зеркало из https://github.com/microsoft/genalog.git
Merge pull request #13 from microsoft/laserprec/bugfix/trailinglash
Bugfix img not generated due to missing trailling '/' in dist folder
This commit is contained in:
Коммит
1227eff672
|
@ -61,7 +61,7 @@ class AnalogDocumentGeneration(object):
|
|||
|
||||
generator = self.doc_generator.create_generator(content, [template])
|
||||
# Generate the image
|
||||
doc = next(generator)
|
||||
doc = next(generator) # TODO: this does not exhaust all of the style combinations in the generator
|
||||
src = doc.render_array(resolution=self.resolution, channel="GRAYSCALE")
|
||||
# Degrade the image
|
||||
dst = self.degrader.apply_effects(src)
|
||||
|
@ -73,7 +73,7 @@ class AnalogDocumentGeneration(object):
|
|||
# save it onto disk
|
||||
text_filename = os.path.basename(full_text_path)
|
||||
img_filename = text_filename.replace(".txt", ".png")
|
||||
img_dst_path = target_folder + "img/" + img_filename
|
||||
img_dst_path = os.path.join(target_folder, "img", img_filename)
|
||||
cv2.imwrite(img_dst_path, dst)
|
||||
return
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ MULTI_PAGE_TEMPLATE_NAME = "multipage.html.jinja"
|
|||
UNDEFINED_TEMPLATE_NAME = "not a valid template"
|
||||
|
||||
TEST_OUTPUT_DIR = "test_out"
|
||||
FILE_DESTINATION = TEST_OUTPUT_DIR + "/save.png"
|
||||
FILE_DESTINATION = os.path.join(TEST_OUTPUT_DIR, "save.png")
|
||||
|
||||
CUSTOM_STYLE = {
|
||||
"font_family": ["Calibri", "Times"],
|
||||
|
|
|
@ -1,10 +1,20 @@
|
|||
import os
|
||||
import glob
|
||||
|
||||
import pytest
|
||||
|
||||
from genalog import pipeline
|
||||
from genalog.generation.document import DocumentGenerator
|
||||
|
||||
EXAMPLE_TEXT_FILE = "tests/unit/text/data/gt_1.txt"
|
||||
INPUT_TEXT_FILENAMES = glob.glob("tests/unit/text/data/gt_*.txt")
|
||||
|
||||
STYLES = {"font_size": ["5px"]}
|
||||
STYLES_COMBINATION = {"font_size": ["5px", "6px"]} # Multiple values per style are not supported right now
|
||||
DEGRATIONS = [
|
||||
("blur", {"radius": 3}),
|
||||
("morphology", {"operation": "close"})
|
||||
]
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
@ -14,14 +24,13 @@ def default_analog_generator():
|
|||
|
||||
@pytest.fixture
|
||||
def custom_analog_generator():
|
||||
custom_styles = {"font_size": ["5px"]}
|
||||
custom_degradation = [("blur", {"radius": 3})]
|
||||
return pipeline.AnalogDocumentGeneration(
|
||||
styles=custom_styles, degradations=custom_degradation, resolution=300
|
||||
styles=STYLES, degradations=DEGRATIONS, resolution=300
|
||||
)
|
||||
|
||||
|
||||
def test_default_generate_img(default_analog_generator):
|
||||
assert len(default_analog_generator.list_templates()) > 0
|
||||
example_template = default_analog_generator.list_templates()[0]
|
||||
default_analog_generator.generate_img(
|
||||
EXAMPLE_TEXT_FILE, example_template, target_folder=None
|
||||
|
@ -29,15 +38,27 @@ def test_default_generate_img(default_analog_generator):
|
|||
|
||||
|
||||
def test_custom_generate_img(custom_analog_generator):
|
||||
assert len(custom_analog_generator.list_templates()) > 0
|
||||
example_template = custom_analog_generator.list_templates()[0]
|
||||
custom_analog_generator.generate_img(
|
||||
EXAMPLE_TEXT_FILE, example_template, target_folder=None
|
||||
)
|
||||
|
||||
|
||||
def test_generate_dataset_multiprocess():
|
||||
INPUT_TEXT_FILENAMES = glob.glob("tests/unit/text/data/gt_*.txt")
|
||||
with pytest.deprecated_call():
|
||||
pipeline.generate_dataset_multiprocess(
|
||||
INPUT_TEXT_FILENAMES, "test_out", {}, [], "text_block.html.jinja"
|
||||
)
|
||||
@pytest.mark.parametrize("styles", [
|
||||
STYLES,
|
||||
pytest.param(
|
||||
STYLES_COMBINATION, marks=pytest.mark.xfail(
|
||||
reason="Style combinations are not supported. Only one value per style", strict=True)
|
||||
)
|
||||
])
|
||||
@pytest.mark.parametrize("folder_name", ["result", "result/"])
|
||||
def test_generate_dataset_multiprocess(tmpdir, folder_name, styles):
|
||||
assert len(INPUT_TEXT_FILENAMES) > 0
|
||||
output_folder = os.path.join(tmpdir, folder_name)
|
||||
pipeline.generate_dataset_multiprocess(
|
||||
INPUT_TEXT_FILENAMES, output_folder, styles, DEGRATIONS, "text_block.html.jinja"
|
||||
)
|
||||
num_generated_img = glob.glob(os.path.join(output_folder, "**/*.png"))
|
||||
assert len(num_generated_img) > 0
|
||||
assert len(num_generated_img) == len(INPUT_TEXT_FILENAMES) * len(DocumentGenerator.expand_style_combinations(styles))
|
||||
|
|
Загрузка…
Ссылка в новой задаче