Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
ocr4all-pixel-classifier-frontend
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ocr4all-page-segmentation
ocr4all-pixel-classifier-frontend
Commits
c9adfd5f
Commit
c9adfd5f
authored
Sep 16, 2020
by
Alexander Gehrke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add new commands for image maps
parent
dbe61c1e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
83 additions
and
0 deletions
+83
-0
ocr4all_pixel_classifier_frontend/convert_colors.py
ocr4all_pixel_classifier_frontend/convert_colors.py
+52
-0
ocr4all_pixel_classifier_frontend/inspect_image_map.py
ocr4all_pixel_classifier_frontend/inspect_image_map.py
+21
-0
ocr4all_pixel_classifier_frontend/main.py
ocr4all_pixel_classifier_frontend/main.py
+10
-0
No files found.
ocr4all_pixel_classifier_frontend/convert_colors.py
0 → 100644
View file @
c9adfd5f
import
argparse
import
functools
import
multiprocessing
import
os
from
ocr4all.image_map
import
ImageMap
from
tqdm
import
tqdm
def
main
():
parser
=
argparse
.
ArgumentParser
(
add_help
=
False
)
paths_args
=
parser
.
add_argument_group
(
"Paths"
)
paths_args
.
add_argument
(
"-i"
,
"--input-color-map"
,
type
=
str
,
required
=
True
,
help
=
"color mapping for the input images"
)
paths_args
.
add_argument
(
"-o"
,
"--output-color-map"
,
type
=
str
,
required
=
True
,
help
=
"desired output color mapping"
)
paths_args
.
add_argument
(
"-O"
,
"--output-dir"
,
type
=
str
,
required
=
True
,
help
=
"The output dir for the recolored masks"
)
paths_args
.
add_argument
(
"images"
,
metavar
=
"IMAGE"
,
type
=
str
,
nargs
=
"+"
,
help
=
"the images to convert"
)
opt_args
=
parser
.
add_argument_group
(
"optional arguments"
)
opt_args
.
add_argument
(
"-j"
,
"--jobs"
,
"--threads"
,
metavar
=
'THREADS'
,
dest
=
'threads'
,
type
=
int
,
default
=
multiprocessing
.
cpu_count
(),
help
=
"Number of threads to use"
)
opt_args
.
add_argument
(
"-h"
,
"--help"
,
action
=
"help"
,
help
=
"show this help message and exit"
)
args
=
parser
.
parse_args
()
in_map
=
ImageMap
.
load
(
args
.
input_color_map
)
out_map
=
ImageMap
.
load
(
args
.
output_color_map
)
os
.
makedirs
(
args
.
output_dir
,
exist_ok
=
True
)
convert_m
=
functools
.
partial
(
convert
,
outdir
=
args
.
output_dir
,
in_map
=
in_map
,
out_map
=
out_map
,
)
with
multiprocessing
.
Pool
(
processes
=
args
.
threads
)
as
p
:
for
_
in
tqdm
(
p
.
imap
(
convert_m
,
args
.
images
),
total
=
len
(
args
.
images
),
unit
=
"img"
):
pass
def
convert
(
img_path
,
outdir
,
in_map
:
ImageMap
,
out_map
:
ImageMap
):
labels
=
in_map
.
imread_labels
(
img_path
)
res
=
out_map
.
to_image
(
labels
)
res
.
save
(
os
.
path
.
join
(
outdir
,
os
.
path
.
basename
(
img_path
)))
if
__name__
==
'__main__'
:
main
()
ocr4all_pixel_classifier_frontend/inspect_image_map.py
0 → 100644
View file @
c9adfd5f
import
argparse
from
ocr4all.image_map
import
ImageMap
def
main
():
parser
=
argparse
.
ArgumentParser
(
add_help
=
False
)
parser
.
add_argument
(
'vars'
,
metavar
=
'IMAGEMAP'
,
type
=
str
,
nargs
=
'+'
,
help
=
'image map json files'
)
opt_args
=
parser
.
add_argument_group
(
"optional arguments"
)
opt_args
.
add_argument
(
"-h"
,
"--help"
,
action
=
"help"
,
help
=
"show this help message and exit"
)
args
=
parser
.
parse_args
()
for
imap
in
args
.
vars
:
map
=
ImageMap
.
load
(
imap
)
for
k
,
v
in
map
.
mapping
.
items
():
print
(
f
"
\x1b
[48;2;
{
k
[
0
]
}
;
{
k
[
1
]
}
;
{
k
[
2
]
}
m
\x1b
[0m
\x1b
[38;2;
{
k
[
0
]
}
;
{
k
[
1
]
}
;
{
k
[
2
]
}
m
{
v
}
\x1b
[0m
\n
"
)
if
__name__
==
'__main__'
:
main
()
ocr4all_pixel_classifier_frontend/main.py
View file @
c9adfd5f
...
...
@@ -34,6 +34,16 @@ commands = {
'main'
:
'main'
,
'help'
:
'Generates color map'
},
'inspect-image-map'
:
{
'script'
:
'ocr4all_pixel_classifier_frontend.inspect_image_map'
,
'main'
:
'main'
,
'help'
:
'Displays image map on a color-enabled terminal'
},
'convert-colors'
:
{
'script'
:
'ocr4all_pixel_classifier_frontend.convert_colors'
,
'main'
:
'main'
,
'help'
:
'Convert predictions or masks from one color mapping to another'
},
'migrate-model'
:
{
'script'
:
'ocr4all_pixel_classifier_frontend.migrate_model'
,
'main'
:
'main'
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment