Spaces:
Running
Running
File size: 1,697 Bytes
947c08e |
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 |
import os
import sys
import cv2
import pytest
import numpy as np
from manga_translator.rendering import dispatch as dispatch_rendering, dispatch_eng_render
from manga_translator.utils import (
TextBlock,
visualize_textblocks,
)
RENDER_IMAGE_FOLDER = 'test/testdata/render'
os.makedirs(RENDER_IMAGE_FOLDER, exist_ok=True)
def save_result(path, img, regions):
path = os.path.join(RENDER_IMAGE_FOLDER, path)
cv2.imwrite(path, visualize_textblocks(img, regions))
@pytest.mark.asyncio
async def test_default_renderer():
width, height = 1000, 1000
img = np.zeros((height, width, 3))
regions = [
TextBlock(
[[[10, 10], [200, 10], [10, 400], [200, 400]]],
texts=['a', 'b','c', 'd', 'e', 'f'],
translation='aaaaaa bbbbbbbbbbbb cccc ddddddddddd eeeeeeeeeeeeee fff'
),
TextBlock(
[[[410, 10], [900, 10], [410, 800], [900, 800]]],
texts=['eng', 'pne'],
translation=#'aaaaaa bbbbbbbbbbbb cccc' \
# 'dddddddddddddddddddddddddddddddddddddddddddddddddddd eeeeeeeeeeeeee fff' \
# 'dddddddddddddddddddddddddddddddddddddddddddddddddddd fff' \
# 'dddddddddddddddddddddddddddddddddddddddddddddddddddd ' \
'normal english sentences can be hyphenated! ' \
'Pneumonoultramicroscopicsilicovolcanoconiosis'
),
]
for region in regions:
region.target_lang = 'ENG'
region.set_font_colors([255, 255, 255], [200, 200, 200])
region.font_size = 100
img_rendered = await dispatch_rendering(img, regions, hyphenate=False)
save_result('default1.png', img_rendered, regions)
|