Decode the image from the given path.
(image_path)
| 32 | # ----------------------- Function Definitions ----------------------- |
| 33 | |
| 34 | def decode_image(image_path): |
| 35 | """ |
| 36 | Decode the image from the given path. |
| 37 | """ |
| 38 | if isinstance(image_path, str): |
| 39 | image = Image.open(image_path).convert('RGB') |
| 40 | elif isinstance(image_path, Image.Image): |
| 41 | image =image_path |
| 42 | else: |
| 43 | raise ValueError("Invalid image path or image object.") |
| 44 | image = np.array(image) |
| 45 | image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR) |
| 46 | return image |
| 47 | |
| 48 | def calculate_spaces_and_newlines(current_box, previous_box, space_threshold=45, line_threshold=15): |
| 49 | """Calculate the number of spaces and newlines between two text boxes.""" |