Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix alpha shape #87

Open
wants to merge 87 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
bd61cc6
recognize: try to self.resolve_resource model
kba Jan 28, 2021
db584d8
resegment: fix method=baseline
bertsky Mar 11, 2022
56affe2
resegment: join_polygons: allow non-contiguous input, too
bertsky Mar 11, 2022
b856f5b
resegment: join_polygons: make equidistant points relative to estimat…
bertsky Mar 11, 2022
d75e58d
update to shapely 1.8
bertsky Mar 25, 2022
6a06f36
fix Workspace.save_image_file args
bertsky Mar 19, 2022
2cdfa79
revert e673544 (crashes OpenCV)
bertsky Mar 24, 2022
8f6cfc5
segment: annotate baselines, too
bertsky Mar 18, 2022
b50c51b
segment: fix lines2regions non-continguous partitions
bertsky Apr 6, 2022
c4eaf3d
re/segment: alpha shape: smaller α to avoid holes
bertsky Apr 6, 2022
8b0e7b8
resegment (ccomps/baseline): propagate/spread twice to catch diacriti…
bertsky Apr 6, 2022
0f359d0
resegment: if method=lineest, then annotate baselines, too
bertsky Apr 6, 2022
b3018eb
ocrd-tool.json: typo cr{,e}ate
kba Apr 7, 2022
97af16c
segment: rewrite separator detection…
bertsky Apr 12, 2022
c10b692
segment: for more robust bg separator detection, combine criteria of …
bertsky Apr 12, 2022
7893615
remove Calamari dependency (not used, only CLI callout)
bertsky Apr 28, 2022
ca15800
join_polygons (alpha shape): make more robust
bertsky Apr 28, 2022
b490d3f
re/segment: join_polygons directly instead of alphashape
bertsky Jun 8, 2022
2bc033c
re/segment: sort text lines in reading order
bertsky Jun 8, 2022
956f4a3
baseline extraction: partition by finding largest cliques
bertsky Jun 8, 2022
62d0729
sepline detection linking: partition by finding largest cliques
bertsky Jun 8, 2022
ff326ca
sepline detection linking: filter results entirely composed by tiny c…
bertsky Jun 8, 2022
65eee88
sepline detection masking: spread against bg and non-separator fg
bertsky Jun 8, 2022
8127613
ocropy.lines2region: improve splitting by separators (fix 6d8c0d36)
bertsky Jun 8, 2022
2849464
ocrolib.morph.all_neighbors: no diagonals
bertsky Jun 8, 2022
4d7a083
sepline detection polygonization: cut inner holes open
bertsky Jun 9, 2022
c90b29f
re/segment: join_polygons: fix b490d3f8 imports
bertsky Jun 9, 2022
2ec107e
re/segment: join_polygons: connect touching neighbours, too
bertsky Mar 25, 2023
b2aba78
re/segment: join_baselines: for complex subtypes, apply recursively
bertsky Mar 25, 2023
77d60ca
re/segment: join_baselines: skip lines outside of polygon
bertsky Mar 25, 2023
8c986be
re/segment: improve polygon simplification
bertsky Mar 25, 2023
0acc6f2
resegment: list instead of generator
bertsky Mar 25, 2023
38206f0
adapt to Numpy 1.24 dtypes
bertsky Mar 25, 2023
6eed14c
adapt to Shapely 2.0 deprecations
bertsky Mar 25, 2023
2bf18e0
check_page: double max page size to 20k by 20k pixels
kba Apr 14, 2023
cd08aab
check_page/region/line: skip assumptions on number of components
bertsky May 30, 2023
70b2191
resegment: add param baseline_only
bertsky May 30, 2023
35227a9
resegment (baseline/ccomps): improve handling of fg conflicts
bertsky May 30, 2023
1abc3b7
segment: adapt to OpenCV changes
bertsky Jun 2, 2023
265b284
Merge branch 'kba:resolve-resources' #83 into fix-alpha-shape
bertsky Jun 7, 2023
6fd1b3e
Merge branch 'kba:double-page-max-size' #96 into fix-alpha-shape
bertsky Jun 7, 2023
a0ea0a2
Merge branch 'kba:typo' #91 into fix-alpha-shape
bertsky Jun 7, 2023
4c55422
ocrd-tool: rm old ocrd-cis-ocropy-rec (gone in 9e20991)
bertsky Jun 21, 2023
4c9ad27
ocropy-train: improve/update OCR-D wrapper…
bertsky Jun 21, 2023
43a356a
postcorrect: improve/update OCR-D wrapper…
bertsky Jun 22, 2023
2783f61
segment: fix baseline extraction
bertsky Jul 11, 2023
fcc02fd
adapt to Numpy and Pillow deprecations
bertsky Aug 17, 2023
1512c81
Remove testing from Dockerfile
joschrew Feb 1, 2024
67905d7
Add metadata to Dockerfile
joschrew Feb 9, 2024
d5e8187
Set docker metadata with makefile
joschrew Feb 12, 2024
320d5fd
try to fix tests by adapting URLs
bertsky Feb 12, 2024
1ee6442
add CircleCI config
bertsky Feb 12, 2024
a4dc20f
Update CircleCI config
joschrew Feb 13, 2024
c4f0724
Another try to fix tests
joschrew Feb 13, 2024
71e4e50
Debug circleci tests
joschrew Feb 13, 2024
1b50295
tests: use proper new OCR-D GT URL
bertsky Feb 13, 2024
f214c59
tests: reuse downloaded bag files
bertsky Feb 14, 2024
68dcb90
ocrolib.common.load_object: find ocrolib in sys.path
bertsky Feb 14, 2024
4f3ea7c
postcorrect: adapt processor to new OCR-D (mets:file with @LOCTYPE an…
bertsky Feb 14, 2024
84e3acf
test_lib: update to fixed GT repo URL, don't remove workspace on failure
bertsky Feb 14, 2024
5e06603
tests: use downloadable recognizer models throughout, simplify scripts
bertsky Feb 14, 2024
05895c9
tests: deactivate training (broken)
bertsky Feb 14, 2024
29e6e3a
makefile: allow setting different tag for docker build
bertsky Feb 14, 2024
07662f2
CI: add CD
bertsky Feb 14, 2024
1d2e858
Merge pull request #4 from joschrew/update-dockerfile
bertsky Feb 14, 2024
4673d9b
re/segment join_polygons: fix rare case of adjacent rings
bertsky Apr 25, 2024
338b840
re/segment join_baselines: adapt to Shapely, improve
bertsky Apr 25, 2024
d2a5279
resegment (lineest): fix/improve matching
bertsky Apr 25, 2024
8a71d8e
resegment (lineest): use new polygons instead of intersections but ig…
bertsky Apr 25, 2024
6e95b38
tests: update data_url (after force-push upstream)
bertsky May 6, 2024
b6c8957
resegment: expose parameter spread (analogous to segment)
bertsky May 29, 2024
3346b4e
test assets: workaround for core#1189 / gt_structure_text#2
bertsky May 29, 2024
38ce45b
CircleCI: install JRE
bertsky May 30, 2024
8d65708
resegment: fix 2 edge cases
bertsky Jul 5, 2024
eb4efe1
ocrd-tool.json: add Ocropy default model resources
bertsky Jul 5, 2024
842b4c2
docker: adapt to core using /build already
bertsky Jul 5, 2024
53ae7d6
use importlib instead of pkg_resources via ocrd_utils
bertsky Jul 5, 2024
fed84da
fix 53ae7d69 (already str not bytes)
bertsky Jul 31, 2024
5282092
recognize: replace python-levenshtein with rapidfuzz
bertsky Jul 31, 2024
a382d6f
fix+update dockerfile
bertsky Jul 31, 2024
039e052
test_lib.bash: update GT Github URL
bertsky Aug 16, 2024
83ba2f0
CI: try testing in parallel
bertsky Aug 16, 2024
a2100c2
Updated config.yml
bertsky Aug 16, 2024
fe122ae
segment: adapt to numpy deprecation
bertsky Sep 26, 2024
56eaca7
fix: levenshtein import
MehmedGIT Oct 10, 2024
ca08c1a
eval/stats: Levenshtein -> rapidfuzz.distance.Levenshtein
kba Oct 11, 2024
db65d7f
Merge pull request #6 from MehmedGIT/fix-align-import-levenshtein
bertsky Oct 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
version: 2.1
jobs:
test-python3:
docker:
- image: ocrd/core
resource_class: large
environment:
PIP: pip3
PYTHON: python3
steps:
- checkout
- run: apt-get update && apt-get -y install default-jre-headless
- run: make install
- run: make -j test V=""

deploy-docker:
docker:
- image: circleci/buildpack-deps:stretch
environment:
DOCKER_TAG: ocrd/cis
steps:
- checkout
- setup_remote_docker: # https://circleci.com/docs/2.0/building-docker-images/
docker_layer_caching: true
- run: make docker-build TAG=$DOCKER_TAG
- run:
name: Login to Docker Hub
command: echo "$DOCKERHUB_PASS" | docker login --username "$DOCKERHUB_USER" --password-stdin
- run: docker push $DOCKER_TAG

workflows:
version: 2
build-and-test:
jobs:
- test-python3
deploy:
jobs:
- deploy-docker:
filters:
branches:
only:
- master
- fix-alpha-shape
41 changes: 26 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
FROM ocrd/core:latest AS base
ENV VERSION="Di 12. Mai 13:26:35 CEST 2020"
FROM ocrd/core:v2.67.2 AS base
ARG VCS_REF
ARG BUILD_DATE
LABEL \
maintainer="https://github.com/OCR-D/ocrd_cis/issues" \
org.label-schema.vcs-ref=$VCS_REF \
org.label-schema.vcs-url="https://github.com/OCR-D/ocrd_cis" \
org.label-schema.build-date=$BUILD_DATE

ENV GITURL="https://github.com/cisocrgroup"
ENV DOWNLOAD_URL="http://cis.lmu.de/~finkf"

SHELL ["/bin/bash", "-c"]

# deps
RUN apt-get update \
&& apt-get -y install --no-install-recommends locales
Expand All @@ -16,14 +25,14 @@ RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen \
FROM base AS profiler
RUN apt-get update \
&& apt-get -y install --no-install-recommends cmake g++ libcppunit-dev libxerces-c-dev \
&& git clone ${GITURL}/Profiler --branch devel --single-branch /build \
&& cd /build \
&& git clone ${GITURL}/Profiler --branch devel --single-branch /build/Profiler \
&& pushd /build/Profiler \
&& cmake -DCMAKE_BUILD_TYPE=release . \
&& make compileFBDic trainFrequencyList runDictSearch profiler \
&& mkdir /apps \
&& cp bin/compileFBDic bin/trainFrequencyList bin/profiler bin/runDictSearch /apps/ \
&& cd / \
&& rm -rf /build
&& popd \
&& rm -rf /build/Profiler

FROM profiler AS languagemodel
# install the profiler's language backend
Expand All @@ -32,13 +41,13 @@ COPY --from=profiler /apps/trainFrequencyList /apps/
COPY --from=profiler /apps/runDictSearch /apps/
RUN apt-get update \
&& apt-get -y install --no-install-recommends icu-devtools \
&& git clone ${GITURL}/Resources --branch master --single-branch /build \
&& cd /build/lexica \
&& git clone ${GITURL}/Resources --branch master --single-branch /build/Resources \
&& pushd /build/Resources/lexica \
&& PATH=$PATH:/apps make \
&& PATH=$PATH:/apps make test \
&& PATH=$PATH:/apps make install \
&& cd / \
&& rm -rf /build
&& popd \
&& rm -rf /build/Resources

FROM base AS postcorrection
# install ocrd_cis (python)
Expand All @@ -48,11 +57,13 @@ COPY --from=profiler /apps/profiler /apps/
COPY --from=profiler /usr/lib/x86_64-linux-gnu/libicuuc.so /usr/lib//x86_64-linux-gnu/
COPY --from=profiler /usr/lib/x86_64-linux-gnu/libicudata.so /usr/lib//x86_64-linux-gnu/
COPY --from=profiler /usr/lib//x86_64-linux-gnu/libxerces-c-3.2.so /usr/lib//x86_64-linux-gnu/
COPY . /build
COPY . /build/ocrd_cis
RUN apt-get update \
&& apt-get -y install --no-install-recommends gcc wget default-jre-headless \
&& cd /build \
&& pushd /build/ocrd_cis \
&& make install \
&& make test \
&& cd / \
&& rm -rf /build
# test always fail, resources not available for download. Resources should be made available
# somewhere else, e.g. github.com/OCR-D/assets
# && make test \
&& popd \
&& rm -rf /build/ocrd_cis
14 changes: 9 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ PY ?= python3
PIP ?= pip3
V ?= > /dev/null 2>&1
PKG = ocrd_cis
TAG = flobar/ocrd_cis

install:
${PIP} install --upgrade pip .
Expand All @@ -11,14 +12,17 @@ uninstall:
${PIP} uninstall ${PKG}

docker-build: Dockerfile
docker build -t flobar/ocrd_cis:latest .
docker build \
--build-arg VCS_REF=$$(git rev-parse --short HEAD) \
--build-arg BUILD_DATE=$$(date -u +"%Y-%m-%dT%H:%M:%SZ") \
-t $(TAG):latest .
docker-push: docker-build
docker push flobar/ocrd_cis:latest
docker push $(TAG):latest

TEST_SCRIPTS=$(sort $(wildcard tests/run_*.bash))
TEST_SCRIPTS=$(sort $(filter-out tests/run_training_test.bash, $(wildcard tests/run_*.bash)))
.PHONY: $(TEST_SCRIPTS)
$(TEST_SCRIPTS):
bash $@ $V
test: $(TEST_SCRIPTS)
echo $^
.PHONY: install test
@echo $^
.PHONY: install install-devel uninstall test docker-build docker-push
2 changes: 1 addition & 1 deletion ocrd_cis/align/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import click
import json
import os
import Levenshtein
from rapidfuzz.distance import Levenshtein
from ocrd import Processor
from ocrd.decorators import ocrd_cli_options
from ocrd.decorators import ocrd_cli_wrap_processor
Expand Down
2 changes: 1 addition & 1 deletion ocrd_cis/div/cutter.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def bounding_box(coord_points):
def resize_keep_ratio(image, baseheight=48):
hpercent = (baseheight / float(image.size[1]))
wsize = int((float(image.size[0] * float(hpercent))))
image = image.resize((wsize, baseheight), Image.ANTIALIAS)
image = image.resize((wsize, baseheight), Image.LANCZOS)
return image


Expand Down
2 changes: 1 addition & 1 deletion ocrd_cis/div/eval.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
from PIL import Image
from Levenshtein import distance
from rapidfuzz.distance.Levenshtein import distance


path = '/mnt/c/Users/chris/Documents/projects/OCR-D/daten/gt/lines/'
Expand Down
4 changes: 2 additions & 2 deletions ocrd_cis/div/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from ocrd import Processor
from ocrd_cis import get_ocrd_tool
from ocrd_models.ocrd_page_generateds import parse
from Levenshtein import distance
from rapidfuzz.distance import Levenshtein


class Stats(Processor):
Expand Down Expand Up @@ -81,7 +81,7 @@ def process(self):
# print(line.get_TextEquiv()[2].dataType)
unicodeline = line.get_TextEquiv()[i].Unicode

d[i] += distance(gtline, unicodeline)
d[i] += Levenshtein.distance(gtline, unicodeline)

# words = line.get_Word()
# for word in words:
Expand Down
71 changes: 46 additions & 25 deletions ocrd_cis/ocrd-tool.json
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@
"output_file_grp": [
"OCR-D-SEG-LINE"
],
"description": "Resegment text lines",
"description": "Improve coordinates of text lines",
"parameters": {
"level-of-operation": {
"type": "string",
Expand All @@ -205,6 +205,11 @@
"description": "source for new line polygon candidates ('lineest' for line estimation, i.e. how Ocropy would have segmented text lines; 'baseline' tries to re-polygonize from the baseline annotation; 'ccomps' avoids crossing connected components by majority rule)",
"default": "lineest"
},
"baseline_only": {
"type": "boolean",
"description": "ignore existing textline coords completely and use baseline as input if possible",
"default": false
},
"dpi": {
"type": "number",
"format": "float",
Expand All @@ -217,10 +222,16 @@
"description": "share of foreground pixels that must be retained by the output polygons",
"default": 0.75
},
"spread": {
"type": "number",
"format": "float",
"description": "distance in points (pt) from the foreground to project textline labels into the background for polygonal contours; if zero, project half a scale/capheight",
"default": 2.4
},
"extend_margins": {
"type": "number",
"format": "integer",
"description": "number of pixels to extend the input polygons in all directions",
"description": "(ignored)",
"default": 3
}
}
Expand Down Expand Up @@ -293,29 +304,37 @@
},
"model": {
"type": "string",
"description": "ocropy model to apply (e.g. fraktur.pyrnn)"
"format": "uri",
"content-type": "application/gzip",
"description": "ocropy model to apply (e.g. fraktur.pyrnn.gz)"
}
}
},
"ocrd-cis-ocropy-rec": {
"executable": "ocrd-cis-ocropy-rec",
"categories": [
"Text recognition and optimization"
],
"steps": [
"recognition/text-recognition"
],
"input_file_grp": [
"OCR-D-GT-SEG-BLOCK",
"OCR-D-SEG-BLOCK"
],
"description": "Recognize text snippets",
"parameters": {
"model": {
"type": "string",
"description": "ocropy model to apply (e.g. fraktur.pyrnn)"
},
"resources": [
{
"url": "https://github.com/zuphilip/ocropy-models/raw/master/en-default.pyrnn.gz",
"name": "en-default.pyrnn.gz",
"description": "Default ocropy model for English",
"size": 83826134
},
{
"url": "https://github.com/zuphilip/ocropy-models/raw/master/fraktur.pyrnn.gz",
"name": "fraktur.pyrnn.gz",
"description": "Default ocropy fraktur model",
"size": 43882365
},
{
"url": "https://github.com/jze/ocropus-model_fraktur/raw/master/fraktur.pyrnn.gz",
"name": "fraktur-jze.pyrnn.gz",
"description": "ocropy fraktur model by github.com/jze",
"size": 2961298
},
{
"url": "https://github.com/chreul/OCR_Testdata_EarlyPrintedBooks/raw/master/LatinHist-98000.pyrnn.gz",
"name": "LatinHist.pyrnn.gz",
"description": "ocropy historical latin model by github.com/chreul",
"size": 16989864
}
}
]
},
"ocrd-cis-ocropy-segment": {
"executable": "ocrd-cis-ocropy-segment",
Expand Down Expand Up @@ -433,13 +452,15 @@
"parameters": {
"textequiv_level": {
"type": "string",
"description": "PAGE XML hierarchy level granularity",
"description": "hierarchy level to extract GT pairs from",
"enum": ["line", "word", "glyph"],
"default": "line"
},
"model": {
"type": "string",
"description": "load model or crate new one (e.g. fraktur.pyrnn)"
"format": "uri",
"content-type": "application/gzip",
"description": "load model (e.g. 'fraktur.pyrnn.gz') to init weights, or none to train from scratch"
},
"ntrain": {
"type": "number",
Expand Down
5 changes: 2 additions & 3 deletions ocrd_cis/ocrd_tool.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import json
from pkg_resources import resource_string
from ocrd_utils import resource_string


def get_ocrd_tool():
return json.loads(
resource_string(__name__, 'ocrd-tool.json').decode('utf8'))
return json.loads(resource_string(__name__, 'ocrd-tool.json'))
18 changes: 6 additions & 12 deletions ocrd_cis/ocropy/binarize.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,8 @@ def process_page(self, page, page_image, page_xywh, zoom, page_id, file_id):
file_id += '.IMG-BIN'
features += ',binarized'
file_path = self.workspace.save_image_file(
bin_image,
file_id,
page_id=page_id,
file_grp=self.output_file_grp)
bin_image, file_id, self.output_file_grp,
page_id=page_id)
# update PAGE (reference the image file):
page.add_AlternativeImage(AlternativeImageType(
filename=file_path,
Expand Down Expand Up @@ -263,10 +261,8 @@ def process_region(self, region, region_image, region_xywh, zoom, page_id, file_
file_id += '.IMG-BIN'
features += ',binarized'
file_path = self.workspace.save_image_file(
bin_image,
file_id,
page_id=page_id,
file_grp=self.output_file_grp)
bin_image, file_id, self.output_file_grp,
page_id=page_id)
# update PAGE (reference the image file):
region.add_AlternativeImage(AlternativeImageType(
filename=file_path,
Expand Down Expand Up @@ -306,10 +302,8 @@ def process_line(self, line, line_image, line_xywh, zoom, page_id, region_id, fi
file_id += '.IMG-BIN'
features += ',binarized'
file_path = self.workspace.save_image_file(
bin_image,
file_id,
page_id=page_id,
file_grp=self.output_file_grp)
bin_image, file_id, self.output_file_grp,
page_id=page_id)
# update PAGE (reference the image file):
line.add_AlternativeImage(AlternativeImageType(
filename=file_path,
Expand Down
6 changes: 2 additions & 4 deletions ocrd_cis/ocropy/clip.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,8 @@ def process_segment(self, segment, segment_mask, segment_polygon, neighbours,
segment_image = crop_image(segment_image,box=segment_bbox)
# update METS (add the image file):
file_path = self.workspace.save_image_file(
segment_image,
file_id=file_id + '.IMG-CLIP',
page_id=page_id,
file_grp=self.output_file_grp)
segment_image, file_id + '.IMG-CLIP', self.output_file_grp,
page_id=page_id)
# update PAGE (reference the image file):
segment.add_AlternativeImage(AlternativeImageType(
filename=file_path,
Expand Down
Loading