Commit d6a92cbf authored by Robin Tissot's avatar Robin Tissot
Browse files

Merge branch 'develop'

parents 83ec1e1d 2983b057
# pull official base image
FROM python:3.7.5-stretch
FROM python:3.7.5-buster
# ARG KRAKEN_VERSION=3.0b5
# EXPOSE 8000
......
......@@ -340,7 +340,7 @@ class LineTranscriptionViewSet(DocumentPermissionMixin, ModelViewSet):
if serializer.is_valid():
try:
lt.new_version(author=request.user.username,
source=settings.VERSIONING_DEFAULT_SOURCE)
source=settings.VERSIONING_DEFAULT_SOURCE)
except NoChangeException:
pass
......
......@@ -23,6 +23,8 @@ def render_field(field, group=False, **kwargs):
tplt = template.loader.get_template('django/forms/widgets/field.html')
if 'class' in kwargs and 'class' in field.field.widget.attrs:
kwargs['class'] = field.field.widget.attrs['class'] + " " + kwargs['class']
if 'help_text' in kwargs:
field.help_text = kwargs.pop('help_text')
field.field.widget.attrs.update(**{k.replace('_', '-'): v
for k, v in kwargs.items()
......
......@@ -642,17 +642,16 @@ class DocumentPart(OrderedModel):
res = blla.segment(im, **options)
regs = []
if steps in ['regions', 'both']:
block_types = {t.name: t for t in self.document.valid_block_types.all()}
for region_type, regions in res['regions'].items():
for region in regions:
block = Block.objects.create(
Block.objects.create(
document_part=self,
typology=block_types.get(region_type),
box=region)
regs.append(block)
regions = self.blocks.all()
if steps in ['lines', 'both']:
line_types = {t.name: t for t in self.document.valid_line_types.all()}
for line in res['lines']:
......@@ -662,7 +661,7 @@ class DocumentPart(OrderedModel):
# calculate if the center of the line is contained in one of the region
# (pick the first one that matches)
center = LineString(baseline).interpolate(0.5, normalized=True)
region = next((r for r in regs if Polygon(r.box).contains(center)), None)
region = next((r for r in regions if Polygon(r.box).contains(center)), None)
Line.objects.create(
document_part=self,
......@@ -763,16 +762,22 @@ class DocumentPart(OrderedModel):
im = Image.open(self.image).convert('L')
lines = list(self.lines.all()) # needs to store the qs result
to_calc = [l for l in lines if (only and l.pk in only) or (only is None)]
context = [l for l in lines if only and l.pk not in only]
masks = calculate_polygonal_environment(im,
[l.baseline for l in to_calc],
suppl_obj=[l.baseline for l in context],
scale=(1200, 0))
ziped = zip(to_calc, masks)
for line, mask in ziped:
line.mask = mask
line.save()
for line in to_calc:
context = [l.baseline for l in lines if l.pk != line.pk]
if line.block:
poly = line.block.box
poly.append(line.block.box[0]) # close it
context.append(poly)
mask = calculate_polygonal_environment(
im,
[line.baseline],
suppl_obj=context,
scale=(1200, 0))
if mask[0]:
line.mask = mask[0]
line.save()
return to_calc
......
......@@ -10,7 +10,8 @@
{% if not import_form.current_import.ongoing %}
<h5>{% trans "Import images from a PDF document." %}</h5>
<div class="form-group">
{% render_field import_form.upload_file class="js-proc-settings" accept=".pdf" %}
{% trans "A single pdf with one image per page." as help_text %}
{% render_field import_form.upload_file class="js-proc-settings" accept=".pdf" help_text=help_text %}
</div>
{% endif %}
{% endblock %}
......
{% if not group %}<div class="form-group">{% endif %}
{% if field.field.widget.need_label %}<label class="my-1 mr-1" for="{{ field.name }}">{{ field.label }}</label>{% endif %}
{{ field }}
{% if not group %}
{% if field.help_text %}<small id="{{field.name}}Help" class="form-text text-muted">{{field.help_text|safe}}</small>{% endif %}
{% if field.field.widget.need_label %}<label class="my-1 mr-1" for="{{ field.name }}">{{ field.label }}</label>{% endif %}
{{ field }}
{% if not group %}
{% if field.help_text %}
<small id="{{field.name}}Help" class="form-text text-muted">
{{ field.help_text|safe }}
</small>
{% endif %}
{% for error in field.errors %}<div class="invalid-feedback">{{ error }}</div>{% endfor %}
</div>
{% endif %}
......@@ -12,7 +12,7 @@ django-redis==4.10.0
psycopg2-binary==2.7.6
django-ordered-model==3.1.1
easy-thumbnails==2.5
git+https://github.com/mittagessen/kraken.git@3.0b15#egg=kraken
git+https://github.com/mittagessen/kraken.git@3.0b16#egg=kraken
django-cleanup==3.0.1
djangorestframework==3.9.2
drf-nested-routers==0.91
......@@ -23,3 +23,4 @@ numpy>=1.17
django-compressor==2.4
albumentations
django-simple-captcha==0.5.12
pyvips==2.1.12
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