I have image (think of image of small plant) with bounding box. For data augmentation I want to rotate (45 degrees) the image (plant) in bounding box, and place it at same place in original image. so that I don't have to annotate again in image. Only difference is that image(plant) in box is rotated by 45 degrees. I am using cv2 and pil. I have below code writtend and got help up after that. Looking for inputs. Thanks for your time.
demo_test_img = 'repa_trn_23_4598958_2920949_png.rf.996ba731acd8b0d4b75c57acf85cc91b.jpg'
demo_test_img_path = os.path.join(f'{DIR_TRAIN}',demo_test_img)
# read image
demo_read_test_img = cv2.imread(demo_test_img_path, cv2.IMREAD_COLOR)
# colors for boxes.
colour_dict = {1:(220, 0, 0), 2:(0, 0, 220)}
# get number of boxes present in image.
demo_img_boxes_info = train_df[train_df["image_id"] == demo_test_img]
print('Number of boxes for demo image ', len(demo_img_boxes_info))
for index, row in demo_img_boxes_info.iterrows():
if (row['class'] == 1 or row['class'] == 2):
H = int(row['h'])
W = int(row['w'])
X = int(row['x'])
Y = int(row['y'])
cropped_image = demo_read_test_img[Y:Y+H, X:X+W]
print('Box for idx is ', index, 'is ',[X,Y,W,H])
**# TODO: rotate cropped image and place it at same location of original demo test image.**
fig, ax = plt.subplots(1, 1, figsize=(16, 8))
ax.imshow(demo_read_test_img)