# Aligns text lines and characters within an image
## Tested against Windows 10 / Python 3.11 / Anaconda
## pip install wrilytextaligner
## Original
<img src="https://github.com/hansalemaos/screenshots/raw/main/16_2.png"/>
## Aligned
<img src="https://github.com/hansalemaos/screenshots/raw/main/16_3.png"/>
```python
i (Any): The input image or file path.
blured_kernel (Tuple[int, int], optional): The kernel size for blurring the input image. Defaults to (5, 5).
blured_dst (int, optional): The destination for the blurred image. Defaults to 0.
adaptiveThreshold_max_value (int, optional): The maximum pixel value for the adaptive thresholding. Defaults to 255.
adaptiveTreshold_method (int, optional): The adaptive thresholding method. Defaults to cv2.ADAPTIVE_THRESH_GAUSSIAN_C.
adaptiveThreshold_block_size (int, optional): The block size for adaptive thresholding. Defaults to 11.
adaptiveThreshold_C (int, optional): The constant subtracted from the mean in adaptive thresholding. Defaults to 2.
rect_kernel_size (Tuple[int, int], optional): The kernel size for morphological operations. Defaults to (10, 10).
otsu_threshold (int, optional): The threshold value for Otsu's thresholding. Defaults to 0.
otsu_max_value (int, optional): The maximum pixel value for Otsu's thresholding. Defaults to 255.
max_line_join_distance (int, optional): The maximum distance for joining lines. Defaults to 30.
border_color_letters (Tuple[int, int, int], optional): The color of borders around characters. Defaults to (255, 255, 255).
letter_border_top (int, optional): The top border size for characters. Defaults to 10.
letter_border_bottom (int, optional): The bottom border size for characters. Defaults to 10.
letter_border_right (int, optional): The right border size for characters. Defaults to 10.
letter_border_left (int, optional): The left border size for characters. Defaults to 10.
line_border_top (int, optional): The top border size for lines. Defaults to 10.
line_border_bottom (int, optional): The bottom border size for lines. Defaults to 10.
line_border_right (int, optional): The right border size for lines. Defaults to 10.
line_border_left (int, optional): The left border size for lines. Defaults to 10.
image2crop (Union[None, np.ndarray], optional): An optional image to be cropped instead of the input image. Defaults to None.
import os, cv2
import numpy as np
from wrilytextaligner import align_wrily_text
outputfolder = r"C:\readx2"
if not os.path.exists(outputfolder):
os.makedirs(outputfolder)
for ini, fi in enumerate(
[r"https://github.com/hansalemaos/screenshots/raw/main/16_2.png"]
):
allines = align_wrily_text(
i=fi,
blured_kernel=(5, 5),
blured_dst=0,
adaptiveThreshold_max_value=255,
adaptiveTreshold_method=cv2.ADAPTIVE_THRESH_GAUSSIAN_C,
adaptiveThreshold_block_size=11,
adaptiveThreshold_C=2,
rect_kernel_size=(8, 8),
otsu_threshold=0,
otsu_max_value=255,
max_line_join_distance=30,
border_color_letters=(255, 255, 255),
letter_border_top=10,
letter_border_bottom=10,
letter_border_right=10,
letter_border_left=10,
line_border_top=10,
line_border_bottom=10,
line_border_right=10,
line_border_left=10,
image2crop=None,
)
vstacked = np.vstack(allines)
cv2.imwrite(rf"{outputfolder}\{ini}.png", vstacked)
```
Raw data
{
"_id": null,
"home_page": "https://github.com/hansalemaos/wrilytextaligner",
"name": "wrilytextaligner",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "text,align",
"author": "Johannes Fischer",
"author_email": "aulasparticularesdealemaosp@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/ee/fc/cc00c6e8adeabf208c737a5185f2eef9fa5976dd578b6ad3c47ef6da9749/wrilytextaligner-0.10.tar.gz",
"platform": null,
"description": "\r\n# Aligns text lines and characters within an image\r\n\r\n## Tested against Windows 10 / Python 3.11 / Anaconda\r\n\r\n## pip install wrilytextaligner\r\n\r\n## Original\r\n<img src=\"https://github.com/hansalemaos/screenshots/raw/main/16_2.png\"/>\r\n\r\n\r\n## Aligned\r\n<img src=\"https://github.com/hansalemaos/screenshots/raw/main/16_3.png\"/>\r\n\r\n\r\n\r\n```python\r\n\r\ni (Any): The input image or file path.\r\nblured_kernel (Tuple[int, int], optional): The kernel size for blurring the input image. Defaults to (5, 5).\r\nblured_dst (int, optional): The destination for the blurred image. Defaults to 0.\r\nadaptiveThreshold_max_value (int, optional): The maximum pixel value for the adaptive thresholding. Defaults to 255.\r\nadaptiveTreshold_method (int, optional): The adaptive thresholding method. Defaults to cv2.ADAPTIVE_THRESH_GAUSSIAN_C.\r\nadaptiveThreshold_block_size (int, optional): The block size for adaptive thresholding. Defaults to 11.\r\nadaptiveThreshold_C (int, optional): The constant subtracted from the mean in adaptive thresholding. Defaults to 2.\r\nrect_kernel_size (Tuple[int, int], optional): The kernel size for morphological operations. Defaults to (10, 10).\r\notsu_threshold (int, optional): The threshold value for Otsu's thresholding. Defaults to 0.\r\notsu_max_value (int, optional): The maximum pixel value for Otsu's thresholding. Defaults to 255.\r\nmax_line_join_distance (int, optional): The maximum distance for joining lines. Defaults to 30.\r\nborder_color_letters (Tuple[int, int, int], optional): The color of borders around characters. Defaults to (255, 255, 255).\r\nletter_border_top (int, optional): The top border size for characters. Defaults to 10.\r\nletter_border_bottom (int, optional): The bottom border size for characters. Defaults to 10.\r\nletter_border_right (int, optional): The right border size for characters. Defaults to 10.\r\nletter_border_left (int, optional): The left border size for characters. Defaults to 10.\r\nline_border_top (int, optional): The top border size for lines. Defaults to 10.\r\nline_border_bottom (int, optional): The bottom border size for lines. Defaults to 10.\r\nline_border_right (int, optional): The right border size for lines. Defaults to 10.\r\nline_border_left (int, optional): The left border size for lines. Defaults to 10.\r\nimage2crop (Union[None, np.ndarray], optional): An optional image to be cropped instead of the input image. Defaults to None.\r\n\r\n\r\n\r\nimport os, cv2\r\nimport numpy as np\r\nfrom wrilytextaligner import align_wrily_text\r\n\r\noutputfolder = r\"C:\\readx2\"\r\nif not os.path.exists(outputfolder):\r\n\tos.makedirs(outputfolder)\r\nfor ini, fi in enumerate(\r\n\t[r\"https://github.com/hansalemaos/screenshots/raw/main/16_2.png\"]\r\n):\r\n\tallines = align_wrily_text(\r\n\t\ti=fi,\r\n\t\tblured_kernel=(5, 5),\r\n\t\tblured_dst=0,\r\n\t\tadaptiveThreshold_max_value=255,\r\n\t\tadaptiveTreshold_method=cv2.ADAPTIVE_THRESH_GAUSSIAN_C,\r\n\t\tadaptiveThreshold_block_size=11,\r\n\t\tadaptiveThreshold_C=2,\r\n\t\trect_kernel_size=(8, 8),\r\n\t\totsu_threshold=0,\r\n\t\totsu_max_value=255,\r\n\t\tmax_line_join_distance=30,\r\n\t\tborder_color_letters=(255, 255, 255),\r\n\t\tletter_border_top=10,\r\n\t\tletter_border_bottom=10,\r\n\t\tletter_border_right=10,\r\n\t\tletter_border_left=10,\r\n\t\tline_border_top=10,\r\n\t\tline_border_bottom=10,\r\n\t\tline_border_right=10,\r\n\t\tline_border_left=10,\r\n\t\timage2crop=None,\r\n\t)\r\n\r\n\tvstacked = np.vstack(allines)\r\n\tcv2.imwrite(rf\"{outputfolder}\\{ini}.png\", vstacked)\r\n\r\n```\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Aligns text lines and characters within an image",
"version": "0.10",
"project_urls": {
"Homepage": "https://github.com/hansalemaos/wrilytextaligner"
},
"split_keywords": [
"text",
"align"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "2538d8bffe6f559fe00432917e5dfb32edd9792387cf11cf6e7ffebddc8e0a5a",
"md5": "88c6f372972168b046cc11ac2c48ad8b",
"sha256": "1fbf8097e668235309284f14870eb8333ebc33793779a3ef1e9561316eae989d"
},
"downloads": -1,
"filename": "wrilytextaligner-0.10-py3-none-any.whl",
"has_sig": false,
"md5_digest": "88c6f372972168b046cc11ac2c48ad8b",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 59220,
"upload_time": "2023-09-22T03:46:10",
"upload_time_iso_8601": "2023-09-22T03:46:10.845257Z",
"url": "https://files.pythonhosted.org/packages/25/38/d8bffe6f559fe00432917e5dfb32edd9792387cf11cf6e7ffebddc8e0a5a/wrilytextaligner-0.10-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "eefccc00c6e8adeabf208c737a5185f2eef9fa5976dd578b6ad3c47ef6da9749",
"md5": "8a1a46c431eb6d73973b88e41fecf5c2",
"sha256": "93df6c81430e26335730ee380f06dc27797f2888ef790311c819b2e442d3a808"
},
"downloads": -1,
"filename": "wrilytextaligner-0.10.tar.gz",
"has_sig": false,
"md5_digest": "8a1a46c431eb6d73973b88e41fecf5c2",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 58483,
"upload_time": "2023-09-22T03:46:12",
"upload_time_iso_8601": "2023-09-22T03:46:12.887504Z",
"url": "https://files.pythonhosted.org/packages/ee/fc/cc00c6e8adeabf208c737a5185f2eef9fa5976dd578b6ad3c47ef6da9749/wrilytextaligner-0.10.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-09-22 03:46:12",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "hansalemaos",
"github_project": "wrilytextaligner",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [],
"lcname": "wrilytextaligner"
}