Ejemplo n.º 1
0
    def receive_tracking(self, queue_name):
        """
        >>> from cv_utils import sample_pixel, sample_array
        >>> rb = RabbitMQ()
        >>> rb.channel.queue_purge(queue='loi-rabbitmq-test-queue') #doctest: +ELLIPSIS
        <...
        >>> rb.send_tracking((1, sample_pixel(), sample_array(), 'AREA', 152364, '0_0_0_0'),
        ...                  queue_name='loi-rabbitmq-test-queue') #doctest: +ELLIPSIS
        message sent
        '1?iVBORw...Jggg==?1?AREA?152364?0_0_0_0'
        >>> rb.receive_tracking(queue_name='loi-rabbitmq-test-queue')
        (1, array([[[1, 1, 1]]], dtype=uint8), array([ 1.]), 'AREA', 152364.0, '0_0_0_0')
        """
        # TODO:@loi modify doctest following new format
        msg = self.receive_once(queue_name)
        if msg:

            track_list = msg[0].split(Config.Rabbit.INTRA_SEP)

            fid = int(track_list[0])
            image_str = track_list[1]
            emb_str = track_list[2]
            area_id = track_list[3]
            timestamp = float(track_list[4])
            origin_bb_str = track_list[5]
            angle = float(track_list[6])

            image = decode_image(image_str)
            emb = decode_ndarray(emb_str)
            origin_bb = decode_ndarray(origin_bb_str)

            return fid, image, emb, area_id, timestamp, origin_bb, angle
        return None, None, None, None, None, None, None
Ejemplo n.º 2
0
    def receive_multi_embedding_message(self, queue_name):
        """
        >>> from cv_utils import sample_pixel, sample_array
        >>> rb = RabbitMQ()
        >>> rb.channel.queue_purge(queue='loi-rabbitmq-test-queue') #doctest: +ELLIPSIS
        <...
        >>> rb.send_multi_embedding_message([sample_pixel()], [sample_array()], 'AREA',
        ...                                 1111, ['0_0_0_0'], 'loi-rabbitmq-test-queue')
        ...                                 #doctest: +ELLIPSIS
        message sent
        'iVBORw...Jggg==|1|AREA|1111|0_0_0_0'
        >>> rb.receive_multi_embedding_message(queue_name='loi-rabbitmq-test-queue')
        ([array([[[1, 1, 1]]], dtype=uint8)], [array([ 1.])], 'AREA', 1111.0, ['0_0_0_0'])
        """
        msg = self.receive_once(queue_name)
        if msg:
            img_list = msg[0].split(Config.Rabbit.INTRA_SEP)
            imgs = [decode_image(i) for i in img_list]
            emb_list = msg[1].split(Config.Rabbit.INTRA_SEP)
            embs = [decode_ndarray(e) for e in emb_list]
            area_id = msg[2]
            timestamp = float(msg[3])
            after_padded_bbs = msg[4].split(Config.Rabbit.INTRA_SEP)

            return imgs, embs, area_id, timestamp, after_padded_bbs
        return None, None, None, None, None
Ejemplo n.º 3
0
    def receive_api_worker_to_central(self, queue_name):
        """
        >>> from cv_utils import sample_array, sample_pixel
        >>> rb = RabbitMQ()
        >>> rb.channel.queue_purge(queue='loi-rabbitmq-test-queue') #doctest: +ELLIPSIS
        <...
        >>> rb.send_response_from_rpc_to_central('loi-rabbitmq-test-queue',
        ...                                      {'Loi':[(sample_array(),
        ...                                               sample_pixel(),
        ...                                               '0_0_0_0',
        ...                                               562)]},
        ...                                      'CHECKIN-AREA') #doctest: +ELLIPSIS
        message sent
        'iVBORw...Jggg==|1|0|Loi|CHECKIN-AREA|...|0_0_0_0'
        >>> rb.receive(queue_name='loi-rabbitmq-test-queue') #doctest: +ELLIPSIS
        [['iVBORw...Jggg==', '1', '0', 'Loi', 'CHECKIN-AREA', '...', '0_0_0_0']]
        """
        msg = self.receive_once(queue_name)
        if msg:
            img_list = msg[0].split(Config.Rabbit.INTRA_SEP)
            if img_list:
                imgs = [decode_image(i) for i in img_list]
            else:
                imgs = []

            emb_list = msg[1].split(Config.Rabbit.INTRA_SEP)
            embs = [decode_ndarray(e) for e in emb_list]
            order_list = msg[2].split(Config.Rabbit.INTRA_SEP)
            id_list = msg[3].split(Config.Rabbit.INTRA_SEP)
            area_id = msg[4]
            timestamp = float(msg[5])
            after_padded_bbs = msg[6].split(Config.Rabbit.INTRA_SEP)

            return imgs, embs, order_list, id_list, area_id, timestamp, after_padded_bbs
        return None, None, None, None, None, None, None
