<launch>

  <arg name="gui" default="true" />
  <arg name="gpu" default="0" />

  <arg name="COCO" default="false" doc="true: COCO, false: VOC" />

  <arg name="person_label" value="0" if="$(arg COCO)" />
  <arg name="person_label" value="14" unless="$(arg COCO)" />

  <arg name="approximate_sync" default="true" />
  <arg name="slop" default="1.0" />

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

  <include file="$(find jsk_perception)/launch/mask_rcnn_instance_segmentation.launch">
    <arg name="INPUT_IMAGE" default="$(arg INPUT_IMAGE)" />
    <arg name="gpu" value="$(arg gpu)" />
    <arg name="gui" value="false" />
    <arg name="COCO" value="$(arg COCO)" />
  </include>

  <!-- use cluster_indices and labels -->
  <node name="image_cluster_indices_decomposer"
        pkg="jsk_perception" type="image_cluster_indices_decomposer.py"
        clear_params="true">
    <remap from="~input" to="$(arg INPUT_IMAGE)" />
    <remap from="~input/cluster_indices"
           to="mask_rcnn_instance_segmentation/output/cluster_indices" />
  </node>

  <!-- use lbl_cls and lbl_ins -->
  <node name="label_cls_to_mask"
        pkg="jsk_perception" type="label_to_mask_image"
        clear_params="true">
    <remap from="~input" to="mask_rcnn_instance_segmentation/output/label_cls" />
    <rosparam subst_value="true">
      label_value: $(arg person_label)
    </rosparam>
  </node>
  <node name="apply_mask_image"
        pkg="jsk_perception" type="apply_mask_image"
        clear_params="true">
    <remap from="~input" to="mask_rcnn_instance_segmentation/output/label_ins" />
    <remap from="~input/mask" to="label_cls_to_mask/output" />
    <rosparam subst_value="true">
      clip: false
      cval: -1
    </rosparam>
  </node>
  <node name="label_image_decomposer"
        pkg="jsk_perception" type="label_image_decomposer.py"
        clear_params="true">
    <remap from="~input" to="$(arg INPUT_IMAGE)" />
    <remap from="~input/label" to="apply_mask_image/output" />
    <rosparam subst_value="true">
      bg_label: -1
      queue_size: 50
    </rosparam>
  </node>

  <node name="tile_image"
        pkg="jsk_perception" type="tile_image.py"
        clear_params="true">
    <rosparam subst_value="true">
      input_topics:
        - $(arg INPUT_IMAGE)
        - mask_rcnn_instance_segmentation/output/viz
        - image_cluster_indices_decomposer/output
        - label_image_decomposer/output/label_viz
      draw_topic_name: true
      font_scale: 0.8
      font_thickness: 2
    </rosparam>
  </node>

  <group if="$(arg gui)">
    <node name="image_view"
          pkg="image_view" type="image_view"
          clear_params="true">
      <remap from="image" to="tile_image/output" />
    </node>
  </group>

</launch>
