Example #1
0
    def callbackFunction(annotations: List[List[Dict[str, float]]]):  # pylint: disable=invalid-name
        """Callback function.

    This is the call back function to capture the data from the frontend and
    convert the data into a numpy array.

    Args:
      annotations: list[list[dict[str, float]]]
        The input of the call back function is a list of list of objects
        corresponding to the annotations. The format of annotations is shown
        below

        [
          // stuff for image 1
          [
            // stuff for rect 1
            {x, y, w, h},
            // stuff for rect 2
            {x, y, w, h},
            ...
          ],
          // stuff for image 2
          [
            // stuff for rect 1
            {x, y, w, h},
            // stuff for rect 2
            {x, y, w, h},
            ...
          ],
          ...
        ]
    """

        # reset the boxes list
        nonlocal box_storage_pointer
        boxes: List[np.ndarray] = box_storage_pointer
        boxes.clear()

        # load the new annotations into the boxes list
        for annotations_per_img in annotations:
            rectangles_as_arrays = [
                np.clip(dictToList(annotation), 0, 1)
                for annotation in annotations_per_img
            ]
            if rectangles_as_arrays:
                boxes.append(np.stack(rectangles_as_arrays))
            else:
                boxes.append(None)

        # output the annotations to the errorlog
        with output.redirect_to_element('#errorlog'):
            display('--boxes array populated--')
Example #2
0
 def _active_component(self, component_id):
     """Sets active subcomponent."""
     if not self._published:
         self._publish()
     if self._current_component is not None:
         raise WidgetException('Already inside a component')
     self._current_component = component_id
     _util.flush_all()
     with self._output_in_widget():
         with output.use_tags(self._current_component):
             with output.redirect_to_element('#' + component_id):
                 with output.use_tags('user_output'):
                     try:
                         yield
                     finally:
                         _util.flush_all()
                         self._current_component = None