コード例 #1
0
 def __init__(self):
     yarp.RFModule.__init__(self)
     self.image = np.zeros((240, 304))
     self.image_buf = np.zeros((240, 304))
     self.input_port = yarp.BufferedPortBottle()
     self.rpc_port = yarp.RpcServer()
     cv2.namedWindow("events", cv2.WINDOW_NORMAL)
     self.mutex = threading.Lock()
コード例 #2
0
    def __createPort(self, name, target=None, mode='unbuffered'):
        """ This method returns a port object.

        @param name     - yarp name for the port
        @param obj      - object for which the port is created
        @param buffered - if buffered is True a buffered port will be used otherwise not;
                          default is True.
        @result port
        """
        # create port
        if mode == 'buffered':
            port = yarp.BufferedPortBottle()

        elif mode == 'rpcclient':
            port = yarp.RpcClient()

        elif mode == 'rpcserver':
            port = yarp.RpcServer()

        else:
            port = yarp.Port()

        # build port name
        port_name = ['']

        # prefix handling
        if hasattr(self, 'prefix') and self.prefix:
            port_name.append(self.prefix)

        port_name.append(self.__class__.__name__)
        port_name.append(name)

        # open port
        if not port.open('/'.join(port_name)):
            raise RuntimeError, EMSG_YARP_NOT_FOUND

        # add output if given
        if target:
            port.addOutput(target)

        if hasattr(self, '_ports'):
            self._ports.append(port)

        return port
コード例 #3
0
    def configure(self, rf):

        name = self.__class__.__name__
        if self.prefix:
            name = self.prefix + '/' + name

        self.setName(name)

        # RPC Port
        self.rpc_port = yarp.RpcServer()

        # name settings
        port_name = '/%s/%s' % (name, 'rpc')

        if not self.rpc_port.open(port_name):
            raise RuntimeError, EMSG_YARP_NOT_FOUND

        self.attach_rpc_server(self.rpc_port)

        return True
コード例 #4
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
コード例 #5
0
ファイル: interaction_faces.py プロジェクト: pecfw/wysiwyd
    SAMCore.load_pruned_model(fname, economy_save, cur.SAMObject.model)
    mm.append(cur)

#open ports
yarp.Network.init()

sect = splitPath[0].split('/')[-1].lower()

parser2 = SafeConfigParser()
parser2.read(interactionConfPath)
portNameList = parser2.items(sect)
print portNameList
portsList = []
for j in range(len(portNameList)):
    if (portNameList[j][0] == 'rpcbase'):
        portsList.append(yarp.RpcServer())
        portsList[j].open(portNameList[j][1] + ':i')
        svPort = j
    elif (portNameList[j][0] == 'callsign'):
        callSignList = portNameList[j][1].split(',')
    else:
        parts = portNameList[j][1].split(' ')
        print parts

        if (parts[1].lower() == 'imagergb'):
            portsList.append(yarp.BufferedPortImageRgb())
            portsList[j].open(parts[0])

        elif (parts[1].lower() == 'imagemono'):
            portsList.append(yarp.BufferedPortImageMono())
            portsList[j].open(parts[0])
コード例 #6
0
ファイル: samSupervisor.py プロジェクト: pecfw/wysiwyd
            else:
                print 'No interaction function specified in config.ini. Skipping model'

        #connect supervisor to all submodels
        if (len(rpcConnections) != 0):
            for j in rpcConnections:
                noConn = True
                print 'connecting ' + j[2] + 'o ' + 'with ' + j[2] + 'i'
                while (noConn):
                    noConn = yarp.Network.connect(j[2] + 'o', j[2] + 'i')
                    noConn = not noConn
                    time.sleep(1)
                print 'connected'

            #create rpc port to communicate with outside
            supervisorPort = yarp.RpcServer()
            supervisorPort.open('/sam/rpc:i')
            inputBottle = yarp.Bottle()
            sendingBottle = yarp.Bottle()
            responseBottle = yarp.Bottle()
            outputBottle = yarp.Bottle()
            print
            print '-------------------'

            while (True):
                try:
                    print 'Waiting for input:'
                    supervisorPort.read(inputBottle, True)

                    #determine towards which process inputBottle is directed
                    callSign = inputBottle.get(0).asString()
コード例 #7
0
ファイル: bottleParser.py プロジェクト: pecfw/wysiwyd
                resp += 'blob of lenght (' + str(val.asBlobLength()) + ')\n'
            elif (val.isList()):
                resp += 'List of ' + str(val.asList().size()) + ' elements\n'
                indentation += 1
                resp = readBottle(val.asList(), resp, indentation)
                indentation -= 1
            else:
                resp += 'Unrecognized type\n'
    else:
        print 'no bottle'
    return resp


yarp.Network.init()

messagePort = yarp.RpcServer()
messagePort.open('/testServer')
inputBottle = yarp.Bottle()

while (True):
    try:
        print 'Waiting for input:'
        messagePort.read(inputBottle, True)
        #parse Bottle Contents
        resp = readBottle(inputBottle)
        print resp
        print
    except KeyboardInterrupt:
        print 'Closing server ...'
        messagePort.close()
        try:
コード例 #8
0
ファイル: sightcorp.py プロジェクト: pecfw/wysiwyd
# Ask where the images are stored
cmd = yarp.Bottle()
resp = yarp.Bottle()
cmd.addString('getStoringPath')
abm_port.write(cmd, resp)
storing_path = resp.get(0).asString()
print("Storing path: ", storing_path)

################################################# TO BE REMOVED ##################################################
storing_path = '/home/maxime/Downloads/Max.jpg'
storing_label = 'Max_label'
print("Fix storing path for testing purpose: ", storing_path)
################################################# TO BE REMOVED ##################################################

try:
    rpc_port = yarp.RpcServer()
    rpc_port.open("/sightcorp/rpc")

    while True:
        print("Waiting for command")
        cmd = yarp.Bottle()
        resp = yarp.Bottle()
        rpc_port.read(cmd, True)
        print("Got message: ", cmd.toString())
        if (cmd.get(0).asString() == 'tag'):
            print("Going to tag image")
            relative_path = cmd.get(1).asString()
            print("Relative path: ", relative_path)
            full_path = storing_path + '/' + relative_path
            print("Full path: ", full_path)
            #convert tif to jpg