Skip to content

Commit

Permalink
resolved merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Jenckel committed Oct 31, 2019
2 parents 6bf4020 + 26faa50 commit 44247ab
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 134 deletions.
5 changes: 1 addition & 4 deletions ocrd_anybaseocr/cli/ocrd_anybaseocr_binarize.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,6 @@ def process(self):

for (n, input_file) in enumerate(self.input_files):
page_id = input_file.pageId or input_file.ID
# if input_file.pageId is None:
# continue
# page_id = input_file.pageId

LOG.info("INPUT FILE %i / %s", n, page_id)
pcgts = page_from_file(self.workspace.download_file(input_file))
Expand Down Expand Up @@ -159,7 +156,6 @@ def _process_segment(self,page_image, page, page_xywh, page_id, input_file, n):
if len(raw.shape) > 2:
raw = np.mean(raw, 2)
raw = raw.astype("float64")

# perform image normalization
image = raw-amin(raw)
if amax(image) == amin(image):
Expand Down Expand Up @@ -255,3 +251,4 @@ def _process_segment(self,page_image, page, page_xywh, page_id, input_file, n):
file_grp=self.image_grp
)
page.add_AlternativeImage(AlternativeImageType(filename=file_path, comments=page_xywh['features']))

8 changes: 2 additions & 6 deletions ocrd_anybaseocr/cli/ocrd_anybaseocr_cropping.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,12 +424,8 @@ def process(self):
self.image_grp = FALLBACK_IMAGE_GRP
LOG.info("No output file group for images specified, falling back to '%s'", FALLBACK_IMAGE_GRP)
oplevel = self.parameter['operation_level']

for (n, input_file) in enumerate(self.input_files):
page_id = input_file.pageId or input_file.ID
#if input_file.mimetype =="image/png":
# continue
#page_id = input_file.pageId

LOG.info("INPUT FILE %i / %s", n, page_id)

Expand Down Expand Up @@ -463,6 +459,7 @@ def process(self):
LOG.warning('Operation level %s, but should be "page".', oplevel)
break
file_id = input_file.ID.replace(self.input_file_grp, self.output_file_grp)

# Use input_file's basename for the new file -
# this way the files retain the same basenames:
if file_id == input_file.ID:
Expand Down Expand Up @@ -500,7 +497,6 @@ def _process_segment(self,page_image, page, page_xywh, page_id, input_file, n):
img_array_rr)
self.parameter['colSeparator'] = int(
width * self.parameter['colSeparator'])

if len(textarea) > 1:
textarea = self.crop_area(
textarea, img_array_bin, img_array_rr_ta)
Expand All @@ -517,7 +513,6 @@ def _process_segment(self,page_image, page, page_xywh, page_id, input_file, n):
y1 = y1-40 if y1 > 40 else 0
y2 = y2+40 if y2 < height-40 else height

#self.save_pf(base, [x1, y1, x2, y2])
min_x, min_y, max_x, max_y = textarea[0]
else:
min_x, min_y, max_x, max_y = self.select_borderLine(
Expand All @@ -540,3 +535,4 @@ def _process_segment(self,page_image, page, page_xywh, page_id, input_file, n):
file_grp=self.image_grp
)
page.add_AlternativeImage(AlternativeImageType(filename=file_path, comments=page_xywh['features']))

4 changes: 0 additions & 4 deletions ocrd_anybaseocr/cli/ocrd_anybaseocr_deskew.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,7 @@ def process(self):
oplevel = self.parameter['operation_level']

for (n, input_file) in enumerate(self.input_files):
#file_id = input_file.ID.replace(self.input_file_grp, self.image_grp)
page_id = input_file.pageId or input_file.ID
#if input_file.mimetype !="image/png":
# continue
#page_id = input_file.pageId

LOG.info("INPUT FILE %i / %s", n, page_id)
pcgts = page_from_file(self.workspace.download_file(input_file))
Expand Down
120 changes: 0 additions & 120 deletions ocrd_anybaseocr/cli/ocrd_anybaseocr_dewarp.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,124 +168,4 @@ def _process_segment(self, model, dataset, page, page_xywh, page_id, input_file,
)
page.add_AlternativeImage(AlternativeImageType(filename=file_path, comments=page_xywh['features']))
































