<launch>
  <arg name="gui" default="true"/>

  <node name="image_publisher"
        pkg="jsk_perception" type="image_publisher.py">
    <rosparam subst_value="true">
      file_name: $(find jsk_perception)/sample/object_detection_example_1.jpg
      publish_info: false
    </rosparam>
  </node>
  <arg name="INPUT_IMAGE" default="image_publisher/output" />

  <node name="sample_manager"
        pkg="nodelet" type="nodelet"
        args="manager"
        output="screen"/>

  <node name="mask_image_generator_foreground"
        pkg="nodelet" type="nodelet"
        args="load jsk_perception/MaskImageGenerator /sample_manager">
    <remap from="~input" to="$(arg INPUT_IMAGE)"/>
    <rosparam>
      offset_x: 290
      offset_y: 50
      width: 30
      height: 220
    </rosparam>
  </node>

  <node name="mask_image_generator_background"
        pkg="nodelet" type="nodelet"
        args="load jsk_perception/MaskImageGenerator /sample_manager">
    <remap from="~input" to="$(arg INPUT_IMAGE)"/>
    <rosparam>
      offset_x: 400
      offset_y: 300
      width: 230
      height: 60
    </rosparam>
  </node>

  <node name="grabcut"
        pkg="nodelet" type="nodelet"
        args="load jsk_perception/GrabCut /sample_manager"
        respawn="true">
    <remap from="~input" to="$(arg INPUT_IMAGE)"/>
    <remap from="~input/foreground" to="mask_image_generator_foreground/output"/>
    <remap from="~input/background" to="mask_image_generator_background/output"/>
    <rosparam>
      seed_pixel_policy: 1
    </rosparam>
  </node>

  <group if="$(arg gui)">
    <node name="apply_mask_image_input_foreground"
          pkg="nodelet" type="nodelet"
          args="load jsk_perception/ApplyMaskImage /sample_manager">
      <remap from="~input" to="$(arg INPUT_IMAGE)"/>
      <remap from="~input/mask" to="mask_image_generator_foreground/output"/>
      <rosparam>
        clip: false
      </rosparam>
    </node>

    <node name="apply_mask_image_input_background"
          pkg="nodelet" type="nodelet"
          args="load jsk_perception/ApplyMaskImage /sample_manager">
      <remap from="~input" to="$(arg INPUT_IMAGE)"/>
      <remap from="~input/mask" to="mask_image_generator_background/output"/>
      <rosparam>
        clip: false
      </rosparam>
    </node>

    <node name="tile_image"
          pkg="jsk_perception" type="tile_image.py">
      <rosparam>
        input_topics:
          - /image_publisher/output
          - /apply_mask_image_input_foreground/output
          - /apply_mask_image_input_background/output
          - /grabcut/output/foreground
          - /grabcut/output/background
        draw_topic_name: true
      </rosparam>
    </node>

    <node name="image_view"
          pkg="image_view" type="image_view">
      <remap from="image" to="tile_image/output"/>
    </node>
  </group>
</launch>
