Как избежать искажения результатов с помощью инструмента OCR pdfsandwich?

857
lalebarde

Обычно отсканированные страницы должны быть выровнены до применения инструмента OCR. Здесь мой вход - это страница с прямым сканированием, а выходной сигнал OCR иногда искажается, по часовой стрелке или против часовой стрелки. В моем случае использования английской книги на 260 страниц это происходит на 14 страницах.

Пример: input.pdf: input.pdf

output.pdf output.pdf

Команда:

convert -density 300 -quality 100 input.pdf -level 0%,100%,4.0 -black-threshold 75% convert.pdf && pdfsandwich -noimage -coo "-normalize -density 300 -black-threshold 75%" convert.pdf -o output.pdf 

Как я могу избежать этого искажения вывода?

В качестве альтернативы, как я могу выровнять вывод без потери OCR? Все методы и инструменты, которые я нашел, сначала конвертируются в формат изображения, который приводит к потере распознавания текста, а затем здесь бесполезен.

0

1 ответ на вопрос

0
lalebarde

Thanks to Remy F, I could write this solution, with the help of this LaTeX file, which import output.pdf, and rotate it:

\documentclass \usepackage[paperwidth=6.38in,paperheight=10.32in,bindingoffset=0in,top=-0.39in,bottom=0in,left=-0.29in,right=0in,footskip=0in] \usepackage \begin \pagestyle \begin[t] \includegraphics[scale=0.233,angle=-4] \end \end 

Then:

pdflatex output_tex.tex 

Creates output_tex.pdf: enter image description here

It would be nice to be able to tune the scale and margins automatically to be able to automatize the process.

EDIT: I have made some progress to obtain the deskew angle automatically:

angle=`convert output.pdf -deskew 40 -format "%[deskew:angle]" info:` 

If I automatize, it leads to:

#/bin/bash name=$ ext=$ convert -density 300 -quality 100 $.$ext -level 0%,100%,4.0 -black-threshold 75% $_convert.$ext pdfsandwich -noimage -coo "-normalize -density 300 -black-threshold 75%" $_convert.$ext -o $_ocr.$ext angle=`convert $_ocr.$ext -deskew 40 -format "%[deskew:angle]" info:` angle=`echo "$*-1" | bc` echo " angle = $angle" sed -e "s/ANGLE/$angle/" -e "s/FILE/$_ocr.$ext/" /var/ocr/pdfrotate.tex > $_ocr_straight.tex pdflatex $_ocr_straight.tex rm $_convert.$ext $_ocr_straight.tex $_ocr_straight.aux $_ocr_straight.log 

With /var/ocr/pdfrotate.tex:

\documentclass \usepackage[paperwidth=6.38in,paperheight=10.32in,bindingoffset=0in,top=-0.39in,bottom=0in,left=-0.29in,right=0in,footskip=0in] \usepackage \begin \pagestyle \begin[t] \includegraphics[scale=0.233,angle=ANGLE] \end \end 

The scale looks right and is document dependent. But unfortunatly, the geometry parameters top and left I tuned for my trial page are not good for other pages. I don't know how to automatize them. Possibly by bluring the original page and the result one, and performing an optimisation of a correlation of them, with top and left as parameters.

Похожие вопросы