Pdf Ocr
read_pdf_unstructured ¶
Convert PDF from specified path to list of text items with location information
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_path
|
Union[Path, str]
|
path to input file |
required |
Returns:
Type | Description |
---|---|
Dict page_number: list of text boxes |
Source code in libs/kotaemon/kotaemon/loaders/utils/pdf_ocr.py
merge_ocr_and_pdf_texts ¶
Merge PDF and OCR text using IOU overlapping location Args: ocr_list: List of OCR items {"text", "box", "location"} pdf_text_list: List of PDF items {"text", "box", "location"}
Returns:
Type | Description |
---|---|
Combined list of PDF text and non-overlap OCR text |
Source code in libs/kotaemon/kotaemon/loaders/utils/pdf_ocr.py
merge_table_cell_and_ocr ¶
Merge table items with OCR text using IOU overlapping location Args: table_list: List of table items "type": ("table", "cell", "text"), "text", "box", "location"} ocr_list: List of OCR items {"text", "box", "location"} pdf_list: List of PDF items {"text", "box", "location"}
Returns:
Name | Type | Description |
---|---|---|
all_table_cells |
List of tables, each of table is represented by list of cells with combined text from OCR |
|
not_matched_items |
List of PDF text which is not overlapped by table region |
Source code in libs/kotaemon/kotaemon/loaders/utils/pdf_ocr.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
|
parse_ocr_output ¶
Main function to combine OCR output and PDF text to form list of table / non-table regions Args: ocr_page_items: List of OCR items by page pdf_page_items: Dict of PDF texts (page number as key) debug_path: If specified, use OpenCV to plot debug image and save to debug_path