Skip to content

Pipeline Parameters

firepick1 edited this page Mar 23, 2014 · 9 revisions

If you find yourself creating many pipelines that only differ by a few simple values, you may want to consider using pipeline parameters. A pipeline parameter is a name/value pair with an optional default. Consider the following pipeline to resize an image to 50% of the original size:

[
  {"op":"resize", "fx":0.5, "fy":0.5}
]

If we want to resize an image by 75%, we could certainly create another pipeline. However, it may be easier to use a pipeline with parameters {fx}} and {{fy}}. Specifically, the caller provides definitions for fx and fy, since the braces are parameter delimiters:

[
  {"op":"resize", "fx":"{{fx}}", "fy":"{{fy}}"}
]

If the caller does NOT provide a parameter's value, then you'll get an error unless you provide a default value using the || delimiter:

[
  {"op":"resize", "fx":"{{fx||0.5}}", "fy":"{{fy||0.5}}"}
]

Pipeline parameter values can be defined using the -D option of firesight:

firesight -i img/duck.jpg -p json/resize.json -o target/resize.jpg -Dfx=0.25 -Dfy=0.5

←Original Duck ←Parametrically resized Duck

For C++ users, see FireSight.cpp for an example of using an ArgMap to provide parameter values.

JSON Data Types

In the above example, we introduced a parameter for a JSON numeric double value. More precisely, we specified the parameter using a string (e.g., "{{fy||0.5}}"), and a string isn't a JSON number. FireSight handles this by applying the JSON parser to any value with embedded parameter delimiters (i.e., "{{"). Since the string is parsed, we end up with a real JSON object as the replacement. This lets us parameterize a JSON array used to represent a BGR color that defaults to magenta:

[
  {"op":"rectangle", "width":"{{width}}", "height":"{{height}}", "color":"{{color||[255,0,255]}}"}
]

See Also

Clone this wiki locally