<jupyter_start><jupyter_text>Borrow from [https://github.com/foamliu/Car-Recognition/blob/master/pre-process.py](https://github.com/foamliu/Car-Recognition/blob/master/pre-process.py)<jupyter_code>fnames = []
class_ids = []
bboxes = []
labels = []

for annotation in annotations:
    bbox_x1 = annotation[0][0][0][0]
    bbox_y1 = annotation[0][1][0][0]
    bbox_x2 = annotation[0][2][0][0]
    bbox_y2 = annotation[0][3][0][0]
    class_id = annotation[0][4][0][0]
    labels.append('%04d' % (class_id,))
    fname = annotation[0][5][0]
    bboxes.append((bbox_x1, bbox_y1, bbox_x2, bbox_y2))
    class_ids.append(class_id)
    fnames.append(fname)
np.unique(class_ids).shape[0]
!rm -rf cars_train_crop
!mkdir cars_train_crop
src_folder = 'cars_train'
dst_folder = 'cars_train_crop'
margin = 16

for i in tqdm(range(len(fnames))):
    fname = fnames[i]
    label = labels[i]
    (x1, y1, x2, y2) = bboxes[i]

    src_path = os.path.join(src_folder, fname)
    src_image = cv.imread(src_path)
    height, width = src_image.shape[:2]
    
    x1 = max(0, x1 - margin)
    y1 = max(0, y1 - margin)
    x2 = min(x2 + margin, width)
    y2 = min(y2 + margin, height)
    
    dst_path = os.path.join(dst_folder, label + '_' + fname)
    crop_image = src_image[y1:y2, x1:x2]
    dst_img = cv.resize(src=crop_image, dsize=(height, width))
    imsave(dst_path + '.jpg', dst_img)<jupyter_output>0%|          | 0/8144 [00:00<?, ?it/s]/usr/local/lib/python3.6/dist-packages/ipykernel_launcher.py:22: DeprecationWarning: `imsave` is deprecated!
`imsave` is deprecated in SciPy 1.0.0, and will be removed in 1.2.0.
Use ``imageio.imwrite`` instead.
100%|██████████| 8144/8144 [02:45<00:00, 49.22it/s]
{'fraction_non_alphanumeric': 0.17427385892116182, 'fraction_numerical': 0.058091286307053944, 'mean_word_length': 4.008902077151335, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 4, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '270055', 'license': 'MIT', 'n_tokens_mistral': 770, 'n_tokens_neox': 720, 'n_words': 119, 'path': 'grab-aiforsea/computer-vision/preprocessing.ipynb', 'repo_name': 'huseinzol05/Machine-Learning-Data-Science-Reuse', 'size': '1687'}