Skip to content

Commit

Permalink
update immvision (Add IsUsingRgbColorOrder() / IsUsingBgrColorOrder()…
Browse files Browse the repository at this point in the history
…) / use in imgui_fig
  • Loading branch information
pthom committed Oct 6, 2024
1 parent dcc980a commit 1e2166e
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 26 deletions.
25 changes: 14 additions & 11 deletions bindings/imgui_bundle/imgui_fig.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
"""imgui_fig.fig: Display Matplotlib figures in an ImGui window.
Important: before importing pyplot, set the renderer to Tk,
so that the figure is not displayed on the screen before we can capture it.
so that the figure is not displayed on the screen before we can capture it:
import matplotlib
matplotlib.use('Agg')
"""
import matplotlib
matplotlib.use('Agg') #
import matplotlib.pyplot as plt

import numpy
import cv2
import matplotlib
from imgui_bundle.immapp import static
from imgui_bundle import immvision, ImVec2, imgui
matplotlib.use('Agg') # set the renderer to Tk
import numpy # noqa: E402
import cv2 # noqa: E402
import matplotlib # noqa: E402
from imgui_bundle.immapp import static # noqa: E402
from imgui_bundle import immvision, ImVec2, imgui # noqa: E402


@static(fig_image_cache=dict())
Expand All @@ -36,9 +36,12 @@ def _fig_to_image(label_id: str, figure: matplotlib.figure.Figure, refresh_image
w, h = figure.canvas.get_width_height()
buf = numpy.fromstring(figure.canvas.tostring_rgb(), dtype=numpy.uint8)
buf.shape = (h, w, 3)
img_rgb = cv2.cvtColor(buf, cv2.COLOR_RGB2BGR)
if immvision.is_using_bgr_color_order():
img = cv2.cvtColor(buf, cv2.COLOR_RGB2BGR)
else:
img = buf
matplotlib.pyplot.close(figure)
statics.fig_image_cache[fig_id] = img_rgb
statics.fig_image_cache[fig_id] = img
return statics.fig_image_cache[fig_id]


Expand Down
32 changes: 23 additions & 9 deletions bindings/imgui_bundle/immvision.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,6 @@ ImTextureID: TypeAlias = int
# IMMVISION_API is a marker for public API functions. IMMVISION_STRUCT_API is a marker for public API structs (in comment lines)
# Usage of ImmVision as a shared library is not recommended. No guaranty of ABI stability is provided

class ColorMapStatsTypeId(enum.Enum):
"""Are we using the stats on the full image, on the Visible ROI, or are we using Min/Max values"""

# FromFullImage, /* original C++ signature */
from_full_image = enum.auto() # (= 0)
# FromVisibleROI /* original C++ signature */
# }
from_visible_roi = enum.auto() # (= 1)

# Set the color order for displayed images.
# You **must** call once at the start of your program:
# ImmVision::UseRgbColorOrder() or ImmVision::UseBgrColorOrder() (C++)
Expand All @@ -62,6 +53,29 @@ def use_bgr_color_order() -> None:
"""(private API)"""
pass

# bool IsUsingRgbColorOrder(); /* original C++ signature */
def is_using_rgb_color_order() -> bool:
"""Returns True if we are using RGB color order
(private API)
"""
pass

# bool IsUsingBgrColorOrder(); /* original C++ signature */
def is_using_bgr_color_order() -> bool:
"""Returns True if we are using BGR color order
(private API)
"""
pass

class ColorMapStatsTypeId(enum.Enum):
"""Are we using the stats on the full image, on the Visible ROI, or are we using Min/Max values"""

# FromFullImage, /* original C++ signature */
from_full_image = enum.auto() # (= 0)
# FromVisibleROI /* original C++ signature */
# }
from_visible_roi = enum.auto() # (= 1)

class ColormapScaleFromStatsData:
"""Scale the Colormap according to the Image stats
Expand Down
16 changes: 11 additions & 5 deletions external/immvision/bindings/pybind_immvision.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,23 @@ void py_init_module_immvision(py::module& m)
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! AUTOGENERATED CODE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// <litgen_pydef> // Autogenerated code below! Do not edit!
//////////////////// <generated_from:immvision.h> ////////////////////
py::enum_<ImmVision::ColorMapStatsTypeId>(m, "ColorMapStatsTypeId", py::arithmetic(), "Are we using the stats on the full image, on the Visible ROI, or are we using Min/Max values")
.value("from_full_image", ImmVision::ColorMapStatsTypeId::FromFullImage, "")
.value("from_visible_roi", ImmVision::ColorMapStatsTypeId::FromVisibleROI, "");


m.def("use_rgb_color_order",
ImmVision::UseRgbColorOrder, "(private API)");

m.def("use_bgr_color_order",
ImmVision::UseBgrColorOrder, "(private API)");

m.def("is_using_rgb_color_order",
ImmVision::IsUsingRgbColorOrder, " Returns True if we are using RGB color order\n(private API)");

m.def("is_using_bgr_color_order",
ImmVision::IsUsingBgrColorOrder, " Returns True if we are using BGR color order\n(private API)");


py::enum_<ImmVision::ColorMapStatsTypeId>(m, "ColorMapStatsTypeId", py::arithmetic(), "Are we using the stats on the full image, on the Visible ROI, or are we using Min/Max values")
.value("from_full_image", ImmVision::ColorMapStatsTypeId::FromFullImage, "")
.value("from_visible_roi", ImmVision::ColorMapStatsTypeId::FromVisibleROI, "");


auto pyClassColormapScaleFromStatsData =
py::class_<ImmVision::ColormapScaleFromStatsData>
Expand Down

0 comments on commit 1e2166e

Please sign in to comment.