SHEETtoPNG
Converter class to convert input sample sheet to character PNGs.
Source code in handwrite/sheettopng.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 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 159 160 161 | |
convert(sheet, characters_dir, config, cols=8, rows=10)
¶
Convert a sheet of sample writing input to a custom directory structure of PNGs.
Detect all characters in the sheet as a separate contours and convert each to a PNG image in a temp/user provided directory.
Parameters¶
sheet : str Path to the sheet file to be converted. characters_dir : str Path to directory to save characters in. config: str Path to config file. cols : int, default=8 Number of columns of expected contours. Defaults to 8 based on the default sample. rows : int, default=10 Number of rows of expected contours. Defaults to 10 based on the default sample.
Source code in handwrite/sheettopng.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | |
detect_characters(sheet_image, threshold_value, cols=8, rows=10)
¶
Detect contours on the input image and filter them to get only characters.
Uses opencv to threshold the image for better contour detection. After finding all contours, they are filtered based on area, cropped and then sorted sequentially based on coordinates. Finally returs the cols*rows top candidates for being the character containing contours.
Parameters¶
sheet_image : str Path to the sheet file to be converted. threshold_value : int Value to adjust thresholding of the image for better contour detection. cols : int, default=8 Number of columns of expected contours. Defaults to 8 based on the default sample. rows : int, default=10 Number of rows of expected contours. Defaults to 10 based on the default sample.
Returns¶
sorted_characters : list of list
Final rows*cols contours in form of list of list arranged as:
sorted_characters[x][y] denotes contour at x, y position in the input grid.
Source code in handwrite/sheettopng.py
52 53 54 55 56 57 58 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 | |
save_images(characters, characters_dir)
¶
Create directory for each character and save as PNG.
Creates directory and PNG file for each image as following:
characters_dir/ord(character)/ord(character).png (SINGLE SHEET INPUT)
characters_dir/sheet_filename/ord(character)/ord(character).png (MULTIPLE SHEETS INPUT)
Parameters¶
characters : list of list Sorted list of character images each inner list representing a row of images. characters_dir : str Path to directory to save characters in.
Source code in handwrite/sheettopng.py
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 | |