Aligns text lines and characters within an image
Project description
Aligns text lines and characters within an image
Tested against Windows 10 / Python 3.11 / Anaconda
pip install wrilytextaligner
Original
Aligned
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)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
wrilytextaligner-0.10.tar.gz
(58.5 kB
view details)
Built Distribution
File details
Details for the file wrilytextaligner-0.10.tar.gz
.
File metadata
- Download URL: wrilytextaligner-0.10.tar.gz
- Upload date:
- Size: 58.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 93df6c81430e26335730ee380f06dc27797f2888ef790311c819b2e442d3a808 |
|
MD5 | 8a1a46c431eb6d73973b88e41fecf5c2 |
|
BLAKE2b-256 | eefccc00c6e8adeabf208c737a5185f2eef9fa5976dd578b6ad3c47ef6da9749 |
File details
Details for the file wrilytextaligner-0.10-py3-none-any.whl
.
File metadata
- Download URL: wrilytextaligner-0.10-py3-none-any.whl
- Upload date:
- Size: 59.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1fbf8097e668235309284f14870eb8333ebc33793779a3ef1e9561316eae989d |
|
MD5 | 88c6f372972168b046cc11ac2c48ad8b |
|
BLAKE2b-256 | 2538d8bffe6f559fe00432917e5dfb32edd9792387cf11cf6e7ffebddc8e0a5a |