question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Visualization of rotated bounding boxes

See original GitHub issue

Hi! I’m working with rotated bounding boxes now and I found out that the visualizer cannot display the bounding box annotation for rotated boxes. The reason it cannot display rotated bounding boxes for a dataset by using draw_dataset_dict is simply because the code expects a BoxMode to convert the dataset coordinates to the variant which is used for visualization. However, rotated bounding boxes currently don’t have any BoxMode. I made a small fix that let me skip the coordinate conversion and visualize the rotated bounding boxes. I was considering submitting a pull request, but I think that a cleaner solution would be to add an additional BoxMode value for rotated bounding boxes. What is your opinion?

This is my makeshift solution. I replaced line https://github.com/facebookresearch/detectron2/blob/706a3185d187ea912b324eb0b5eac064ca0a62ce/detectron2/utils/visualizer.py#L489 with this code.

if "bbox" in annos[0] and len(annos[0]["bbox"]) == 4:
    boxes = [BoxMode.convert(x["bbox"], x["bbox_mode"], BoxMode.XYXY_ABS) for x in annos]
else:
    boxes = [x["bbox"] for x in annos]

If you think this is okay, I will submit a pull request. If you think that an additional BoxMode value would be better, I can try adding one and submit a pull request then. I’m looking forward to your reply.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
ssarucommented, Jan 20, 2020

Hi! now i trying visualize rotated bbox in detectron2. but it’s not visualize well

i build own get_dataset_dict as here

def get_rbox_detection_dicts():
    annotations = read_dataset()
    detection_anno = DetectionAnnotations(annotations)
    classes_list = collect_class_info(detection_anno)

    dataset_dicts = []
    for idx, FILE in enumerate(detection_anno.FILES):
        record = {}

        filename = FILE.FILEPATH
        height = FILE.IMAGE_HEIGHT
        width = FILE.IMAGE_WIDTH

        record["file_name"] = filename
        record["image_id"] = idx
        record["height"] = height
        record["width"] = width

        objs = []

        for OBJ in FILE.OBJECTS:
            xmin = OBJ.XMIN
            ymin = OBJ.YMIN
            xmax = OBJ.XMAX
            ymax = OBJ.YMAX
            theta = -OBJ.THETA

            classes = OBJ.CLASS

            cx, cy, bbox_w, bbox_h, angle = bbox_convert(xmin, ymin, xmax, ymax, theta)
            objs.append({"bbox": [cx, cy, bbox_w, bbox_h, angle],
                         "bbox_mode": BoxMode.XYWHA_ABS,
                         "category_id": classes_list.index(classes),
                         "iscrowd": 0})

            record["annotations"] = objs

        dataset_dicts.append(record)

    return dataset_dicts

after that i try visualize rotated box like here

DatasetCatalog.register("Rbox-Detection", get_rbox_detection_dicts)
MetadataCatalog.get("Rbox-Detection").set(thing_classes=["A", "B", "C", "D"])
rbox_detection_metadata = MetadataCatalog.get("Rbox-Detection")

dataset_dicts = get_rbox_detection_dicts()

import matplotlib.pyplot as plt

for d in random.sample(dataset_dicts, 3):
    img = cv2.imread(d["file_name"])
    visualizer = Visualizer(img[:, :, ::-1], metadata=rbox_detection_metadata, scale=1)

    vis = visualizer.draw_dataset_dict(d)
    test_img = vis.get_image()[:, :, ::-1]

    plt.figure()
    plt.imshow(test_img)
    plt.show()

but image display like this

so i fixed this line. like here

# Origin
boxes = [BoxMode.convert(x["bbox"], x["bbox_mode"], BoxMode.XYXY_ABS) for x in annos]

# Fixed
boxes = [BoxMode.convert(x["bbox"], x["bbox_mode"], BoxMode.XYWHA_ABS)
                     if x["bbox_mode"] is BoxMode.XYWHA_ABS else
                     BoxMode.convert(x["bbox"], x["bbox_mode"], BoxMode.XYXY_ABS) for x in annos]

https://github.com/facebookresearch/detectron2/blob/706a3185d187ea912b324eb0b5eac064ca0a62ce/detectron2/utils/visualizer.py#L489

as result it work well

2reactions
janzdcommented, Jan 13, 2020

That’s a way to bypass it and visualize rotated boxes with the current code, but hopefully some following updates will enable visualization of rotated boxes and training with rotated boxes by default.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Visualization of bounding boxes of the original and rotated ...
Visualization of bounding boxes of the original and rotated images. (a) is the original image obtained from the Inria dataset; (b) is the...
Read more >
How to Use Detectron2 for Rotated Bounding Box Detection ...
Before we can visualize the rotated bounding box annotations and train the model, we need to install Detectron2. Warning: this step may cause...
Read more >
Detecting Rotated Objects Using the NVIDIA Object Detection ...
This means that most of the objects in the image can be considered to be axis-aligned and can be described by four bounding...
Read more >
Rotated Bounding-Box Annotations for Mirror Worlds Dataset ...
The dataset is very useful for research on people detection from overhead fisheye cameras. However, all person objects in the videos are annotated...
Read more >
Image and Bounding Box Rotation Using OpenCV (Python)
Image rotation is a common task in image processing. You may also want to rotate bounding boxes if you work on machine learning...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found