class RabbitMQTest(unittest.TestCase): def setUp(self): if not Config.DEBUG: raise ('To run RabbitMQTest, DEBUG Mode must be on') self.rb = RabbitMQ() self.queue_name = self.rb.RECEIVE_WEB_CAM self.frame_reader = RabbitFrameReader(self.rb, self.queue_name) def test_no_frame_avaiable(self): frame = self.frame_reader.next_frame() self.assertIsNone(frame) 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 test_read_queue_from_non_existing_queue(self): queue_name = 'non_exist' self.assertRaises(ValueError, RabbitFrameReader, self.rb, queue_name)
#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', sess_id, detector, face_extractor, matcher, register_command, sent_msg_queue, )) thread.daemon = True thread.start() else: # print('Send frame to session {}'.format(sess_id)) frame_readers[sess_id].add_item(frame) if not sent_msg_queue.empty(): queue_name, msg_content = sent_msg_queue.get() rb.send(queue_name, msg_content)
from config import Config from rabbitmq import RabbitMQ import argparse rabbit_mq = RabbitMQ((Config.Rabbit.USERNAME, Config.Rabbit.PASSWORD), (Config.Rabbit.IP_ADDRESS, Config.Rabbit.PORT)) image_url = '/home/manho/public/new-face.jpg' parser = argparse.ArgumentParser() parser.add_argument('-t', '--token', help='Token', default=None) parser.add_argument('-i', '--id', help='ID', default=None) args = parser.parse_args() mgs_parts = [args.token, args.id] rabbit_mq.send('eyeq-tch-confirmed-id', '|'.join(mgs_parts))
from config import Config from rabbitmq import RabbitMQ import os import time rabbit_mq = RabbitMQ((Config.Rabbit.USERNAME, Config.Rabbit.PASSWORD), (Config.Rabbit.IP_ADDRESS, Config.Rabbit.PORT)) image_url = '/home/manho/public/new-face.jpg' abs_path = os.path.abspath(image_url) token = 'TCH-VVT-' + str(time.time()) mgs_parts = [token, abs_path] for i in range(3): mgs_parts.append('id' + str(i) + '?' + abs_path) counter = 0 while (counter < 10): counter += 1 rabbit_mq.send('hieuha-test-tch', '|'.join(mgs_parts))
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)