mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/ocr.git
synced 2024-12-26 18:24:17 +00:00
Remove unused dependencies and use ghostscript for image split
This commit is contained in:
parent
aee9628e5e
commit
2b63ba9e59
@ -14,7 +14,6 @@ RUN apt-get update \
|
|||||||
ca-certificates \
|
ca-certificates \
|
||||||
gnupg2 \
|
gnupg2 \
|
||||||
ghostscript \
|
ghostscript \
|
||||||
imagemagick \
|
|
||||||
poppler-utils \
|
poppler-utils \
|
||||||
python2.7 \
|
python2.7 \
|
||||||
python3.7 \
|
python3.7 \
|
||||||
|
39
ocr
39
ocr
@ -98,12 +98,16 @@ class OCRPipeline(WorkflowRunner):
|
|||||||
n_cores = min(self.n_cores, max(1, int(self.n_cores / len(self.jobs))))
|
n_cores = min(self.n_cores, max(1, int(self.n_cores / len(self.jobs))))
|
||||||
for i, job in enumerate(self.jobs):
|
for i, job in enumerate(self.jobs):
|
||||||
output_dir = os.path.join(job.output_dir, 'tmp')
|
output_dir = os.path.join(job.output_dir, 'tmp')
|
||||||
output_file_base = os.path.join(output_dir, 'page')
|
cmd = 'gs'
|
||||||
cmd = 'pdftoppm'
|
cmd += ' -dBATCH'
|
||||||
cmd += ' -r 300'
|
cmd += ' -dNOPAUSE'
|
||||||
cmd += ' -tiff'
|
cmd += ' -dNumRenderingThreads={}'.format(n_cores)
|
||||||
cmd += ' -tiffcompression lzw'
|
cmd += ' -dQUIET'
|
||||||
cmd += ' "{}" "{}"'.format(job.file, output_file_base)
|
cmd += ' -r300'
|
||||||
|
cmd += ' -sDEVICE=tiff24nc'
|
||||||
|
cmd += ' -sCompression=lzw'
|
||||||
|
cmd += ' "-sOutputFile={}/page-%d.tif"'.format(output_dir)
|
||||||
|
cmd += ' "{}"'.format(job.file)
|
||||||
deps = 'setup_output_directory_-_{}'.format(i)
|
deps = 'setup_output_directory_-_{}'.format(i)
|
||||||
lbl = 'split_input_-_{}'.format(i)
|
lbl = 'split_input_-_{}'.format(i)
|
||||||
split_input_jobs.append(self.addTask(command=cmd,
|
split_input_jobs.append(self.addTask(command=cmd,
|
||||||
@ -138,8 +142,9 @@ class OCRPipeline(WorkflowRunner):
|
|||||||
files.sort(key=lambda x: int(re.search(r'\d+', x).group(0)))
|
files.sort(key=lambda x: int(re.search(r'\d+', x).group(0)))
|
||||||
files = map(lambda x: os.path.join(input_dir, x), files)
|
files = map(lambda x: os.path.join(input_dir, x), files)
|
||||||
cmd = 'ocropus-nlbin "{}"'.format('" "'.join(files))
|
cmd = 'ocropus-nlbin "{}"'.format('" "'.join(files))
|
||||||
cmd += ' -o "{}"'.format(output_dir)
|
cmd += ' --nocheck'
|
||||||
cmd += ' -Q "{}"'.format(n_cores)
|
cmd += ' --output "{}"'.format(output_dir)
|
||||||
|
cmd += ' --parallel "{}"'.format(n_cores)
|
||||||
deps = 'split_input_-_{}'.format(i)
|
deps = 'split_input_-_{}'.format(i)
|
||||||
lbl = 'binarization_-_{}'.format(i)
|
lbl = 'binarization_-_{}'.format(i)
|
||||||
binarization_jobs.append(self.addTask(command=cmd,
|
binarization_jobs.append(self.addTask(command=cmd,
|
||||||
@ -322,19 +327,22 @@ class OCRPipeline(WorkflowRunner):
|
|||||||
' ##################################################
|
' ##################################################
|
||||||
'''
|
'''
|
||||||
pdf_compression_jobs = []
|
pdf_compression_jobs = []
|
||||||
|
n_cores = min(self.n_cores, max(1, int(self.n_cores / len(self.jobs))))
|
||||||
if self.compress:
|
if self.compress:
|
||||||
for i, job in enumerate(self.jobs):
|
for i, job in enumerate(self.jobs):
|
||||||
file = filter(lambda x: x.endswith('.pdf'), os.listdir(job.output_dir))[0] # noqa
|
file = filter(lambda x: x.endswith('.pdf'), os.listdir(job.output_dir))[0] # noqa
|
||||||
original_file = os.path.join(job.output_dir, file)
|
original_file = os.path.join(job.output_dir, file)
|
||||||
compressed_file = os.path.join(job.output_dir, 'c_' + file)
|
compressed_file = os.path.join(job.output_dir, 'c_' + file)
|
||||||
cmd = 'gs'
|
cmd = 'gs'
|
||||||
cmd += ' -sDEVICE=pdfwrite'
|
|
||||||
cmd += ' -dCompatibilityLevel=1.4'
|
|
||||||
cmd += ' -dPDFSETTINGS=/ebook'
|
|
||||||
cmd += ' -dNOPAUSE'
|
|
||||||
cmd += ' -dQUIET'
|
|
||||||
cmd += ' -dBATCH'
|
cmd += ' -dBATCH'
|
||||||
cmd += ' -sOutputFile="{}"'.format(compressed_file)
|
cmd += ' -dNOPAUSE'
|
||||||
|
cmd += ' -dNumRenderingThreads={}'.format(n_cores)
|
||||||
|
cmd += ' -dPDFSETTINGS=/ebook'
|
||||||
|
# -dCompatibilityLevel must be defined after -dPDFSETTINGS
|
||||||
|
cmd += ' -dCompatibilityLevel=1.4'
|
||||||
|
cmd += ' -dQUIET'
|
||||||
|
cmd += ' -sDEVICE=pdfwrite'
|
||||||
|
cmd += ' "-sOutputFile={}"'.format(compressed_file)
|
||||||
cmd += ' "{}"'.format(original_file)
|
cmd += ' "{}"'.format(original_file)
|
||||||
cmd += ' && '
|
cmd += ' && '
|
||||||
cmd += 'mv "{}" "{}"'.format(compressed_file, original_file)
|
cmd += 'mv "{}" "{}"'.format(compressed_file, original_file)
|
||||||
@ -342,7 +350,8 @@ class OCRPipeline(WorkflowRunner):
|
|||||||
lbl = 'pdf_compression_-_{}'.format(i)
|
lbl = 'pdf_compression_-_{}'.format(i)
|
||||||
pdf_compression_jobs.append(self.addTask(command=cmd,
|
pdf_compression_jobs.append(self.addTask(command=cmd,
|
||||||
dependencies=deps,
|
dependencies=deps,
|
||||||
label=lbl))
|
label=lbl,
|
||||||
|
nCores=n_cores))
|
||||||
|
|
||||||
'''
|
'''
|
||||||
' ##################################################
|
' ##################################################
|
||||||
|
Loading…
Reference in New Issue
Block a user