def send_multi_embedding_message_with_frame( self, img_list, emb_arrays, area, time_stamp, after_padded_bbs, frame, origin_bbs, queue_name): """ >>> from cv_utils import sample_pixel, sample_array >>> rb = RabbitMQ() >>> 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' """ bin_frame = encode_image(frame) bin_img_list = [encode_image(i) for i in img_list] bin_img_list_str = Config.Rabbit.INTRA_SEP.join(bin_img_list) emb_list = [encode_ndarray(e) for e in emb_arrays] after_padded_bbs_str = Config.Rabbit.INTRA_SEP.join(after_padded_bbs) origin_bbs_str_list = [] for origin_bb in origin_bbs: origin_bb_str_array = np.array(origin_bb, dtype='U') origin_bb_str = '_'.join(origin_bb_str_array) origin_bbs_str_list.append(origin_bb_str) origin_bbs_str = Config.Rabbit.INTRA_SEP.join(origin_bbs_str_list) emb_list_str = Config.Rabbit.INTRA_SEP.join(emb_list) msg = Config.Rabbit.INTER_SEP.join([ bin_img_list_str, emb_list_str, str(area), str(time_stamp), after_padded_bbs_str, bin_frame, origin_bbs_str ]) return self.send(queue_name, msg)
def send_tracking(self, track_tuple, queue_name): """ "send tracking from cam to central" - by Man >>> from cv_utils import sample_pixel, sample_array >>> rb = RabbitMQ() >>> 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' """ # TODO:@loi modify doctest following new format fid = str(track_tuple[0]) image = track_tuple[1] emb = track_tuple[2] area_id = track_tuple[3] timestamp = str(track_tuple[4]) origin_bb = track_tuple[5] angle = str(track_tuple[6]) bin_img_str = encode_image(image) emb_str = encode_ndarray(emb) origin_bb_str = encode_ndarray(origin_bb) msg_list = [fid, bin_img_str, emb_str, area_id, timestamp, origin_bb_str, angle] msg = Config.Rabbit.INTRA_SEP.join(msg_list) return self.send(queue_name, msg)
def test_read_frame_from_queue(self): sample = sample_image() self.rb.send(self.queue_name, encode_image(sample)) time.sleep(2) frame = self.frame_reader.next_frame() self.assertIsNotNone(frame) self.assertEqual(frame.shape, sample.shape) self.assertAlmostEqual(np.sum(frame - sample), 0)
def send_capture_result(self, images, queue_name): """ >>> from cv_utils import sample_pixel >>> rb = RabbitMQ() >>> rb.send_capture_result([sample_pixel(), sample_pixel()], 'loi-rabbitmq-test-queue') ... #doctest: +ELLIPSIS message sent 'iVBORw0KG...AAABJRU5ErkJggg==?iVBORw0KGgoAA...ADgAF847BZQAAAABJRU5ErkJggg==' """ bin_img_list = [encode_image(image) for image in images] bin_img_list_str = Config.Rabbit.INTRA_SEP.join(bin_img_list) return self.send(queue_name, bin_img_list_str)
def send_recognition_result(self, human_id, image_id, image, queue_name): """ >>> from cv_utils import sample_pixel >>> rb = RabbitMQ() >>> rb.send_recognition_result('Loi', 'AREA-1253_1233_66_102-13524796', sample_pixel(), ... queue_name='loi-rabbitmq-test-queue') #doctest: +ELLIPSIS message sent 'Loi|AREA-1253_1233_66_102-13524796|iVBORw0KGgoAAAANSUh...AgAADgAF847BZQAAAABJRU5ErkJggg==' """ binaryImg = encode_image(image) msg = Config.Rabbit.INTER_SEP.join( [str(human_id), str(image_id), binaryImg]) return self.send(queue_name, msg)
def send_import_register_data(self, image_face_list, queue_name): """ >>> from cv_utils import sample_pixel >>> rb = RabbitMQ() >>> rb.send_import_register_data([('Loi', sample_pixel()), ('Man', sample_pixel())], ... queue_name='loi-rabbitmq-test-queue') #doctest: +ELLIPSIS message sent 'Loi?iVBORw...Jggg==|Man?iVBORw...Jggg==' """ image_face_str_list = [] for image_face in image_face_list: bin_img_str = encode_image(image_face[1]) image_face_str_list.append( Config.Rabbit.INTRA_SEP.join([image_face[0], bin_img_str])) msg = Config.Rabbit.INTER_SEP.join(image_face_str_list) return self.send(queue_name, msg)
def send_multi_recognition_result(self, human_ids, image_ids, images, queue_name): """ >>> from cv_utils import sample_pixel >>> rb = RabbitMQ() >>> rb.send_multi_recognition_result(['Loi', 'Man'], ... ['IMAGE_ID_1', 'IMAGE_ID_2'], ... [sample_pixel(), sample_pixel()], ... 'loi-rabbitmq-test-queue') #doctest: +ELLIPSIS message sent 'Loi?Man|IMAGE_ID_1?IMAGE_ID_2|iVBORw...kJggg==?iVBORw...Jggg==' """ human_list_str = Config.Rabbit.INTRA_SEP.join(human_ids) image_id_list_str = Config.Rabbit.INTRA_SEP.join(image_ids) bin_img_list = [encode_image(i) for i in images] bin_img_list_str = Config.Rabbit.INTRA_SEP.join(bin_img_list) msg = Config.Rabbit.INTER_SEP.join( [human_list_str, image_id_list_str, bin_img_list_str]) return self.send(queue_name, msg)
def send_response_from_rpc_to_central(self, queue_name, id_dict, area_id): """ >>> from cv_utils import sample_pixel, sample_array >>> rb = RabbitMQ() >>> 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' """ display_face_img_list = [] emb_list = [] order_list = [] padded_bboxes_str_list = [] id_list = [] for face_id, embs_faces_list in id_dict.items(): order_id = 0 for emb, display_face_image, padded_bbox_str, _ in embs_faces_list: emb_list.append(encode_ndarray(emb)) display_face_img_list.append(encode_image(display_face_image)) padded_bboxes_str_list.append(padded_bbox_str) id_list.append(str(face_id)) order_list.append(str(order_id)) order_id += 1 display_face_img_list_str = Config.Rabbit.INTRA_SEP.join( display_face_img_list) emb_list_str = Config.Rabbit.INTRA_SEP.join(emb_list) order_list_str = Config.Rabbit.INTRA_SEP.join(order_list) id_list_str = Config.Rabbit.INTRA_SEP.join(id_list) padded_bboxes_str = Config.Rabbit.INTRA_SEP.join(padded_bboxes_str_list) msg = Config.Rabbit.INTER_SEP.join([ display_face_img_list_str, emb_list_str, order_list_str, id_list_str, area_id, str(int(time.time())), padded_bboxes_str ]) return self.send(queue_name, msg)
def send_multi_live_reg(self, recog_list, queue_name): # recog_list = [(image_id, image, track_id, top_match_ids)...] """ sending top match to web dashboard >>> from cv_utils import sample_pixel >>> rb = RabbitMQ() >>> 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' """ face_msg_list = [] for recog in recog_list: bin_img_str = encode_image(recog[1]) face_msg = Config.Rabbit.INTRA_SEP.join([ recog[0], bin_img_str, recog[2], Config.Rabbit.INTRA_SEP.join(recog[3]) ]) face_msg_list.append(face_msg) msg = Config.Rabbit.INTER_SEP.join(face_msg_list) return self.send(queue_name, msg)
def send_multi_embedding_message(self, img_list, emb_arrays, area, time_stamp, after_padded_bbs, queue_name): """ >>> from cv_utils import sample_pixel, sample_array >>> rb = RabbitMQ() >>> rb.send_multi_embedding_message([sample_pixel()], [sample_array()], 'AREA', ... 1111, ['0_0_0_0'], 'loi-rabbitmq-test-queue') ... #doctest: +ELLIPSIS message sent 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd...==|1|AREA|1111|0_0_0_0' """ bin_img_list = [encode_image(image) for image in img_list] bin_img_list_str = Config.Rabbit.INTRA_SEP.join(bin_img_list) # split emb by ? since - can be negative sign emb_list = [encode_ndarray(embedding) for embedding in emb_arrays] emb_list_str = Config.Rabbit.INTRA_SEP.join(emb_list) after_padded_bbs_str = Config.Rabbit.INTRA_SEP.join(after_padded_bbs) msg = Config.Rabbit.INTER_SEP.join([ bin_img_list_str, emb_list_str, str(area), str(time_stamp), after_padded_bbs_str ]) return self.send(queue_name, msg)
time_stamp_list = [] info_dictionary = {} # sort glob order by time stamp counter = 0 for img_dir in image_dirs: print("Saving {}".format(img_dir)) human_id = img_dir.split('/')[-1].split('.')[0].split('_')[0] img_dir_info = os.stat(img_dir) time_stamp = img_dir_info.st_mtime cv_img = cv2.imread(img_dir) if cv_img is None: print('Cant read this image') counter += 1 continue binaryimg = encode_image(cv_img) time_stamp_list.append(time_stamp) if time_stamp in list(info_dictionary.keys()): raise "BREAKKKKING DOWNNNNNN" info_dictionary[time_stamp] = "{}|{}|{}".format(human_id, binaryimg, time_stamp * 1000) print("Saved {}".format(human_id)) time_stamp_list = sorted(time_stamp_list) f = open('/home/manho/data/tch_db_history_27062018.csv', 'a') for fid in time_stamp_list: print(datetime.datetime.fromtimestamp(fid).strftime('%Y-%m-%d %H:%M:%S')) f.write(info_dictionary[fid] + '\n') # rabbit_mq.send('tchdashboard-result', info_dictionary[fid])
import cv2 from rabbitmq import RabbitMQ from cv_utils import encode_image rb = RabbitMQ() cap = cv2.VideoCapture(0) frame_counter = 0 while (True): frame_counter += 1 print(frame_counter) _, frame = cap.read() bin_image = encode_image(frame) rb.send('uob-live', bin_image)