| 
									
										
										
										
											2019-06-19 12:22:41 +02:00
										 |  |  | #!/bin/bash | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | set -e  # Abort on error | 
					
						
							| 
									
										
										
										
											2020-02-07 17:12:51 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | # Set up logging | 
					
						
							|  |  |  | export LOG_LEVEL=${LOG_LEVEL:-DEBUG}  # /etc/ocrd_logging.py uses this to set level for all OCR-D modules | 
					
						
							| 
									
										
										
										
											2019-06-19 17:48:38 +02:00
										 |  |  | if [ "$LOG_LEVEL" = "DEBUG" -o "$LOG_LEVEL" = "TRACE" ]; then | 
					
						
							|  |  |  |   set -x | 
					
						
							|  |  |  | fi | 
					
						
							| 
									
										
										
										
											2019-06-19 12:22:41 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-05 15:27:38 +02:00
										 |  |  | do_validate() { | 
					
						
							| 
									
										
										
										
											2020-02-07 14:13:32 +01:00
										 |  |  |   validate_options=" | 
					
						
							|  |  |  |     --skip dimension | 
					
						
							|  |  |  |     --skip pixel_density | 
					
						
							|  |  |  |     --page-strictness lax | 
					
						
							|  |  |  |     --page-coordinate-consistency off" | 
					
						
							|  |  |  |   ocrd workspace validate $validate_options | 
					
						
							| 
									
										
										
										
											2019-08-05 15:27:38 +02:00
										 |  |  |   # XXX ocrd-tesserocr INCONSISTENCY in TextRegion → use "--page-strictness lax" for now | 
					
						
							| 
									
										
										
										
											2020-01-16 16:33:36 +01:00
										 |  |  |   # XXX INVALIDITY in Glyph ID etc. in GT → --page-coordinate-consistency off | 
					
						
							| 
									
										
										
										
											2019-08-05 15:27:38 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-24 12:34:08 +02:00
										 |  |  | do_binarization() { | 
					
						
							| 
									
										
										
										
											2019-07-03 12:22:55 +02:00
										 |  |  |   # Binarize the images | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-07 13:20:18 +01:00
										 |  |  |   ocrd_olena_binarize_paramters='{"impl": "sauvola-ms-split"}' | 
					
						
							| 
									
										
										
										
											2020-02-07 14:26:20 +01:00
										 |  |  |   ocrd workspace remove-group -rf OCR-D-IMG-BINPAGE | 
					
						
							|  |  |  |   ocrd workspace remove-group -rf OCR-D-IMG-BIN | 
					
						
							| 
									
										
										
										
											2020-02-07 17:12:51 +01:00
										 |  |  |   ocrd-olena-binarize \ | 
					
						
							| 
									
										
										
										
											2020-02-07 16:25:40 +01:00
										 |  |  |     -I OCR-D-IMG -O OCR-D-IMG-BINPAGE \ | 
					
						
							| 
									
										
										
										
											2020-02-07 13:20:18 +01:00
										 |  |  |     -p "$ocrd_olena_binarize_paramters" | 
					
						
							| 
									
										
										
										
											2019-06-24 12:34:08 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-11 19:16:43 +02:00
										 |  |  | do_linesegmentation_tesserocr() { | 
					
						
							| 
									
										
										
										
											2019-07-03 12:22:55 +02:00
										 |  |  |   # Segment the lines in the binarized images | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-07 14:26:20 +01:00
										 |  |  |   ocrd workspace remove-group -rf OCR-D-SEG-REGION | 
					
						
							|  |  |  |   ocrd workspace remove-group -rf OCR-D-SEG-LINE | 
					
						
							| 
									
										
										
										
											2020-02-07 17:12:51 +01:00
										 |  |  |   ocrd-tesserocr-segment-region \ | 
					
						
							| 
									
										
										
										
											2020-02-07 16:25:40 +01:00
										 |  |  |     -I OCR-D-IMG-BINPAGE -O OCR-D-SEG-REGION | 
					
						
							| 
									
										
										
										
											2020-02-07 17:12:51 +01:00
										 |  |  |   ocrd-tesserocr-segment-line \ | 
					
						
							| 
									
										
										
										
											2020-02-07 16:25:40 +01:00
										 |  |  |     -I OCR-D-SEG-REGION -O OCR-D-SEG-LINE | 
					
						
							| 
									
										
										
										
											2019-08-05 15:27:38 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-24 12:13:49 +02:00
										 |  |  |   # XXX compare ocrd-tesserocr-segment* vs tesseract native | 
					
						
							| 
									
										
										
										
											2019-06-19 12:51:52 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-11 19:16:43 +02:00
										 |  |  | do_linesegmentation_sbb() { | 
					
						
							|  |  |  |   # Segment the lines in the images | 
					
						
							| 
									
										
										
										
											2019-11-20 12:40:05 +01:00
										 |  |  |   # TODO: Check that this works with the RGB images | 
					
						
							| 
									
										
										
										
											2019-10-11 19:16:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-07 13:20:18 +01:00
										 |  |  |   ocrd_sbb_textline_detector_parameters='{"model": "/var/lib/textline_detection"}' | 
					
						
							| 
									
										
										
										
											2020-02-07 14:26:20 +01:00
										 |  |  |   ocrd workspace remove-group -rf OCR-D-SEG-REGION | 
					
						
							|  |  |  |   ocrd workspace remove-group -rf OCR-D-SEG-LINE | 
					
						
							| 
									
										
										
										
											2020-02-07 17:12:51 +01:00
										 |  |  |   ocrd-sbb-textline-detector \ | 
					
						
							| 
									
										
										
										
											2020-02-07 16:25:40 +01:00
										 |  |  |     -I OCR-D-IMG-BINPAGE -O OCR-D-SEG-LINE \ | 
					
						
							| 
									
										
										
										
											2020-02-07 13:20:18 +01:00
										 |  |  |     -p "$ocrd_sbb_textline_detector_parameters" | 
					
						
							| 
									
										
										
										
											2019-10-11 19:16:43 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-19 13:02:54 +02:00
										 |  |  | do_ocr() { | 
					
						
							| 
									
										
										
										
											2019-07-03 12:22:55 +02:00
										 |  |  |   # Perform OCR on the segmented lines | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-02 16:48:28 +02:00
										 |  |  |   ocrd_tesserocr_recognize_parameters='{ "model": "GT4HistOCR_2000000" }'  # TODO mods:language + fontident → model | 
					
						
							| 
									
										
										
										
											2020-02-07 14:26:20 +01:00
										 |  |  |   ocrd workspace remove-group -rf OCR-D-OCR-TESS | 
					
						
							| 
									
										
										
										
											2020-02-07 17:12:51 +01:00
										 |  |  |   ocrd-tesserocr-recognize \ | 
					
						
							| 
									
										
										
										
											2020-02-07 16:25:40 +01:00
										 |  |  |     -I OCR-D-SEG-LINE -O OCR-D-OCR-TESS \ | 
					
						
							| 
									
										
										
										
											2020-02-07 12:24:51 +01:00
										 |  |  |     -p "$ocrd_tesserocr_recognize_parameters" | 
					
						
							| 
									
										
										
										
											2019-06-19 13:02:54 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2019-06-19 12:51:52 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-21 11:54:01 +02:00
										 |  |  | do_ocr_calamari() { | 
					
						
							| 
									
										
										
										
											2020-02-07 13:31:26 +01:00
										 |  |  |   ocrd_calamari_recognize_parameters='{ | 
					
						
							|  |  |  |     "checkpoint": "/var/lib/calamari-models/GT4HistOCR/2019-07-22T15:49+0200/*.ckpt.json", | 
					
						
							|  |  |  |     "textequiv_level": "line" | 
					
						
							|  |  |  |   }' | 
					
						
							| 
									
										
										
										
											2020-02-07 14:26:20 +01:00
										 |  |  |   ocrd workspace remove-group -rf OCR-D-OCR-CALAMARI | 
					
						
							| 
									
										
										
										
											2020-02-07 17:12:51 +01:00
										 |  |  |   ocrd-calamari-recognize \ | 
					
						
							| 
									
										
										
										
											2020-02-07 16:25:40 +01:00
										 |  |  |     -I OCR-D-SEG-LINE -O OCR-D-OCR-CALAMARI \ | 
					
						
							| 
									
										
										
										
											2020-02-07 12:24:51 +01:00
										 |  |  |     -p "$ocrd_calamari_recognize_parameters" | 
					
						
							| 
									
										
										
										
											2019-08-21 11:54:01 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-19 14:55:50 +02:00
										 |  |  | page_validate_xml() { | 
					
						
							| 
									
										
										
										
											2019-07-03 12:22:55 +02:00
										 |  |  |   # Validate all PAGE XML against the XML schema | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-19 14:55:50 +02:00
										 |  |  |   filegrp=$1 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   local file | 
					
						
							|  |  |  |   for file in `ocrd workspace find -G $filegrp`; do | 
					
						
							| 
									
										
										
										
											2019-09-30 18:25:54 +02:00
										 |  |  |     XSD_DIR=`dirname $0`/xsd | 
					
						
							|  |  |  |     if [ ! -d "$XSD_DIR" ]; then | 
					
						
							|  |  |  |       XSD_DIR=/usr/share/xml | 
					
						
							|  |  |  |     fi | 
					
						
							|  |  |  |     xmllint --noout --schema $XSD_DIR/pagecontent.2019-07-15.xsd $file | 
					
						
							| 
									
										
										
										
											2019-06-19 14:55:50 +02:00
										 |  |  |   done | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-11 19:16:43 +02:00
										 |  |  | page_upgrade_to_2019() { | 
					
						
							|  |  |  |   filegrp=$1 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   local file | 
					
						
							|  |  |  |   for file in `ocrd workspace find -G $filegrp`; do | 
					
						
							|  |  |  |     sed -i 's#pagecontent/[0-9-]*#pagecontent/2019-07-15#g' $file | 
					
						
							|  |  |  |   done | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2019-08-05 15:40:39 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-27 13:16:14 +02:00
										 |  |  | pip3 list | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-30 12:26:14 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-24 12:34:08 +02:00
										 |  |  | do_binarization | 
					
						
							| 
									
										
										
										
											2019-08-05 15:27:38 +02:00
										 |  |  | do_validate | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-30 12:26:14 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-11 19:16:43 +02:00
										 |  |  | do_linesegmentation_sbb | 
					
						
							|  |  |  | page_upgrade_to_2019             OCR-D-SEG-LINE | 
					
						
							|  |  |  | page_validate_xml                OCR-D-SEG-REGION | 
					
						
							|  |  |  | page_validate_xml                OCR-D-SEG-LINE | 
					
						
							| 
									
										
										
										
											2019-08-05 15:27:38 +02:00
										 |  |  | do_validate | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-21 13:07:27 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-21 11:54:01 +02:00
										 |  |  | do_ocr_calamari | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-21 13:07:27 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-19 13:02:54 +02:00
										 |  |  | do_ocr | 
					
						
							| 
									
										
										
										
											2019-08-05 15:27:38 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-19 12:22:41 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-21 13:07:27 +02:00
										 |  |  | for ocr_filegrp in OCR-D-OCR-CALAMARI OCR-D-OCR-TESS; do | 
					
						
							| 
									
										
										
										
											2019-08-05 18:46:36 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-21 13:07:27 +02:00
										 |  |  |   page_validate_xml           $ocr_filegrp | 
					
						
							|  |  |  |   do_validate | 
					
						
							| 
									
										
										
										
											2019-08-13 18:13:49 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-21 13:07:27 +02:00
										 |  |  |   page_validate_xml           $ocr_filegrp | 
					
						
							|  |  |  |   do_validate | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-26 16:46:12 +02:00
										 |  |  |   # XXX This seems to be causing new problems with validation | 
					
						
							|  |  |  |   # https://github.com/OCR-D/core/issues/176 | 
					
						
							|  |  |  |   #page_fix_image_references   $ocr_filegrp | 
					
						
							|  |  |  |   #do_validate | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-21 13:07:27 +02:00
										 |  |  |   if ocrd workspace list-group | grep -q OCR-D-GT-PAGE; then | 
					
						
							| 
									
										
										
										
											2020-02-07 14:26:20 +01:00
										 |  |  |     ocrd workspace remove-group -rf $ocr_filegrp-EVAL | 
					
						
							| 
									
										
										
										
											2020-02-07 16:25:40 +01:00
										 |  |  |     ocrd-dinglehopper -I OCR-D-GT-PAGE,$ocr_filegrp -O $ocr_filegrp-EVAL | 
					
						
							| 
									
										
										
										
											2019-08-21 13:07:27 +02:00
										 |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | done | 
					
						
							| 
									
										
										
										
											2019-08-13 18:13:49 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-19 12:39:42 +02:00
										 |  |  | # vim:tw=120: |