def receive_recog_result(self, queue_name): """ >>> from cv_utils import sample_pixel >>> rb = RabbitMQ() >>> rb.channel.queue_purge(queue='loi-rabbitmq-test-queue') #doctest: +ELLIPSIS <... >>> rb.send_multi_live_reg([('Image_ID_1', sample_pixel(), 'Loi', ['Man', 'Dat', 'Phuc'])], ... queue_name='loi-rabbitmq-test-queue') #doctest: +ELLIPSIS message sent 'Image_ID_1?iVBORw...Jggg==?Loi?Man?Dat?Phuc' >>> rb.receive_recog_result(queue_name='loi-rabbitmq-test-queue') [('Image_ID_1', array([[[1, 1, 1]]], dtype=uint8), 'Loi', ['Man', 'Dat', 'Phuc'])] """ msg = self.receive_once(queue_name) recog_list = [] if msg: for recog_str in msg: recog_eles = recog_str.split(Config.Rabbit.INTRA_SEP) # image_id, image, track_id, top_match_ids image_id = recog_eles[0] image_str = recog_eles[1] image = decode_image(image_str) track_id = recog_eles[2] top_match_ids = recog_eles[3:] recog_list.append((image_id, image, track_id, top_match_ids)) return recog_list return None
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
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
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
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
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
def receive_raw_live_image(self, queue_name): """ >>> from cv_utils import sample_pixel >>> rb = RabbitMQ() >>> rb.channel.queue_purge(queue='loi-rabbitmq-test-queue') #doctest: +ELLIPSIS <... >>> rb.send(queue_name='loi-rabbitmq-test-queue', msg=encode_image(sample_pixel())) ... #doctest: +ELLIPSIS message sent 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAACklEQVQIHWMEAg...ABJRU5ErkJggg==' >>> rb.receive_raw_live_image('loi-rabbitmq-test-queue') array([[[1, 1, 1]]], dtype=uint8) """ msg = self.receive_once(queue_name) if msg: # img = decode_image(msg[0]) try: img = decode_image(msg[0]) except Exception as e: with open('../data/er_log.txt', 'a') as f: f.write('CV2 Error Fail message: {}\n'.format(msg)) f.write('CV2 Error Exception: {}\n'.format(e)) return img return msg
sess_id, detector, face_extractor, matcher, register_command, sent_msg_queue, )) thread.daemon = True thread.start() if img_msg is not None: # print(img_msg) sess_id = None sess_id = img_msg[0] frame_string = img_msg[1] frame = decode_image(frame_string) #cv2.imshow('frame', frame) #cv2.waitKey(1) # print(type(frame)) if sess_id not in frame_readers: with open('multi_process_logging.txt', 'a') as f: f.write('Create new session {}\n'.format(sess_id)) frame_readers[sess_id] = QueueFrameReader() frame_readers[sess_id].add_item(frame) register_command[sess_id] = Queue() thread = threading.Thread( target=generic_function, args=( frame_readers, 'TCH',