mmengine
mmengine copied to clipboard
[Enhancement] Provide `OpenCV` backend for visualizer
#1101
Hi! Is this PR ready for review? It remains a draft.
Hi @HAOCHENYE , two functions are left to be implemented, I will issue a PR soon.
Hi @HAOCHENYE, I have issued the PR, please review. Thanks!
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).
Hi @HAOCHENYE, I have made the necessary changes, please review. Thanks!
Hi @HAOCHENYE, I have made the suggested changes, please review. Thanks!
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.
Hi @HAOCHENYE, I have updated the tests, please review. Thanks!
Hi @HAOCHENYE, is there anything else which needs to be done for this PR? Can you please elaborate?
Hi @HAOCHENYE, is there anything else which needs to be done for this PR? Can you please elaborate?
Your PR is not run correctly,
you need to see the detail and correct