|
1 | | -from mindee.v2.product.crop.crop_box import CropBox |
| 1 | +from mindee.image.extracted_image import ExtractedImage |
| 2 | +from mindee.image.image_extractor import extract_multiple_images_from_source |
| 3 | +from mindee.input.local_input_source import LocalInputSource |
| 4 | +from mindee.parsing.common import StringDict |
| 5 | +from mindee.v2.parsing.inference.field import FieldLocation |
| 6 | +from mindee.v2.product.extraction.extraction_response import ExtractionResponse |
2 | 7 |
|
3 | 8 |
|
4 | | -class CropItem(CropBox): |
5 | | - """Result of a cropped document region.""" |
| 9 | +class CropItem: |
| 10 | + """Deprecated class. Use CropItem instead.""" |
| 11 | + |
| 12 | + location: FieldLocation |
| 13 | + """Location which includes cropping coordinates for the detected object, within the source document.""" |
| 14 | + |
| 15 | + object_type: str |
| 16 | + """Type or classification of the detected object.""" |
| 17 | + |
| 18 | + extraction_response: ExtractionResponse | None = None |
| 19 | + """The extraction response associated with the crop.""" |
| 20 | + |
| 21 | + def __init__(self, server_response: StringDict): |
| 22 | + self.location = FieldLocation(server_response["location"]) |
| 23 | + self.object_type = server_response["object_type"] |
| 24 | + if server_response.get("extraction_response") is not None: |
| 25 | + self.extraction_response = ExtractionResponse( |
| 26 | + server_response["extraction_response"] |
| 27 | + ) |
| 28 | + |
| 29 | + def __str__(self) -> str: |
| 30 | + return f"* :Location: {self.location}\n :Object Type: {self.object_type}" |
| 31 | + |
| 32 | + def extract_from_input_source( |
| 33 | + self, input_source: LocalInputSource |
| 34 | + ) -> ExtractedImage: |
| 35 | + """ |
| 36 | + Apply the split range inference to a file and return a single extracted PDF. |
| 37 | +
|
| 38 | + :param input_source: Local file to apply the inference to |
| 39 | + :return: Extracted PDF |
| 40 | + """ |
| 41 | + return extract_multiple_images_from_source( |
| 42 | + input_source, self.location.page, [self.location.polygon] |
| 43 | + )[0] |
0 commit comments