ocr_cropper
data.crop.ocr_cropper
OcrCropper
OcrCropper(chr_height: int = 32, crop_jitter: Optional[float] = None, crop_jitter_rate: Optional[List[float]] = None, save_polygons: bool = False)
Cropper class for OCR task.
Attributes:
-
chr_height(int) –cropped image patch is resized to be the same height as chr_height.
-
crop_jitter(Optional[float]) –if not None, cropping box is jittered horizontally with ratio crop_jitter.
-
crop_jitter_rate(Optional[List[float]]) –if not None, cropping box points are jittered to any direction with ratio crop_jitter_rate.
-
save_polygons(bool) –whether polygon label is preserved after cropping.
initializing OcrCropper. all initializing input is set to class attribute.
Parameters:
-
chr_height(int, default:32) –Defaults to 32.
-
crop_jitter(Optional[float], default:None) –Defaults to None.
-
crop_jitter_rate(Optional[List[float]], default:None) –Defaults to None.
-
save_polygons(bool, default:False) –Defaults to False.
Source code in SaigeToolkit/data/crop/ocr_cropper.py
get_n_patch
OcrCropper only crops all polygon areas, unlike SegCropper. Therefore, resultant number of patches is simply equals to number of polygons.
Parameters:
-
polygons(List[List[ndarray]]) –polygons of all images in dataset.
Returns:
-
int(int) –total number of patches to be cropped
Source code in SaigeToolkit/data/crop/ocr_cropper.py
__call__
__call__(image: Union[Image, ndarray], polygons: List[ndarray], strings: List[str], ignore: List[bool], is_vertical: Optional[List[bool]] = None, **kwargs) -> List[dict]
crop image into image patches. polygon, string, ignore data should be same length.
Parameters:
-
image(Union[Image, ndarray]) –original image
-
polygons(List[ndarray]) –polygon data (# of polygons, (4, 2)) polygon should have 4 points
-
strings(List[str]) –string data
-
ignore(List[bool]) –ignore notation data
-
is_vertical(List[bool], default:None) –is_vertical notation data
Returns:
-
List[dict]–List[dict]: list of cropped image data dict
Source code in SaigeToolkit/data/crop/ocr_cropper.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 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 | |
calculate_width_height
calculate width and heights for every four polygon points (2 tops and 2 bots). Assuming that polygon is composed of top-points and bot-points, and every top and bot points are paired.
Parameters:
-
tops(ndarray) –top points of polygon
-
bots(ndarray) –bot points of polygon
Returns:
-
Tuple[List[ndarray], List[ndarray]]–Tuple[List[np.ndarray]]: width and height list for every four points.
Source code in SaigeToolkit/data/crop/ocr_cropper.py
jitter_polygon
jittering polygon points and split into tops and bots points
Parameters:
-
polygon(ndarray) –original polygon data
Returns:
-
Tuple[ndarray, ndarray]–Tuple[np.ndarray, np.ndarray]: jittered tops, bots points