Skip to content

Latest commit

 

History

History
149 lines (110 loc) · 4.99 KB

File metadata and controls

149 lines (110 loc) · 4.99 KB

Tutorial 02 — HelloParams: Parameter Types and Image Rotation

What you will learn

  • All core parameter types: IntParam, FloatParam, BoolParam, ChoiceParam, StringParam
  • The advanced=True attribute (hides parameters under the Advanced section)
  • The invalidate=False attribute (cosmetic parameters that don't trigger recomputation)
  • The semantic="image" attribute on outputs (enables 2D viewer display)

Prerequisites

  • Completed Tutorial 01 or equivalent understanding of the basic node structure.

Parameter types reference

desc.File

desc.File(
    name="input",
    label="Input Image",
    description="Path to the input image file.",
    value="",
)

A file path selector. In the Meshroom UI, it shows a text field with a file browser button.

desc.IntParam

desc.IntParam(
    name="angle",
    label="Rotation Angle",
    description="Rotation angle in degrees.",
    value=0,
    range=(-360, 360, 1),  # (min, max, step)
)

An integer parameter. Renders as a slider in the UI. The range tuple defines the slider bounds and step size.

IntParam

desc.FloatParam

desc.FloatParam(
    name="scale",
    label="Scale Factor",
    description="Scale factor applied after rotation.",
    value=1.0,
    range=(0.1, 3.0, 0.1),
    advanced=True,  # Hidden under the Advanced section
)

A floating-point parameter. Similar to IntParam but with decimal precision. Setting advanced=True hides it under an expandable "Advanced" section — useful for parameters that most users won't need to change. To reveal advanced parameters in the Meshroom UI, right-click on the node's attribute panel and enable the Advanced filter:

Enabling advanced parameters

desc.BoolParam

desc.BoolParam(
    name="flip",
    label="Flip Horizontal",
    description="If enabled, flips the image horizontally.",
    value=False,
)

A boolean parameter. Renders as a checkbox.

desc.ChoiceParam

desc.ChoiceParam(
    name="interpolation",
    label="Interpolation",
    description="Interpolation method for rotation.",
    values=["NEAREST", "LINEAR", "CUBIC"],
    value="LINEAR",
    exclusive=True,  # Required on all ChoiceParams
)

A dropdown selector. exclusive=True is required on all ChoiceParams in the Meshroom ecosystem — it means only one value can be selected.

ChoiceParam

desc.StringParam

desc.StringParam(
    name="textOverlay",
    label="Text Overlay",
    description="Optional text to draw on the image.",
    value="",
    invalidate=False,  # Cosmetic — doesn't trigger recomputation
)

A free text input field. Setting invalidate=False means changing this parameter does not mark the node as "needs recomputation". Use this for cosmetic or metadata-only parameters.

The processing logic

HelloParams reads the parameters and applies them using OpenCV:

  1. Rotation: cv2.getRotationMatrix2D + cv2.warpAffine with the user-defined angle and scale.
  2. Flip: cv2.flip(image, 1) when the boolean is True.
  3. Text overlay: cv2.putText with white text and a black outline for readability.

The interpolation ChoiceParam is mapped to OpenCV constants:

interp_map = {
    "NEAREST": cv2.INTER_NEAREST,
    "LINEAR": cv2.INTER_LINEAR,
    "CUBIC": cv2.INTER_CUBIC,
}

How to test it

A pre-configured project is available: open meshroom/tuto02-hello-params.mg in Meshroom (make sure you have run scripts/setup_projects.sh first). Or set it up manually:

  1. Add a HelloParams node to your graph.
  2. Set the Input Image field to the path of your test image.
  3. Set Rotation Angle to 90.
  4. Click Compute.
  5. To view the output in the 2D viewer, double-click on the node or use the dropdown menu at the bottom of the 2D viewer and select Output Image.
  6. The output should be the image rotated 90 degrees clockwise.
  7. Try enabling Flip Horizontal, changing Scale Factor, and adding Text Overlay.

HelloParams output

Going further

HelloParams covers the core parameter types. For more advanced patterns:

  • GroupAttribute: Groups related parameters into a collapsible section. Used in mrSegmentation.
  • ListAttribute: A list of values (e.g., multiple file paths). Used in nodes that accept variable-length inputs.
  • enabled lambda on outputs: enabled=lambda node: node.someParam.value conditionally shows/hides an output. Used when an output only makes sense with certain parameter combinations.

These patterns are documented in the Meshroom source code and in production plugins like mrSegmentation.