mmengine icon indicating copy to clipboard operation
mmengine copied to clipboard

[Enhancement] Provide `OpenCV` backend for visualizer

Open Om-Doiphode opened this issue 2 years ago • 10 comments

#1101

Om-Doiphode avatar May 10 '23 18:05 Om-Doiphode

Hi! Is this PR ready for review? It remains a draft.

HAOCHENYE avatar May 17 '23 13:05 HAOCHENYE

Hi @HAOCHENYE , two functions are left to be implemented, I will issue a PR soon.

Om-Doiphode avatar May 17 '23 13:05 Om-Doiphode

Hi @HAOCHENYE, I have issued the PR, please review. Thanks!

Om-Doiphode avatar May 17 '23 15:05 Om-Doiphode

Hi, we should provide the OpenCV backend for Visualizer to draw bboxes, points, .etc, just like the show method does:

https://github.com/open-mmlab/mmengine/blob/4bc2fe1aaec2d7d1464b11d50f6165494f62ef18/mmengine/visualization/visualizer.py#L228

Although there will be a lot of if-else logic, it is the only way to make downstream repos can use the OpenCV backend without changing their code (They have already implemented their Visualizer by inheriting the current Visualizer).

HAOCHENYE avatar May 19 '23 07:05 HAOCHENYE

Hi @HAOCHENYE, I have made the necessary changes, please review. Thanks!

Om-Doiphode avatar May 19 '23 17:05 Om-Doiphode

Hi @HAOCHENYE, I have made the suggested changes, please review. Thanks!

Om-Doiphode avatar May 26 '23 16:05 Om-Doiphode

Hi, you can update the unittest in test_visualizer.py like this:

from parameterized import parameterized

...

    @parameterized.expand([['cv2'], ['matplotlib']])
    def test_draw_bboxes(self, backend):
        visualizer = Visualizer(image=self.image)

        # only support 4 or nx4 tensor and numpy
        visualizer.draw_bboxes(torch.tensor([1, 1, 2, 2]), backend=backend)
        # valid bbox
        visualizer.draw_bboxes(torch.tensor([1, 1, 1, 2]), backend=backend)
        bboxes = torch.tensor([[1, 1, 2, 2], [1, 2, 2, 2.5]])
        visualizer.draw_bboxes(
            bboxes, alpha=0.5, edge_colors=(255, 0, 0), line_styles='-', backend=backend)
        bboxes = bboxes.numpy()
        visualizer.draw_bboxes(bboxes, backend=backend)

        # test invalid bbox
        with pytest.raises(AssertionError):
            # x1 > x2
            visualizer.draw_bboxes(torch.tensor([5, 1, 2, 2]))

        # test out of bounds
        with pytest.warns(
                UserWarning,
                match='Warning: The bbox is out of bounds,'
                ' the drawn bbox may not be in the image'):
            visualizer.draw_bboxes(torch.tensor([1, 1, 20, 2]))

        # test incorrect bbox format
        with pytest.raises(TypeError):
            visualizer.draw_bboxes([1, 1, 2, 2])

I get some unexpected error when updating the unit test.

HAOCHENYE avatar Jun 01 '23 05:06 HAOCHENYE

Hi @HAOCHENYE, I have updated the tests, please review. Thanks!

Om-Doiphode avatar Jun 05 '23 12:06 Om-Doiphode

Hi @HAOCHENYE, is there anything else which needs to be done for this PR? Can you please elaborate?

Om-Doiphode avatar Jun 12 '23 05:06 Om-Doiphode

Hi @HAOCHENYE, is there anything else which needs to be done for this PR? Can you please elaborate?

Your PR is not run correctly,
image

you need to see the detail and correct image

CastleDream avatar Jul 25 '23 03:07 CastleDream