コード例 #1
0
    def test_send_and_recv_setExt(self):
        port_in = yarp.Port()
        in_port_name = '/test/img:i'
        self.assertTrue(port_in.open(in_port_name))
        port_out = yarp.Port()
        port_out.enableBackgroundWrite(True);
        out_port_name = '/test/img:o'
        self.assertTrue(port_out.open(out_port_name))
        self.assertTrue(yarp.Network.connect(port_out.getName(), port_in.getName()))
        yarp.delay(0.5)
        height = 240
        width = 320
        yarp_img_out = yarp.ImageMono()
        yarp_img_out.resize(width, height)
        yarp_img_in = yarp.ImageMono()
        self.assertEqual(240, yarp_img_out.height())
        self.assertEqual(320, yarp_img_out.width())
        yarp_vector = yarp.Vector()
        yarp_vector.resize(320*240, 0)
        self.assertTrue(240*320, yarp_vector.size())
        yarp_img_out.setExternal(yarp_vector, width, height)
        self.assertTrue(port_out.write(yarp_img_out))
        yarp.delay(0.5)
        self.assertTrue(port_in.read(yarp_img_in))
        self.assertEqual(240, yarp_img_in.height())
        self.assertEqual(320, yarp_img_in.width())

        port_out.close()
        port_in.close()
コード例 #2
0
    def formatGeneratedData(self, instance):
        """
        Method to transform a generated instance from the model into a Yarp formatted output.

        Args:
            instance: Feature vector returned during generation of a label.

        Returns:
            Yarp formatted output for instance.
        """
        # normalise image between 0 and 1
        yMin = instance.min()
        instance -= yMin
        yMax = instance.max()
        instance /= yMax
        instance *= 255
        instance = instance.astype(numpy.uint8)
        instance = numpy.reshape(
            instance, (self.paramsDict['imgHNew'], self.paramsDict['imgWNew']))

        # convert image into yarp rgb image
        yarpImage = yarp.ImageMono()
        yarpImage.resize(self.paramsDict['imgHNew'],
                         self.paramsDict['imgWNew'])
        instance = instance.astype(numpy.uint8)
        yarpImage.setExternal(instance, instance.shape[1], instance.shape[0])

        return yarpImage
コード例 #3
0
ファイル: interactionSAMModel.py プロジェクト: dcam0050/SSM
    def readFrame(self):
        """
            Logic to read an available data frame.

            Description:
                This function first checks the required data type of the frame to be received and instantiates the required yarp data object. This function then subsequently reads in the latest frame from the __dataIn__ port which it returns. Return is `None` if the data type is not recognised. This is currently a limitation because `ImageRgb`, `ImageMono` and `Bottle` are so far the only supported bottle types. This can be easily extended in this section by adding more cases.

            Returns: Boolean indicating success of logic or not.
        """
        if self.inputType == 'imagergb':
            frame = yarp.ImageRgb()
        elif self.inputType == 'imagemono':
            frame = yarp.ImageMono()
        elif self.inputType == 'bottle':
            frame = yarp.Bottle()
        else:
            return None

        frameRead = self.portsList[self.labelPort].read(True)

        if self.inputType == 'bottle':
            frame.fromString(frameRead.toString())
        elif 'image' in self.inputType:
            frame.copy(frameRead)

        return frame
コード例 #4
0
    def readFrame(self):

        if self.inputType == 'imagergb':
            frame = yarp.ImageRgb()
        elif self.inputType == 'imagemono':
            frame = yarp.ImageMono()
        elif self.inputType == 'bottle':
            frame = yarp.Bottle()

        frame = self.portsList[self.labelPort].read(True)

        return frame
コード例 #5
0
ファイル: yarp_module.py プロジェクト: xEnVrE/DenseFusion
    def __init__(self, options):

        self.options = options

        # Set requested GPU
        os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID"
        os.environ["CUDA_VISIBLE_DEVICES"] = str(options.gpu_id)

        # Initialize YARP network
        yarp.Network.init()

        # Initialize RF module
        yarp.RFModule.__init__(self)

        # Initialize inference
        self.inference = Inference(self.options.model, self.options.refine_model, self.options.width, self.options.height, self.options.cam_fx, self.options.cam_fy, self.options.cam_cx, self.options.cam_cy)

        # Initialize YARP ports
        self.rgb_in = yarp.BufferedPortImageRgb()
        self.rgb_in.open("/dense-fusion/camera/rgb:i")

        self.depth_in = yarp.BufferedPortImageFloat()
        self.depth_in.open("/dense-fusion/camera/depth:i")

        self.mask_in = yarp.BufferedPortImageMono()
        self.mask_in.open("/dense-fusion/camera/mask:i")

        self.camera_pose_in = yarp.BufferedPortVector()
        self.camera_pose_in.open("/dense-fusion/camera/pose:i")

        self.prediction_out = yarp.Port()
        self.prediction_out.open("/dense-fusion/pose:o")

        # Input buffers initialization
        self.rgb_buffer = bytearray(numpy.zeros((self.options.height, self.options.width, 3), dtype = numpy.uint8))
        self.rgb_image = yarp.ImageRgb()
        self.rgb_image.resize(self.options.width, self.options.height)
        self.rgb_image.setExternal(self.rgb_buffer, self.options.width, self.options.height)

        self.depth_buffer = bytearray(numpy.zeros((self.options.height, self.options.width, 1), dtype = numpy.float32))
        self.depth_image = yarp.ImageFloat()
        self.depth_image.resize(self.options.width, self.options.height)
        self.depth_image.setExternal(self.depth_buffer, self.options.width, self.options.height)

        self.mask_buffer = bytearray(numpy.zeros((self.options.height, self.options.width, 1), dtype = numpy.uint8))
        self.mask_image = yarp.ImageMono()
        self.mask_image.resize(self.options.width, self.options.height)
        self.mask_image.setExternal(self.mask_buffer, self.options.width, self.options.height)

        # Stamp initialization for finite differences
        self.last_stamp = -1
        self.last_total_position = None
