Open jigsawcoder opened 3 years ago
I didn't understand what you want to do. If you work with bboxes in yolo
format you don't need to convert them to albumentations format.
import numpy as np
import albumentations as A
import random
import cv2 as cv
import matplotlib.pyplot as plt
def draw_bboxes(img, bboxes):
height, width = img.shape[:2]
for x, y, w, h, label in bboxes:
x *= width
y *= height
w *= width
h *= height
x1 = int(x - w / 2 + 1)
x2 = int(x1 + w)
y1 = int(y - h / 2 + 1)
y2 = int(y1 + h)
cv.rectangle(img, (int(x1), int(y1)), (int(x2), int(y2)), (255, 0, 0), thickness=height // 100)
random.seed(0)
np.random.seed(0)
image = np.zeros([1000, 1000, 3], dtype=np.uint8)
bboxes = [
[0.05, 0.05, 0.1, 0.1, 0],
[0.3, 0.3, 0.25, 0.25, 0],
[0.25, 0.17, 0.38, 0.34, 0],
[0.7, 0.3, 0.11, 0.33, 0],
]
transforms = A.Compose([A.Resize(100, 100)], bbox_params=A.BboxParams(format="yolo"))
res = transforms(image=image, bboxes=bboxes)
plt.subplot(211, title="original")
draw_bboxes(image, bboxes)
plt.imshow(image, vmin=0, vmax=255)
plt.subplot(212, title="result")
draw_bboxes(res["image"], res["bboxes"])
plt.imshow(res["image"], vmin=0, vmax=255)
plt.show()
🐛 Bug
I am using my custom Yolo darknet dataset having multiple classes per image and I tried to visualize the bounding box after converting them from Yolo to the one used by Albumentation but I can't see any bounding box on the images.
I used the following code snippets to convert the bounding boxes from Yolo to the format used by Albumentation:
Also, I used to following code for visualization:
I am getting this image, there are a total of 7 bounding box in this image but they are not drawn correctly, is there something I am missing??
I am following these two links:
https://albumentations.ai/docs/examples/example_bboxes/
https://github.com/albumentations-team/albumentations/blob/13f44d1397f11cb371436715d50739a8c90b6abb/albumentations/augmentations/bbox_utils.py#L195
Environment
conda
,pip
, source):Additional context