Ejemplo n.º 4
0
    def receive_multi_embedding_message_with_frame(self, queue_name):
        """
        For getting QA infomation from operator correction in web dashboard
        >>> from cv_utils import sample_pixel, sample_array
        >>> rb = RabbitMQ()
        >>> rb.channel.queue_purge(queue='loi-rabbitmq-test-queue') #doctest: +ELLIPSIS
        <...
        >>> rb.send_multi_embedding_message_with_frame([sample_pixel()], [sample_array()], 'AREA',
        ...                                          1111, ['0_0_0_0'], sample_pixel(),
        ...                                          [sample_array()], 'loi-rabbitmq-test-queue')
        ...                                          #doctest: +ELLIPSIS
        message sent
        'iVBORw0KGgoAAAANSUhEUgA...ggg==|1|AREA|1111|0_0_0_0|iVBOR...ggg==|1'
        >>> rb.receive_multi_embedding_message_with_frame(queue_name='loi-rabbitmq-test-queue')
        ... #doctest: +ELLIPSIS
        ([array([[[1, 1, 1]]]...], [array([ 1.])], ..., 1111.0, ['0_0_0_0'],..., array([[1]]...))
        """
        msg = self.receive_once(queue_name)
        if msg:
            img_list = msg[0].split(Config.Rabbit.INTRA_SEP)
            imgs = [decode_image(i) for i in img_list]
            emb_list = msg[1].split(Config.Rabbit.INTRA_SEP)
            embs = [decode_ndarray(e) for e in emb_list]

            area_id = msg[2]
            timestamp = float(msg[3])
            after_padded_bbs = msg[4].split(Config.Rabbit.INTRA_SEP)

            bin_frame = msg[5]
            frame = decode_image(bin_frame)

            origin_bbs_str = msg[6].split(Config.Rabbit.INTRA_SEP)
            origin_bbs_list = [np.array(bb.split('_'), dtype=np.int32) for bb in origin_bbs_str]
            origin_bbs = np.vstack(origin_bbs_list)

            return imgs, embs, area_id, timestamp, after_padded_bbs, frame, origin_bbs
        return None, None, None, None, None, None, None
Ejemplo n.º 5
0
 def receive_embedding_message(self, queue_name):
     """
     >>> from cv_utils import sample_pixel, sample_array
     >>> rb = RabbitMQ()
     >>> rb.channel.queue_purge(queue='loi-rabbitmq-test-queue') #doctest: +ELLIPSIS
     <...
     >>> rb.send(queue_name='loi-rabbitmq-test-queue',
     ...         msg=Config.Rabbit.INTER_SEP.join([encode_image(sample_pixel()),
     ...                                           encode_ndarray(sample_array()),
     ...                                           'AREA', '1111', '1.5'])) #doctest: +ELLIPSIS
     message sent
     'iVBORw...Jggg==|1|AREA|1111|1.5'
     >>> rb.receive_embedding_message(queue_name='loi-rabbitmq-test-queue')
     (array([[[1, 1, 1]]], dtype=uint8), array([ 1.]), 'AREA', 1111.0, '1.5')
     """
     msg = self.receive_once(queue_name)
     if msg:
         image = decode_image(msg[0])
         emb = decode_ndarray(msg[1])
         area_id = msg[2]
         timestamp = float(msg[3])
         crop_ratio = msg[4]
         return image, emb, area_id, timestamp, crop_ratio
     return None, None, None, None, None