コード例 #6
0
    def formatGeneratedData(self, instance):
        # normalise image between 0 and 1
        yMin = instance.min()
        instance -= yMin
        yMax = instance.max()
        instance /= yMax
        instance *= 255
        instance = instance.astype(numpy.uint8)
        instance = numpy.reshape(
            instance, (self.paramsDict['imgHNew'], self.paramsDict['imgWNew']))

        # convert image into yarp rgb image
        yarpImage = yarp.ImageMono()
        yarpImage.resize(self.paramsDict['imgHNew'],
                         self.paramsDict['imgWNew'])
        instance = instance.astype(numpy.uint8)
        yarpImage.setExternal(instance, instance.shape[1], instance.shape[0])

        return yarpImage
コード例 #7
0
    def configure(self, rf):
        '''
        Configure the module internal variables and ports according to resource finder
        '''

        self._rf = rf

        #   Input
        #   Image port initialization
        self._port_in = yarp.BufferedPortImageRgb()
        self._port_in.open('/' + self._module_name + '/RGBimage:i')

        #   Input buffer initialization
        self._input_buf_image = yarp.ImageRgb()
        self._input_buf_image.resize(self._input_img_width,
                                     self._input_img_height)
        self._input_buf_array = np.ones(
            (self._input_img_height, self._input_img_width, 3), dtype=np.uint8)
        self._input_buf_image.setExternal(self._input_buf_array,
                                          self._input_buf_array.shape[1],
                                          self._input_buf_array.shape[0])

        print('Input image buffer configured')

        #   Output
        #   Output image port initialization
        self._port_out = yarp.Port()
        self._port_out.open('/' + self._module_name + '/RGBimage:o')

        #   Output blobs port initialization
        self._port_out_bboxes = yarp.Port()
        self._port_out_bboxes.open('/' + self._module_name + '/bboxes:o')

        #   Output detection info port initialization
        self._port_out_info = yarp.Port()
        self._port_out_info.open('/' + self._module_name + '/detectionInfo:o')

        #   Output buffer initialization
        self._output_buf_image = yarp.ImageRgb()
        self._output_buf_image.resize(self._input_img_width,
                                      self._input_img_height)
        self._output_buf_array = np.zeros(
            (self._input_img_height, self._input_img_width, 3), dtype=np.uint8)
        self._output_buf_image.setExternal(self._output_buf_array,
                                           self._output_buf_array.shape[1],
                                           self._output_buf_array.shape[0])

        print('Output image buffer configured')

        #   Output mask port initialization
        self._port_out_mask = yarp.Port()
        self._port_out_mask.open('/' + self._module_name + '/maskImage:o')

        #   Output mask buffer initialization
        self._output_mask_buf_image = yarp.ImageMono()
        self._output_mask_buf_image.resize(self._input_img_width,
                                           self._input_img_height)

        print('Output mask buffer configured')

        #   RPC port initialization
        self._port_rpc = yarp.RpcServer()
        self._port_rpc.open('/' + self._module_name + '/rpc')
        self.attach_rpc_server(self._port_rpc)

        #   Inference model setup
        #   Configure some parameters for inference
        config = configurations.YCBVideoConfigInference()
        config.POST_NMS_ROIS_INFERENCE = 300
        config.PRE_NMS_LIMIT = 1000
        config.DETECTION_MAX_INSTANCES = 10
        config.DETECTION_MIN_CONFIDENCE = 0.75

        config.display()

        self._model = modellib.MaskRCNN(mode='inference',
                                        model_dir=MODEL_DIR,
                                        config=config)

        self._detection_results = None

        print('Inference model configured')

        #   Load class names
        dataset_root = os.path.join(ROOT_DIR, "datasets",
                                    "bottles_ycb_video_format")

        # Automatically discriminate the dataset according to the config file
        if isinstance(config, configurations.TabletopConfigInference):
            # Load the validation dataset
            self._dataset = datasets.TabletopDataset()
        elif isinstance(config, configurations.YCBVideoConfigInference):
            self._dataset = datasets.YCBVideoDataset()

        # No need to load the whole dataset, just the class names will be ok
        self._dataset.load_class_names(dataset_root)

        # Create a dict for assigning colors to each class
        random_class_colors = tabletop_bottles.random_colors(
            len(self._dataset.class_names))
        self._class_colors = {
            class_id: color
            for (color, class_id
                 ) in zip(random_class_colors, self._dataset.class_names)
        }

        #   Load model weights
        try:
            assert os.path.exists(self._model_weights_path)
        except AssertionError as error:
            print("Model weights path invalid: file does not exist")
            print(error)
            return False

        self._model.load_weights(self._model_weights_path, by_name=True)

        print("Model weights loaded")

        return True