# import torch
# import sys
# import os
# import shutil

# from ..constants import OCRD_TOOL

# from ocrd import Processor

# from ocrd_models.ocrd_page import parse
# from ocrd_utils import getLogger, concat_padded
# from ocrd_modelfactory import page_from_file
# from ocrd_models.ocrd_page import to_xml,parse
# import shutil

# from pathlib import Path
# from PIL import Image
# import ocrolib

# TOOL = 'ocrd-anybaseocr-dewarp'
# LOG = getLogger('OcrdAnybaseocrDewarper')

# class OcrdAnybaseocrDewarper(Processor):

# def __init__(self, *args, **kwargs):
# kwargs['ocrd_tool'] = OCRD_TOOL['tools'][TOOL]
# kwargs['version'] = OCRD_TOOL['version']
# super(OcrdAnybaseocrDewarper, self).__init__(*args, **kwargs)

# def crop_image(self, image_path, crop_region):
# img = Image.open(image_path)
# cropped = img.crop(crop_region)
# return cropped

# def process(self):
# if not torch.cuda.is_available():
# LOG.error("Your system has no CUDA installed. No GPU detected.")
# sys.exit(1)

# path = Path(self.parameter['pix2pixHD']).absolute()

# if not Path(path).is_dir():
# LOG.error("""\
# NVIDIA's pix2pixHD was not found at '%s'. Make sure the `pix2pixHD` parameter
# in params.json points to the local path to the cloned pix2pixHD repository.

# pix2pixHD can be downloaded from https://github.com/NVIDIA/pix2pixHD
# """ % path)
# sys.exit(1)


# for (_, input_file) in enumerate(self.input_files):
# local_input_file = self.workspace.download_file(input_file)
# pcgts = parse(local_input_file.url, silence=True)
# image_coords = pcgts.get_Page().get_Border().get_Coords().points.split()
# fname = pcgts.get_Page().imageFilename
# LOG.info("INPUT FILE %s", fname)

# # Get page Co-ordinates
# min_x, min_y = image_coords[0].split(",")
# max_x, max_y = image_coords[2].split(",")
# img_tmp_dir = "OCR-D-IMG/test_A"
# img_dir = os.path.dirname(str(fname))
# # Path of pix2pixHD
# Path(img_tmp_dir).mkdir(parents=True, exist_ok=True)

# crop_region = int(min_x), int(
# min_y), int(max_x), int(max_y)
# cropped_img = self.crop_image(fname, crop_region)


# base, _ = ocrolib.allsplitext(fname)
# filename = base.split("/")[-1] + ".png"
# cropped_img.save(img_tmp_dir + "/" + filename)

# os.system("python " + str(path) + "/test.py --dataroot %s --checkpoints_dir ./ --name models --results_dir %s --label_nc 0 --no_instance --no_flip --resize_or_crop none --n_blocks_global 10 --n_local_enhancers 2 --gpu_ids %s --loadSize %d --fineSize %d --resize_or_crop %s" %
# (os.path.dirname(img_tmp_dir), img_dir, self.parameter['gpu_id'], self.parameter['resizeHeight'], self.parameter['resizeWidth'], self.parameter['imgresize']))
# synthesized_image = filename.split(
# ".")[0] + "_synthesized_image.jpg"
# pix2pix_img_dir = img_dir + "/models/test_latest/images/"
# dewarped_image = Path(pix2pix_img_dir + synthesized_image)
# if(dewarped_image.is_file()):
# shutil.copy(dewarped_image, img_dir + "/" +
# filename.split(".")[0] + ".dw.jpg")

# if(Path(img_tmp_dir).is_dir()):
# shutil.rmtree(img_tmp_dir)
# if(Path(img_dir + "/models").is_dir()):
# shutil.rmtree(img_dir + "/models")

0 comments on commit 44247ab

Please sign in to comment.