Skip to content

Commit

Permalink
update ImmVision (Add IsColorOrderUndefined, Push/PopColorOrder) / fi…
Browse files Browse the repository at this point in the history
…x imgui_fix (color order)
  • Loading branch information
pthom committed Oct 8, 2024
1 parent 92d2d44 commit b5ded72
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 6 deletions.
9 changes: 4 additions & 5 deletions bindings/imgui_bundle/imgui_fig.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
matplotlib.use('Agg') # set the renderer to Tk
from matplotlib.figure import Figure # noqa: E402
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
Expand Down Expand Up @@ -37,10 +36,8 @@ def _fig_to_image(label_id: str, figure: Figure, refresh_image: bool = False) ->
w, h = figure.canvas.get_width_height()
buf = numpy.fromstring(figure.canvas.tostring_rgb(), dtype=numpy.uint8)
buf.shape = (h, w, 3)
if immvision.is_using_bgr_color_order():
img = cv2.cvtColor(buf, cv2.COLOR_RGB2BGR)
else:
img = buf

img = buf
matplotlib.pyplot.close(figure)
statics.fig_image_cache[fig_id] = img
return statics.fig_image_cache[fig_id]
Expand Down Expand Up @@ -78,7 +75,9 @@ def fig(label_id: str,
"""
image_rgb = _fig_to_image(label_id, figure, refresh_image)

immvision.push_color_order_rgb()
mouse_position_tuple = immvision.image_display_resizable(
label_id, image_rgb, size, refresh_image, resizable, show_options_button)
immvision.pop_color_order()
mouse_position = ImVec2(mouse_position_tuple[0], mouse_position_tuple[1])
return mouse_position
23 changes: 23 additions & 0 deletions bindings/imgui_bundle/immvision.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,29 @@ def is_using_bgr_color_order() -> bool:
"""
pass

# bool IsColorOrderUndefined(); /* original C++ signature */
def is_color_order_undefined() -> bool:
"""Returns True if the color order is undefined (i.e. UseRgbColorOrder or UseBgrColorOrder was not called)
(private API)
"""
pass

# Temporary change of color order (useful for displaying a single image with a different color order)
# void PushColorOrderRgb(); /* original C++ signature */
def push_color_order_rgb() -> None:
"""(private API)"""
pass

# void PushColorOrderBgr(); /* original C++ signature */
def push_color_order_bgr() -> None:
"""(private API)"""
pass

# void PopColorOrder(); /* original C++ signature */
def pop_color_order() -> None:
"""(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"""

Expand Down
12 changes: 12 additions & 0 deletions external/immvision/bindings/pybind_immvision.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ void py_init_module_immvision(py::module& m)
m.def("is_using_bgr_color_order",
ImmVision::IsUsingBgrColorOrder, " Returns True if we are using BGR color order\n(private API)");

m.def("is_color_order_undefined",
ImmVision::IsColorOrderUndefined, " Returns True if the color order is undefined (i.e. UseRgbColorOrder or UseBgrColorOrder was not called)\n(private API)");

m.def("push_color_order_rgb",
ImmVision::PushColorOrderRgb, "(private API)");

m.def("push_color_order_bgr",
ImmVision::PushColorOrderBgr, "(private API)");

m.def("pop_color_order",
ImmVision::PopColorOrder, "(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, "")
Expand Down

0 comments on commit b5ded72

Please sign in to comment.