| 139 | return label_string |
| 140 | |
| 141 | def save_file(self, image_suffix, image_path, label_string): |
| 142 | dir_index: int = int(self.index / self.image_size_per_dir) |
| 143 | target_dir = os.path.join(self.abs_result_dir_path, str(dir_index)) |
| 144 | print("target path = " + target_dir) |
| 145 | if not os.path.exists(target_dir): |
| 146 | os.mkdir(target_dir) |
| 147 | |
| 148 | index_string = str(self.index) |
| 149 | target_name = "{0}\\{1}.{2}".format(target_dir, index_string, image_suffix) |
| 150 | if os.path.exists(target_name): |
| 151 | print("The file have been created, please check " + target_name) |
| 152 | return |
| 153 | |
| 154 | # 将图片复制过去,每1000张一个文件夹 |
| 155 | os.rename(image_path, target_name) |
| 156 | |
| 157 | f = open("{0}\\{1}.txt".format(target_dir, index_string), 'w') |
| 158 | f.write(str(label_string)) |
| 159 | f.close() |
| 160 | |
| 161 | self.index += 1 |
| 162 | self.success += 1 |
| 163 | |
| 164 | def collect_special_image(self, image_path): |
| 165 | print("recognize fail, move fail to special dir, the file = " + image_path + "\n") |