Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CodeCamp2023-305] Improve Visualizer Rendering Speed with OpenCV Backend #1285

Open
wants to merge 49 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 44 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
05e980c
first commit for original design
KerwinKai Aug 1, 2023
ed2d138
Merge branch 'open-mmlab:main' into add_cv2_backend_for_visualizer
KerwinKai Aug 1, 2023
5df7d5a
update draw_circle function and fix example
KerwinKai Aug 2, 2023
1333ca7
update draw_bboxes function and fix example
KerwinKai Aug 2, 2023
a567a30
add support for parameter alpha and face_colors in cv2 vis backend
KerwinKai Aug 2, 2023
5acb089
update function draw_polugons and generate face_colors to BGR in func…
KerwinKai Aug 2, 2023
0cb52b8
update function draw_binary_masks
KerwinKai Aug 2, 2023
07cadc5
update function draw_points and examples
KerwinKai Aug 2, 2023
35c5aa5
update function draw_text and fix example
KerwinKai Aug 3, 2023
29ade87
add pytest and fix code
KerwinKai Aug 3, 2023
3a6854a
Merge branch 'open-mmlab:main' into add_cv2_backend_for_visualizer
KerwinKai Aug 3, 2023
3aff1b8
Update mmengine/visualization/utils.py
KerwinKai Aug 6, 2023
4aaaa5a
Update mmengine/visualization/visualizer.py
KerwinKai Aug 6, 2023
6cb5cf9
Update mmengine/visualization/visualizer.py
KerwinKai Aug 6, 2023
a5a03ae
Update mmengine/visualization/visualizer.py
KerwinKai Aug 6, 2023
efc30b8
Update mmengine/visualization/visualizer.py
KerwinKai Aug 6, 2023
4ec978b
fix my code mention above
KerwinKai Aug 6, 2023
b4f7881
update the docstring
KerwinKai Aug 7, 2023
96fac84
update code to ignore some unnecessary mypy check
KerwinKai Aug 7, 2023
07c1685
update vis docs
KerwinKai Aug 7, 2023
1d5dce3
Update mmengine/visualization/visualizer.py
KerwinKai Aug 7, 2023
7fe6813
Update mmengine/visualization/visualizer.py
KerwinKai Aug 7, 2023
67c6e97
Update mmengine/visualization/visualizer.py
KerwinKai Aug 7, 2023
746594d
Update docs/en/design/visualization.md
KerwinKai Aug 7, 2023
66f3b04
update the backend argument in docstring
KerwinKai Aug 7, 2023
3fe0214
update code to follow the google python style to raise the exeception
KerwinKai Aug 7, 2023
3e6c69e
change 'None' to 'none'
KerwinKai Aug 7, 2023
7a31868
update my code mentioned by some previews
KerwinKai Aug 7, 2023
75832e5
update code, unit test and docstring for line_widths parameter
KerwinKai Aug 7, 2023
1c62151
Merge branch 'main' into add_cv2_backend_for_visualizer
KerwinKai Aug 7, 2023
a078ea6
resolve conflicts
KerwinKai Aug 7, 2023
cb61b70
setting 20 as a class attribute
KerwinKai Aug 7, 2023
74e515c
Update mmengine/visualization/visualizer.py
KerwinKai Aug 8, 2023
f4fd6ab
Compatible with backend parameter for show function
KerwinKai Aug 9, 2023
ef133dc
Update visualizer.py
KerwinKai Aug 9, 2023
217c511
try to fix ci/circleci
KerwinKai Aug 9, 2023
a35aa4c
Update mmengine/visualization/visualizer.py
KerwinKai Aug 9, 2023
65a052e
update `color_val_opencv` function and set self._image order `rgb` in…
KerwinKai Aug 11, 2023
d705ffe
fix ci
KerwinKai Aug 11, 2023
2c8fa19
fix docstring
KerwinKai Aug 11, 2023
2c051b1
fix ci
KerwinKai Aug 11, 2023
a0fe3ce
standard the input format to be RGB for all interfaces
KerwinKai Aug 14, 2023
530a34f
update marker type in matplotlib backend
KerwinKai Aug 14, 2023
7b90df1
mv parameter font_faces to the end
KerwinKai Aug 14, 2023
1f25984
Update mmengine/visualization/visualizer.py
KerwinKai Aug 14, 2023
e3378f1
also mv font_faces docstring to the end
KerwinKai Aug 14, 2023
ca7f3ab
Update mmengine/visualization/visualizer.py
KerwinKai Aug 14, 2023
7a88458
explain default font size 22
KerwinKai Aug 14, 2023
2398154
fix draw_binary_masks
KerwinKai Aug 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/en/design/visualization.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Based on the above requirements, we proposed the `Visualizer` and various `VisBa

- For convenience, the APIs provided by the `Visualizer` implement the drawing and storage functions. As an internal property of `Visualizer`, `VisBackend` will be called by `Visualizer` to write data to different backends.
- Considering that you may want to write data to multiple backends after drawing, `Visualizer` can be configured with multiple backends. When the user calls the storage API of the `Visualizer`, it will traverse and call all the specified APIs of `VisBackend` internally.
- Considering the difference in drawing performance, the drawing `backend` is an internal property of `Visualizer`, and users can choose a drawing backend according to the usage scenario to balance drawing performance and richness of drawing functions.

The UML diagram of the two is as follows.

Expand Down
1 change: 1 addition & 0 deletions docs/zh_cn/design/visualization.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

- 为了方便调用,Visualizer 提供的接口实现了绘制和存储的功能。可视化存储后端 VisBackend 作为 Visualizer 的内部属性,会在需要的时候被 Visualizer 调用,将数据存到不同的后端
- 考虑到绘制后会希望存储到多个后端,Visualizer 可以配置多个 VisBackend,当用户调用 Visualizer 的存储接口时候,Visualizer 内部会遍历的调用 VisBackend 存储接口
- 考虑到绘图性能的差异,绘图后端 backend 作为 Visualizer 的内部属性,用户可根据使用场景选择绘图后端,以达到绘图性能和绘图功能丰富性的平衡

两者的 UML 关系图如下

Expand Down
32 changes: 31 additions & 1 deletion mmengine/visualization/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ def color_val_matplotlib(
colors: Union[str, tuple, List[Union[str, tuple]]]
) -> Union[str, tuple, List[Union[str, tuple]]]:
"""Convert various input in RGB order to normalized RGB matplotlib color
tuples,
tuples.

Args:
colors (Union[str, tuple, List[Union[str, tuple]]]): Color inputs
Returns:
Expand All @@ -120,6 +121,35 @@ def color_val_matplotlib(
raise TypeError(f'Invalid type for color: {type(colors)}')


def color_val_opencv(
colors: Union[str, tuple, List[Union[str, tuple]]]
) -> Union[tuple, List[tuple]]:
"""Convert various input in RGB order to RGB color tuples.

Args:
colors (Union[str, tuple, List[Union[str, tuple]]]): Color inputs
Returns:
Union[str, tuple, List[Union[str, tuple]]]: A tuple of 3 ints
indicating RGB channels.
"""
if isinstance(colors, str):
colors = color_str2rgb(colors)
return colors
elif isinstance(colors, tuple):
assert len(colors) == 3
for channel in colors:
assert 0 <= channel <= 255
return colors
elif isinstance(colors, list):
colors = [
color_val_opencv(color) # type:ignore
for color in colors
]
return colors # type:ignore
else:
raise TypeError(f'Invalid type for color: {type(colors)}')


def color_str2rgb(color: str) -> tuple:
"""Convert Matplotlib str color to an RGB color which range is 0 to 255,
silently dropping the alpha channel.
Expand Down