@@ -114,7 +114,6 @@ def get_tabular_content(model, image, confidence_dict=None):
114
114
115
115
return table_df , confidence_df
116
116
117
-
118
117
def get_sheet_type (res ):
119
118
"""
120
119
Finds the type of the tally sheet (dataSet, orgUnit, period) from the result of OCR model, where
@@ -208,22 +207,23 @@ def correct_image_orientation(image_path):
208
207
:param image_path: The path to the image file.
209
208
:return: PIL.Image.Image: The image with corrected orientation.
210
209
"""
211
- with Image .open (image_path ) as image :
212
- orientation = None
213
- try :
214
- for orientation in ExifTags .TAGS .keys ():
215
- if ExifTags .TAGS [orientation ] == 'Orientation' :
216
- break
217
- exif = dict (image .getexif ().items ())
218
- if exif .get (orientation ) == 3 :
219
- image = image .rotate (180 , expand = True )
220
- elif exif .get (orientation ) == 6 :
221
- image = image .rotate (270 , expand = True )
222
- elif exif .get (orientation ) == 8 :
223
- image = image .rotate (90 , expand = True )
224
- except (AttributeError , KeyError , IndexError ):
225
- pass
226
- return image .copy ()
210
+ with Image .open (image_path ) as image :
211
+ image .load ()
212
+ orientation = None
213
+ try :
214
+ for orientation in ExifTags .TAGS .keys ():
215
+ if ExifTags .TAGS [orientation ] == 'Orientation' :
216
+ break
217
+ exif = dict (image .getexif ().items ())
218
+ if exif .get (orientation ) == 3 :
219
+ image = image .rotate (180 , expand = True )
220
+ elif exif .get (orientation ) == 6 :
221
+ image = image .rotate (270 , expand = True )
222
+ elif exif .get (orientation ) == 8 :
223
+ image = image .rotate (90 , expand = True )
224
+ except (AttributeError , KeyError , IndexError ):
225
+ pass
226
+ return image
227
227
228
228
# ocr_model = ocr_predictor(det_arch='db_resnet50', reco_arch='crnn_vgg16_bn', pretrained=True)
229
229
# document = DocumentFile.from_images("IMG_20240514_090947.jpg")
0 commit comments