Commit 413a2710 authored by njean42's avatar njean42
Browse files

Right-to-left panel numbering on request.

parent f632059f
......@@ -69,7 +69,7 @@ Also check the [testing doc](doc/Testing.md) if you want to test modified versio
# Numbering
The numbering is left to right, top to bottom for now (see roadmap).
The numbering is left-to-right, or right-to-left if requested.
Here is an example of how *Kumiko* is going to number panels by default (numbers and red lines not in the original picture).
......@@ -95,7 +95,6 @@ If you have ideas on how to programmatically guess the background color of a pag
* be able to detect panel contours on pages with **non-white background**
* implies being able to determine the background color: histogram, probing of some kind? (worst case: manually?)
* provide an option for **right-to-left numbering**, critical e.g. for mangas
## Back-office (validation / edition tool)
......
......@@ -37,15 +37,13 @@ The *size* gives us the *[width,height]* of our image, in pixels.
The panel details are also expressed in pixels.
The 4 values representing a panel are given in the following order: **[x,y,width,height]**, with *x* and *y* representing the **top-left corner** of the panel.
Panels are sorted in left-to-right reading order by default.
Add the `--rtl` option to have them sorted in right-to-left reading order (e.g. mangas).
Note that, although Kumiko can detect panels with arbitrary shapes, it will return a rectangular bounding box for each one.
This is because in the end, many things are rectangular: image files, our screens to display them...
We may want an option in the future to get more accurate polygons instead.
### File names
The `filename`s in our JSON object are relative to the working directory from which we invoked the `./kumiko` command.
## Get panel information for all pages in one comic book
kumiko -i /path/to/comicbook/
......
......@@ -8,13 +8,10 @@ from lib.html import HTML
parser = argparse.ArgumentParser(description='Kumiko CLI')
# Utilities
parser.add_argument('--debug-dir', nargs=1, help='Write debug files in this directory (image files with extra panel information and more)')
parser.add_argument('--progress', action='store_true', help='Prints progress information')
# Input/Output
parser.add_argument('-i', '--input', nargs='+', required=True, help='A file or folder name to parse')
parser.add_argument('-o', '--output', nargs=1, help='A file name to save json/html output to')
parser.add_argument('--rtl', action='store_true', help='Pass this option to number panels right-to-left')
# HTML reader page options
parser.add_argument('-b', '--browser', nargs=1, help='Opens given browser to read your comic page(s) panel-by-panel! (implies --html)', choices=['firefox','konqueror','chromium'])
......@@ -24,12 +21,17 @@ parser.add_argument('--html-static-dir', nargs=1, help='When generating HTML, th
# Configuration tweaks
parser.add_argument('--min-panel-size-ratio', nargs=1, type=float, help='Panels will be considered too small and exluded if they have a width < img.width * ratio or height < img/height * ratio (default is 1/15th)')
# Utilities
parser.add_argument('--debug-dir', nargs=1, help='Write debug files in this directory (image files with extra panel information and more)')
parser.add_argument('--progress', action='store_true', help='Prints progress information')
args = parser.parse_args()
k = Kumiko({
'debug_dir': args.debug_dir[0] if args.debug_dir else False,
'progress': args.progress,
'rtl': args.rtl,
'min_panel_size_ratio': args.min_panel_size_ratio[0] if args.min_panel_size_ratio else False
})
......
......@@ -20,8 +20,11 @@ class Kumiko:
def __init__(self,options={}):
self.options['debug_dir'] = 'debug_dir' in options and options['debug_dir']
self.options['progress'] = 'progress' in options and options['progress']
for o in ['debug_dir','progress','rtl']:
self.options[o] = o in options and options[o]
if self.options['rtl']:
Panel.set_numbering('rtl')
self.options['min_panel_size_ratio'] = 1/15
if 'min_panel_size_ratio' in options and options['min_panel_size_ratio']:
......
......@@ -6,6 +6,14 @@ import numpy as np
class Panel:
numbering = 'ltr' # left-to-right by default
def set_numbering(numbering):
if not (numbering in ['ltr','rtl']):
raise Exception('Fatal error, unknown numbering: '+str(numbering))
Panel.numbering = numbering
def __init__(self, xywh=None, polygon=None):
if xywh is None and polygon is None:
raise Exception('Fatal error: no parameter to define Panel boundaries')
......@@ -42,11 +50,11 @@ class Panel:
# panel is left from other
if other.x >= self.r - self.wt and other.x >= self.x - self.wt:
return True
return True if Panel.numbering == 'ltr' else False
# panel is right from other
if self.x >= other.r - self.wt and self.x >= other.x - self.wt:
return False
return False if Panel.numbering == 'ltr' else True
return True # should not happen, TODO: raise an exception?
......@@ -65,9 +73,9 @@ class Panel:
# update width and height
if name in ['x','y','r','b']:
super().__setattr__('w',self.r - self.x)
super().__setattr__('wt',self.w / 10)
super().__setattr__('wt',self.w / 10) # wt = width threshold (under which two edge coordinates are considered equal)
super().__setattr__('h',self.b - self.y)
super().__setattr__('ht',self.h / 10)
super().__setattr__('ht',self.h / 10) # ht = height threshold
def overlap_panel(self,other):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment