Skip to content

Commit

Permalink
Update immvision (Add json serialization for ImageParams)
Browse files Browse the repository at this point in the history
  • Loading branch information
pthom committed Mar 22, 2024
1 parent 0af13b4 commit 8b95c2f
Show file tree
Hide file tree
Showing 7 changed files with 25,012 additions and 27 deletions.
45 changes: 32 additions & 13 deletions bindings/imgui_bundle/immvision.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,27 @@ class ImageParams: # immvision.h:96
"""Auto-generated default constructor with named params"""
pass

# #ifdef IMMVISION_SERIALIZE_JSON
#
# IMMVISION_API std::string ImageParamsToJson(const ImageParams& params); /* original C++ signature */
def image_params_to_json(params: ImageParams) -> str: # immvision.h:195
pass

# IMMVISION_API void FillImageParamsFromJson(const std::string& json, ImageParams* params); /* original C++ signature */
def fill_image_params_from_json(
json: str, params: ImageParams
) -> None: # immvision.h:196
pass

# IMMVISION_API ImageParams ImageParamsFromJson(const std::string& json); /* original C++ signature */
def image_params_from_json(json: str) -> ImageParams: # immvision.h:197
pass

# #endif
#

# IMMVISION_API ImageParams FactorImageParamsDisplayOnly(); /* original C++ signature */
def factor_image_params_display_only() -> ImageParams: # immvision.h:196
def factor_image_params_display_only() -> ImageParams: # immvision.h:201
"""Create ImageParams that display the image only, with no decoration, and no user interaction"""
pass

Expand All @@ -317,7 +336,7 @@ def factor_image_params_display_only() -> ImageParams: # immvision.h:196
# double zoomRatio,
# const cv::Size displayedImageSize
# );
def make_zoom_pan_matrix( # immvision.h:200
def make_zoom_pan_matrix( # immvision.h:205
zoom_center: Point2d, zoom_ratio: float, displayed_image_size: Size
) -> Matx33d:
"""Create a zoom/pan matrix centered around a given point of interest"""
Expand All @@ -327,7 +346,7 @@ def make_zoom_pan_matrix( # immvision.h:200
# cv::Size imageSize,
# const cv::Size displayedImageSize
# );
def make_zoom_pan_matrix_scale_one( # immvision.h:206
def make_zoom_pan_matrix_scale_one( # immvision.h:211
image_size: Size, displayed_image_size: Size
) -> Matx33d:
pass
Expand All @@ -336,13 +355,13 @@ def make_zoom_pan_matrix_scale_one( # immvision.h:206
# cv::Size imageSize,
# const cv::Size displayedImageSize
# );
def make_zoom_pan_matrix_full_view( # immvision.h:211
def make_zoom_pan_matrix_full_view( # immvision.h:216
image_size: Size, displayed_image_size: Size
) -> Matx33d:
pass

# IMMVISION_API void Image(const std::string& label, const cv::Mat& mat, ImageParams* params); /* original C++ signature */
def image(label: str, mat: Mat, params: ImageParams) -> None: # immvision.h:251
def image(label: str, mat: Mat, params: ImageParams) -> None: # immvision.h:256
"""Display an image, with full user control: zoom, pan, watch pixels, etc.
:param label
Expand Down Expand Up @@ -388,7 +407,7 @@ def image(label: str, mat: Mat, params: ImageParams) -> None: # immvision.h:251
# bool showOptionsButton = false,
# bool isBgrOrBgra = true
# );
def image_display( # immvision.h:297
def image_display( # immvision.h:302
label_id: str,
mat: Mat,
image_display_size: Size = (0, 0),
Expand Down Expand Up @@ -443,14 +462,14 @@ def image_display( # immvision.h:297
pass

# IMMVISION_API std::vector<std::string> AvailableColormaps(); /* original C++ signature */
def available_colormaps() -> List[str]: # immvision.h:309
def available_colormaps() -> List[str]: # immvision.h:314
"""Return the list of the available color maps
Taken from https://github.com/yuki-koyama/tinycolormap, thanks to Yuki Koyama
"""
pass

# IMMVISION_API void ClearTextureCache(); /* original C++ signature */
def clear_texture_cache() -> None: # immvision.h:316
def clear_texture_cache() -> None: # immvision.h:321
"""Clears the internal texture cache of immvision (this is done automatically at exit time)
Note: this function requires that both imgui and OpenGL were initialized.
Expand All @@ -459,15 +478,15 @@ def clear_texture_cache() -> None: # immvision.h:316
pass

# IMMVISION_API cv::Mat GetCachedRgbaImage(const std::string& label); /* original C++ signature */
def get_cached_rgba_image(label: str) -> cv.Mat: # immvision.h:321
def get_cached_rgba_image(label: str) -> cv.Mat: # immvision.h:326
"""Returns the RGBA image currently displayed by ImmVision::Image or ImmVision::ImageDisplay
Note: this image must be currently displayed. This function will return the transformed image
(i.e with ColorMap, Zoom, etc.)
"""
pass

# IMMVISION_API std::string VersionInfo(); /* original C++ signature */
def version_info() -> str: # immvision.h:324
def version_info() -> str: # immvision.h:329
"""Return immvision version info"""
pass

Expand All @@ -493,7 +512,7 @@ def version_info() -> str: # immvision.h:324
# double zoomRatio = -1.,
# bool isColorOrderBGR = true
# );
def inspector_add_image( # immvision.h:345
def inspector_add_image( # immvision.h:350
image: Mat,
legend: str,
zoom_key: str = "",
Expand All @@ -505,11 +524,11 @@ def inspector_add_image( # immvision.h:345
pass

# IMMVISION_API void Inspector_Show(); /* original C++ signature */
def inspector_show() -> None: # immvision.h:355
def inspector_show() -> None: # immvision.h:360
pass

# IMMVISION_API void Inspector_ClearImages(); /* original C++ signature */
def inspector_clear_images() -> None: # immvision.h:357
def inspector_clear_images() -> None: # immvision.h:362
pass

#################### </generated_from:immvision.h> ####################
Expand Down
11 changes: 11 additions & 0 deletions external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ if(IMGUI_BUNDLE_INSTALL_CPP)
ibd_add_installable_dependency(fplus)
endif()

# Add nlohmann_json
add_library(nlohmann_json INTERFACE)
target_include_directories(nlohmann_json INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/nlohmann_json>)
if(IMGUI_BUNDLE_INSTALL_CPP)
install(DIRECTORY nlohmann_json/nlohmann DESTINATION include)
ibd_add_installable_dependency(nlohmann_json)
endif()


###############################################################################
# Build ImGui & Hello ImGui
Expand Down Expand Up @@ -52,6 +60,9 @@ endif()
if(HELLOIMGUI_HAS_OPENGL AND NOT IMGUI_BUNDLE_DISABLE_IMMVISION)
add_subdirectory(immvision)
if (IMGUI_BUNDLE_WITH_IMMVISION)
set(IMMVISION_SERIALIZE_JSON ON CACHE INTERNAL "" FORCE)
target_link_libraries(immvision PUBLIC nlohmann_json)

target_link_libraries(imgui_bundle INTERFACE immvision)
hello_imgui_msvc_target_group_sources(immvision)
target_compile_definitions(imgui_bundle INTERFACE IMGUI_BUNDLE_WITH_IMMVISION)
Expand Down
1 change: 1 addition & 0 deletions external/immvision/bindings/generate_immvision.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def main():
options.original_location_flag_show = True
options.namespaces_root = ["ImmVision"]
options.srcmlcpp_options.functions_api_prefixes = "IMMVISION_API"
options.srcmlcpp_options.header_filter_acceptable__regex = r"IMMVISION_SERIALIZE_JSON"
options.python_run_black_formatter = True
options.fn_exclude_non_api = False

Expand Down
38 changes: 25 additions & 13 deletions external/immvision/bindings/pybind_immvision.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,54 +175,66 @@ void py_init_module_immvision(py::module& m)
.def_readwrite("highlight_watched_pixels", &ImmVision::ImageParams::HighlightWatchedPixels, "Shall the watched pixels be drawn on the image") // immvision.h:186
.def_readwrite("mouse_info", &ImmVision::ImageParams::MouseInfo, "Mouse position information. These values are filled after displaying an image") // immvision.h:189
;
// #ifdef IMMVISION_SERIALIZE_JSON
//

m.def("image_params_to_json", // immvision.h:195
ImmVision::ImageParamsToJson, py::arg("params"));

m.def("factor_image_params_display_only", // immvision.h:196
m.def("fill_image_params_from_json", // immvision.h:196
ImmVision::FillImageParamsFromJson, py::arg("json"), py::arg("params"));

m.def("image_params_from_json", // immvision.h:197
ImmVision::ImageParamsFromJson, py::arg("json"));
// #endif
//

m.def("factor_image_params_display_only", // immvision.h:201
ImmVision::FactorImageParamsDisplayOnly, "Create ImageParams that display the image only, with no decoration, and no user interaction");

m.def("make_zoom_pan_matrix", // immvision.h:200
m.def("make_zoom_pan_matrix", // immvision.h:205
ImmVision::MakeZoomPanMatrix,
py::arg("zoom_center"), py::arg("zoom_ratio"), py::arg("displayed_image_size"),
"Create a zoom/pan matrix centered around a given point of interest");

m.def("make_zoom_pan_matrix_scale_one", // immvision.h:206
m.def("make_zoom_pan_matrix_scale_one", // immvision.h:211
ImmVision::MakeZoomPanMatrix_ScaleOne, py::arg("image_size"), py::arg("displayed_image_size"));

m.def("make_zoom_pan_matrix_full_view", // immvision.h:211
m.def("make_zoom_pan_matrix_full_view", // immvision.h:216
ImmVision::MakeZoomPanMatrix_FullView, py::arg("image_size"), py::arg("displayed_image_size"));

m.def("image", // immvision.h:251
m.def("image", // immvision.h:256
ImmVision::Image,
py::arg("label"), py::arg("mat"), py::arg("params"),
" Display an image, with full user control: zoom, pan, watch pixels, etc.\n\n :param label\n A legend that will be displayed.\n Important notes:\n - With ImGui and ImmVision, widgets *must* have a unique Ids.\n For this widget, the id is given by this label.\n Two widgets (for example) two images *cannot* have the same label or the same id!\n (you can use ImGui::PushID / ImGui::PopID to circumvent this, or add suffixes with ##)\n\n If they do, they might not refresh correctly!\n To circumvent this, you can:\n - Call `ImGui::PushID(\"some_unique_string\")` at the start of your function,\n and `ImGui::PopID()` at the end.\n - Or modify your label like this:\n \"MyLabel##some_unique_id\"\n (the part after \"##\" will not be displayed but will be part of the id)\n - To display an empty legend, use \"##_some_unique_id\"\n\n :param mat\n An image you want to display, under the form of an OpenCV matrix. All types of dense matrices are supported.\n\n :param params\n Complete options (as modifiable inputs), and outputs (mouse position, watched pixels, etc)\n @see ImageParams structure.\n The ImageParams may be modified by this function: you can extract from them\n the mouse position, watched pixels, etc.\n Important note:\n ImageParams is an input-output parameter, passed as a pointer.\n Its scope should be wide enough so that it is preserved from frame to frame.\n !! If you cannot zoom/pan in a displayed image, extend the scope of the ImageParams !!\n\n - This function requires that both imgui and OpenGL were initialized.\n (for example, use `imgui_runner.run`for Python, or `HelloImGui::Run` for C++)");

m.def("image_display", // immvision.h:297
m.def("image_display", // immvision.h:302
ImmVision::ImageDisplay,
py::arg("label_id"), py::arg("mat"), py::arg("image_display_size") = cv::Size(), py::arg("refresh_image") = false, py::arg("show_options_button") = false, py::arg("is_bgr_or_bgra") = true,
" Only, display the image, with no decoration, and no user interaction (by default)\n\n Parameters:\n :param label_id\n A legend that will be displayed.\n Important notes:\n - With ImGui and ImmVision, widgets must have a unique Ids. For this widget, the id is given by this label.\n Two widgets (for example) two images *cannot* have the same label or the same id!\n If they do, they might not refresh correctly!\n To circumvent this, you can modify your label like this:\n \"MyLabel##some_unique_id\" (the part after \"##\" will not be displayed but will be part of the id)\n - To display an empty legend, use \"##_some_unique_id\"\n\n :param mat:\n An image you want to display, under the form of an OpenCV matrix. All types of dense matrices are supported.\n\n :param imageDisplaySize:\n Size of the displayed image (can be different from the mat size)\n If you specify only the width or height (e.g (300, 0), then the other dimension\n will be calculated automatically, respecting the original image w/h ratio.\n\n :param refreshImage:\n images textures are cached. Set to True if your image matrix/buffer has changed\n (for example, for live video images)\n\n :param showOptionsButton:\n If True, show an option button that opens the option panel.\n In that case, it also becomes possible to zoom & pan, add watched pixel by double-clicking, etc.\n\n :param isBgrOrBgra:\n set to True if the color order of the image is BGR or BGRA (as in OpenCV, by default)\n\n :return:\n The mouse position in `mat` original image coordinates, as double values.\n (i.e. it does not matter if imageDisplaySize is different from mat.size())\n It will return (-1., -1.) if the mouse is not hovering the image.\n\n Note: use ImGui::IsMouseDown(mouse_button) (C++) or imgui.is_mouse_down(mouse_button) (Python)\n to query more information about the mouse.\n\n Note: this function requires that both imgui and OpenGL were initialized.\n (for example, use `imgui_runner.run`for Python, or `HelloImGui::Run` for C++)\n");

m.def("available_colormaps", // immvision.h:309
m.def("available_colormaps", // immvision.h:314
ImmVision::AvailableColormaps, " Return the list of the available color maps\n Taken from https://github.com/yuki-koyama/tinycolormap, thanks to Yuki Koyama");

m.def("clear_texture_cache", // immvision.h:316
m.def("clear_texture_cache", // immvision.h:321
ImmVision::ClearTextureCache, " Clears the internal texture cache of immvision (this is done automatically at exit time)\n\n Note: this function requires that both imgui and OpenGL were initialized.\n (for example, use `imgui_runner.run`for Python, or `HelloImGui::Run` for C++)");

m.def("get_cached_rgba_image", // immvision.h:321
m.def("get_cached_rgba_image", // immvision.h:326
ImmVision::GetCachedRgbaImage,
py::arg("label"),
" Returns the RGBA image currently displayed by ImmVision::Image or ImmVision::ImageDisplay\n Note: this image must be currently displayed. This function will return the transformed image\n (i.e with ColorMap, Zoom, etc.)");

m.def("version_info", // immvision.h:324
m.def("version_info", // immvision.h:329
ImmVision::VersionInfo, "Return immvision version info");


m.def("inspector_add_image", // immvision.h:345
m.def("inspector_add_image", // immvision.h:350
ImmVision::Inspector_AddImage, py::arg("image"), py::arg("legend"), py::arg("zoom_key") = "", py::arg("colormap_key") = "", py::arg("zoom_center") = cv::Point2d(), py::arg("zoom_ratio") = -1., py::arg("is_color_order_bgr") = true);

m.def("inspector_show", // immvision.h:355
m.def("inspector_show", // immvision.h:360
ImmVision::Inspector_Show);

m.def("inspector_clear_images", // immvision.h:357
m.def("inspector_clear_images", // immvision.h:362
ImmVision::Inspector_ClearImages);
//////////////////// </generated_from:immvision.h> ////////////////////

Expand Down
Loading

0 comments on commit 8b95c2f

Please sign in to comment.