Skip to content

Commit

Permalink
Merge pull request #4 from mo-mo-666:develop
Browse files Browse the repository at this point in the history
v1.0.0b2
  • Loading branch information
mo-mo-666 committed Oct 23, 2020
2 parents 5c503ed + e30be8d commit a86dd13
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 30 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Adjust Scanned Images

![release](https://img.shields.io/github/v/release/mo-mo-666/adjust-scan-images?include_prereleases)
![build](https://github.com/mo-mo-666/adjust-scan-images/workflows/build/badge.svg)
![python](https://img.shields.io/badge/python-3.7|3.8-blue.svg)

## 必要なもの
Expand Down
6 changes: 3 additions & 3 deletions src/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import Union

from .setting_io import MarksheetResultWriter
from .setting_io_ds import read_metadata, read_marksheet_setting, decide_save_filepath
from .setting_io_ds import read_metadata, read_marksheet_setting, decide_save_filename
from .image_io import read_image, read_images, ImageSaver
from .align_images import ImageAligner
from .read_marksheet import MarkReader
Expand All @@ -24,7 +24,7 @@ def pipeline(
----------
img_dir : str
The name of the directory. We read the images in this directory.
metadata_path : str
metadata_path : None | str
The path of the metadata.
save_dir : str
The name of the directory. We save the processed images in this directory.
Expand Down Expand Up @@ -107,7 +107,7 @@ def pipeline(
v = None

# Set your customized filename
save_filename = decide_save_filepath(p, save_dir, v)
save_filename = decide_save_filename(p, save_dir, v)
save_filename = image_saver.save(save_filename, img, dpi)
logger.info(f"{p} -> {os.path.join(save_dir, save_filename)} saved.")
if is_marksheet:
Expand Down
5 changes: 4 additions & 1 deletion src/read_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ def read_args():
if not baseimg_path:
baseimg_paths = glob.glob(os.path.join(img_dir, "*"))
baseimg_paths = tuple(
sorted([p for p in baseimg_paths if os.path.splitext(p)[1] in img_ext])
sorted(
[p for p in baseimg_paths if os.path.splitext(p)[1] in img_ext],
key=lambda x: os.path.splitext(x)[0],
)
)
if not baseimg_paths:
print(f"{img_dir}に画像{img_ext}が存在しないため,処理を終了します。")
Expand Down
24 changes: 12 additions & 12 deletions src/setting_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@


SETTING_KEYS_DEFAULT = {
"resize_ratio": 1,
"coord_unit": "px",
"is_align": 1,
"marker_range": 200,
"marker_gaussian_ksize": 15,
"marker_gaussian_std": 3,
"is_marksheet": 1,
"is_marksheet_fit": 1,
"sheet_coord_style": "circle",
"sheet_score_threshold": 0,
"sheet_gaussian_ksize": 15,
"sheet_gaussian_std": 3,
"resize_ratio": 1, # float 0 < resize_ratio <= 1.
"coord_unit": "pt", # "pt" | "px"
"is_align": 1, # 0 | 1
"marker_range": 200 / 300 * 72, # float, px
"marker_gaussian_ksize": 15, # int
"marker_gaussian_std": 3, # int
"is_marksheet": 1, # 0 | 1
"is_marksheet_fit": 1, # 0 | 1
"sheet_coord_style": "bbox", # "rect" | "bbox" | "circle"
"sheet_score_threshold": 0, # float
"sheet_gaussian_ksize": 15, # int
"sheet_gaussian_std": 3, # int
}


Expand Down
47 changes: 33 additions & 14 deletions src/setting_io_ds.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
logger = logging.getLogger("adjust-scan-images")

SETTING_KEYS_DEFAULT = {
"resize_ratio": 1,
"coord_unit": "pt",
"is_align": 1,
"marker_range": 200 / 300 * 72,
"marker_gaussian_ksize": 15,
"marker_gaussian_std": 3,
"is_marksheet": 1,
"is_marksheet_fit": 1,
"sheet_coord_style": "bbox",
"sheet_score_threshold": 0,
"sheet_gaussian_ksize": 15,
"sheet_gaussian_std": 3,
"resize_ratio": 1, # float 0 < resize_ratio <= 1.
"coord_unit": "pt", # "pt" | "px"
"is_align": 1, # 0 | 1
"marker_range": 200 / 300 * 72, # float, "coord_unit" style.
"marker_gaussian_ksize": 15, # int
"marker_gaussian_std": 3, # int
"is_marksheet": 1, # 0 | 1
"is_marksheet_fit": 1, # 0 | 1
"sheet_coord_style": "bbox", # "rect" | "bbox" | "circle"
"sheet_score_threshold": 0, # float
"sheet_gaussian_ksize": 15, # int
"sheet_gaussian_std": 3, # int
}

MARK_CATEGORIES = ("room", "class", "student_number_10", "student_number_1")
Expand Down Expand Up @@ -103,6 +103,25 @@ def read_marksheet_setting(
*args,
**kargs,
) -> dict:
"""
Read marksheet setting.
Parameters
----------
filepath : Union[None, str]
Setting file path.
scale : float, optional
Resize ratio of images., by default 1
categories : Union[None, Iterable[str]], optional
Categories of marksheet, by default MARK_CATEGORIES
pt2px : Union[None, float], optional
The scale of pt -> px, by default None
Returns
-------
dict
Marksheet data.
"""
if not filepath or not categories:
return {}
wb = load_workbook(filepath, read_only=True, data_only=True)
Expand Down Expand Up @@ -130,7 +149,7 @@ def read_marksheet_setting(
return marks


def decide_save_filepath(
def decide_save_filename(
read_path: str, save_dir: str, data: Union[dict, None] = None
) -> str:
"""
Expand All @@ -148,7 +167,7 @@ def decide_save_filepath(
Returns
-------
str
Save file path.
Save file name.
"""
read_filename = os.path.basename(read_path)
read_dir = os.path.basename(os.path.dirname(read_path))
Expand Down

0 comments on commit a86dd13

Please sign in to comment.