def __init__(self, exchange, key, qThread):
        c = Config()

        self.exchange = exchange
        self.routing_key = key
        self.qThread = qThread
        rmq_host = str(c.host)
        rmq_port = c.port
        rmq_username = c.username
        rmq_password = c.password
        print "connecting with username", rmq_username, "and password", rmq_password

        if rmq_username:
            if rmq_password:
                print(
                    "Connection established" if RabbitMQ.establishConnection(
                        rmq_host, rmq_port, rmq_username, rmq_password) else
                    "Failed to connect")
            else:
                print(
                    "Connection established" if RabbitMQ.establishConnection(
                        rmq_host, rmq_port, rmq_username) else
                    "Failed to connect")
        else:
            print("Connection established" if RabbitMQ.establishConnection(
                rmq_host, rmq_port) else "Failed to connect")

        print "start listening on", rmq_host, "with port", rmq_port
        print "waiting for", key, "on exchange", exchange
示例#2
0
    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)
示例#3
0
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)
示例#4
0
 def start(self):
     RabbitMQ.declareExchange(self.channel, self.exchange, _type="topic")
     queue = self.channel.queue_declare()
     queue_name = queue.method.queue
     self.channel.queue_bind(exchange=self.exchange, queue=queue_name, routing_key=self.routing_key)
     self.channel.basic_consume(self.onMessage,  no_ack=True)
     self.channel.start_consuming()
示例#5
0
def central_function():
    rabbit_mq = RabbitMQ((Config.Rabbit.USERNAME, Config.Rabbit.PASSWORD),
                         (Config.Rabbit.IP_ADDRESS, Config.Rabbit.PORT))
    cen_list = TrackersList()
    matcher = KdTreeMatcher()
    matcher._match_case = 'TCH'

    while True:
        fid, image, emb, area, _, origin_bb, angle = \
                    rabbit_mq.receive_tracking(rabbit_mq.RECEIVE_CAM_WORKER_TRACKING_QUEUE)
        if fid is not None:
            print("-- Received a face-track message from cam server")
            generated_fid = str(fid) + '-' + area
            cen_list.update_trackers_list(generated_fid, origin_bb, image, emb,
                                          angle, area, 0, matcher, rabbit_mq)

        # check time
        cen_list.check_delete_trackers(matcher, rabbit_mq)

        # Check extract trackers history time
        # cen_list.trackers_history.check_time()

        if fid is None:
            print('Waiting for new job ...')
            time.sleep(5)
 def start(self):
     RabbitMQ.declareExchange(self.channel, self.exchange, _type="topic")
     queue = self.channel.queue_declare()
     queue_name = queue.method.queue
     self.channel.queue_bind(exchange=self.exchange,
                             queue=queue_name,
                             routing_key=self.routing_key)
     self.channel.basic_consume(self.onMessage, no_ack=True)
     self.channel.start_consuming()
示例#7
0
def main():
    queue = "vin"
    if len(sys.argv) >= 2:
        queue = sys.argv[1]
    mq = RabbitMQ(queue=queue)
    msg = mq.basic_get()
    if msg:
        print msg
    else:
        print "no topic"
 def start(self):
     if hasattr(RabbitMQ, 'channel'):
         queue = RabbitMQ.channel.queue_declare()
         queue_name = queue.method.queue
         RabbitMQ.channel.queue_bind(exchange=self.exchange, queue=queue_name, routing_key=self.routing_key)
         RabbitMQ.channel.basic_consume(self.onMessage, no_ack=True)
         # register Exchange and Queue for repeatable events
         RabbitMQ.registerExchanges(RabbitMQ.channel)
         print "start consuming ..."
         RabbitMQ.channel.start_consuming()
     else:
     	print "Can not start the MessageBusConsumer. Not connected."
 def start(self):
     if hasattr(RabbitMQ, 'channel'):
         queue = RabbitMQ.channel.queue_declare()
         queue_name = queue.method.queue
         RabbitMQ.channel.queue_bind(exchange=self.exchange,
                                     queue=queue_name,
                                     routing_key=self.routing_key)
         RabbitMQ.channel.basic_consume(self.onMessage, no_ack=True)
         # register Exchange and Queue for repeatable events
         RabbitMQ.registerExchanges(RabbitMQ.channel)
         print "start consuming ..."
         RabbitMQ.channel.start_consuming()
     else:
         print "Can not start the MessageBusConsumer. Not connected."
示例#10
0
def hello_IoT_world():
    # establish connection
    host = "131.227.92.55"
    port = 8007
    rabbitmqconnection, rabbitmqchannel = RabbitMQ.establishConnection(host, port)

    # declare exchange
    exchange = 'Social_data'
    topic1 = 'Aarhus'
    topic2 = 'Aarhus.Traffic.SensorID002'
    RabbitMQ.declareExchange(rabbitmqchannel, exchange, _type="topic")

    json = make_message()
    RabbitMQ.sendMessage(json, rabbitmqchannel, exchange, topic1)
    time.sleep(10)
 def __init__(self, exchange, key, seconds_delay, repetitions):
     self.config = JOb(file(os.path.join(os.path.dirname(__file__), "..", "virtualisation", "config.json"), "rb"))
     self.host = self.config.rabbitmq.host
     self.port = self.config.rabbitmq.port
     print "Start listening on", self.host, "with port", self.port
     print "Waiting for topic", key, "on exchange", exchange
     self.connection, self.channel = RabbitMQ.establishConnection(self.host, self.port)
     self.exchange = exchange
     self.routing_key = key
     RabbitMQ.declareExchange(self.channel, self.exchange, _type='topic')
     self.seconds_delay = seconds_delay
     self.repetitions = repetitions
     self.timer = None
     self.q = Queue()
     self.lock = Lock()
 def __init__(self, exchange, key):
     self.host = "131.227.92.55"
     self.port = 8007
     self.connection, self.channel = RabbitMQ.establishConnection(
         self.host, self.port)
     self.exchange = exchange
     self.routing_key = key
示例#13
0
    def __init__(self, exchange, key):
        self.host = "131.227.92.55"
        self.port = 8007

        self.connection, self.channel = RabbitMQ.establishConnection(self.host, self.port)
        self.exchange = exchange
        self.routing_key = key
示例#14
0
    def test_log_metrics_works_without_trailing_slashes_on_the_uris(self):
        os.environ['VCAP_SERVICES'] = json.dumps({
            "rmq-service": [{
                "credentials": {
                    "http_api_uri": "http://example.com/api",
                },
                "label": "rmq-service",
                "name": "rm-rabbitmq",
            }]
        })

        metrics = [
            {
                'messages': 101,
                'reductions': 7654321,
                'name': 'queue1'
            },
        ]

        httpretty.register_uri(httpretty.GET,
                               'http://example.com/api/queues',
                               body=json.dumps(metrics),
                               status=200)

        logger = Mock()

        RabbitMQ(logger, 'rmq-service').log_metrics()

        logger.info.assert_has_calls([
            call('sdc.metrics.rmq-service.rm-rabbitmq.queue1',
                 '{"messages": 101}')
        ])
示例#15
0
 def test__get_data(self):
     with mock.patch('rabbitmq.requests') as r:
         from rabbitmq import RabbitMQ, RabbitMQException  # pylint: disable=import-error
         check = RabbitMQ('rabbitmq', {}, {"instances": [{"rabbitmq_api_url": "http://example.com"}]})
         r.get.side_effect = [requests.exceptions.HTTPError, ValueError]
         self.assertRaises(RabbitMQException, check._get_data, '')
         self.assertRaises(RabbitMQException, check._get_data, '')
 def resend(self, channel, message, routing_key, _repetitions):
     _repetitions -= 1
     # print _repetitions, self.exchange, routing_key
     try:
         if not channel.is_open:
             print "Exiting because channel is closed."
             return
         RabbitMQ.sendMessage(message, channel, self.exchange, routing_key)
     except Exception as e:
         print "failed to resend", routing_key, e
     if _repetitions > 0:
         self.q.put((message, routing_key, _repetitions), block=False)
     else:
         del message
         del routing_key
         del _repetitions
示例#17
0
def main(cam_url, recording_area):

    rb = RabbitMQ((Config.Rabbit.USERNAME, Config.Rabbit.PASSWORD),
                  (Config.Rabbit.IP_ADDRESS, Config.Rabbit.PORT))
    detector = MTCNNDetector(FaceGraph())
    frame_reader = URLFrameReader(cam_url)
    edit_image = utils.CropperUtils()
    face_angle = utils.FaceAngleUtils()
    feature_extractor = FacenetExtractor(FaceGraph())
    pre_process = Preprocessor(whitening)

    while frame_reader.has_next():

        embedding_images = []
        embedding_vectors = []
        display_images = []
        display_image_bounding_boxes = []

        frame = frame_reader.next_frame()
        bounding_boxes, points = detector.detect_face(frame)

        for index, bounding_box in enumerate(bounding_boxes):

            if face_angle.is_acceptable_angle(points[:, index]) is True:

                embedding_image = edit_image.crop_face(frame, bounding_box)
                embedding_images.append(embedding_image)

                display_image, display_image_bounding_box = edit_image.crop_display_face(
                    frame, bounding_box)
                display_images.append(display_image)
                display_image_bounding_boxes.append(display_image_bounding_box)

                whitened_image = pre_process.process(embedding_image)
                embedding_vector, coeff = feature_extractor.extract_features(
                    whitened_image)

                embedding_vectors.append(embedding_vector)

        if len(embedding_vectors) > 0:

            rb.send_multi_embedding_message(display_images, embedding_vectors,
                                            recording_area, time.time(),
                                            display_image_bounding_boxes,
                                            rb.SEND_QUEUE_WORKER)
        else:
            print("No Face Detected")
    def connectReplica(self, msg):
        from rabbitmq import RabbitMQ
        login = '******'
        password = '******'
        ip = '18.221.109.240'

        routingkey = msg['topic']
        exchange = msg['exchange']
        tipo = msg['tipo']
        rabbit = RabbitMQ(login=login,
                          password=password,
                          server=ip,
                          exchange=exchange,
                          routingkey=routingkey)

        if tipo == '1':  #'publish'
            req = msg['payload']
            print(req)
            req = json.dumps(req)
            rabbit.publish(req)
    def __init__(self, exchange, key, qThread):
    	c = Config()

        self.exchange = exchange
        self.routing_key = key
        self.qThread = qThread
        rmq_host = str(c.host)
        rmq_port = c.port
        rmq_username = c.username
        rmq_password = c.password
        print "connecting with username", rmq_username, "and password", rmq_password

        if rmq_username:
            if rmq_password:
                print ("Connection established" if RabbitMQ.establishConnection(rmq_host, rmq_port, rmq_username, rmq_password) else "Failed to connect")
            else:
                print ("Connection established" if RabbitMQ.establishConnection(rmq_host, rmq_port, rmq_username) else "Failed to connect")
        else:
            print ("Connection established" if RabbitMQ.establishConnection(rmq_host, rmq_port) else "Failed to connect")

        print "start listening on", rmq_host, "with port", rmq_port
        print "waiting for", key, "on exchange", exchange
示例#20
0
    def test_log_metrics(self):
        os.environ['VCAP_SERVICES'] = json.dumps({
            "rabbitmq": [{
                "credentials": {
                    "http_api_uri": "http://example.com/rabbit1/api/",
                },
                "label": "rabbitmq",
                "name": "rm-rabbitmq",
            }, {
                "credentials": {
                    "http_api_uri": "http://example.com/rabbit2/api/",
                },
                "label": "rabbitmq",
                "name": "sdx-rabbitmq",
            }]
        })

        metrics1 = [{
            "messages": 101,
            "reductions": 7654321,
            "name": "queue1"
        }, {
            "messages": 202,
            "reductions": 1234567,
            "name": "queue2"
        }]

        metrics2 = [{"messages": 303, "reductions": 6666666, "name": "queue3"}]

        httpretty.register_uri(httpretty.GET,
                               'http://example.com/rabbit1/api/queues',
                               body=json.dumps(metrics1),
                               status=200)

        httpretty.register_uri(httpretty.GET,
                               'http://example.com/rabbit2/api/queues',
                               body=json.dumps(metrics2),
                               status=200)

        logger = Mock()

        RabbitMQ(logger, 'rabbitmq').log_metrics()

        logger.info.assert_has_calls([
            call('sdc.metrics.rabbitmq.rm-rabbitmq.queue1',
                 '{"messages": 101}'),
            call('sdc.metrics.rabbitmq.rm-rabbitmq.queue2',
                 '{"messages": 202}'),
            call('sdc.metrics.rabbitmq.sdx-rabbitmq.queue3',
                 '{"messages": 303}')
        ])
示例#21
0
    def handle_EXECUTION(self, req):
        from rabbitmq import RabbitMQ

        login = self.factory.rabbit['login']
        password = self.factory.rabbit['password']
        ip = self.factory.rabbit['ip']

        routingkey =  req['topic']
        exchange   = req['exchange']
        tipo = req['tipo']

        rabbit = RabbitMQ(login=login, password=password,
                          server=ip, exchange=exchange, routingkey=routingkey   )

        if tipo == '1':   #'publish'
            msg = req['payload']
            msg = json.dumps(msg)
            rabbit.publish(msg)
            self.statusCode = '500'
            self.factory.response[self.hashcode] = self.statusCode

        self.state = 'REPLICATION'
        self.handle_REPLICATION(req)
    def __init__(self, exchange, key):
        self.config = JOb(file(os.path.join(os.path.dirname(__file__), "..", "virtualisation", "config.json"), "rb"))
        # self.host = self.config.rabbitmq.host
        # self.port = self.config.rabbitmq.port

        self.exchange = exchange
        self.routing_key = key
        rmq_host = str(self.config.rabbitmq.host)
        rmq_port = self.config.rabbitmq.port
        rmq_username = self.config.rabbitmq.username if "username" in self.config.rabbitmq else None
        rmq_password = self.config.rabbitmq.password if "password" in self.config.rabbitmq else None
        print "connecting with", rmq_username, "and", rmq_password

        if rmq_username:
            if rmq_password:
                print ("Connection established" if RabbitMQ.establishConnection(rmq_host, rmq_port, rmq_username, rmq_password) else "Failed to connect")
            else:
                print ("Connection established" if RabbitMQ.establishConnection(rmq_host, rmq_port, rmq_username) else "Failed to connect")
        else:
            print ("Connection established" if RabbitMQ.establishConnection(rmq_host, rmq_port) else "Failed to connect")

        print "start listening on", rmq_host, "with port", rmq_port
        print "waiting for", key, "on exchange", exchange
示例#23
0
    def test_log_metrics_raises_for_http_errors(self):
        os.environ['VCAP_SERVICES'] = json.dumps({
            "rabbitmq": [{
                "credentials": {
                    "http_api_uri": "http://example.com/api",
                },
                "label": "rabbitmq",
                "name": "rm-rabbitmq",
            }]
        })

        httpretty.register_uri(httpretty.GET,
                               'http://example.com/api/queues',
                               body='Error text',
                               status=500)

        logger = Mock()

        RabbitMQ(logger, 'rabbitmq').log_metrics()

        logger.error.assert_has_calls([
            call('sdc.metrics.rabbitmq.rm-rabbitmq',
                 f'GET http://example.com/api/queues - [500] - Error text')
        ])
示例#24
0
 def main(cls):
     while True:
         try:
             objqueue = RabbitMQ(**cls.config['source'])
             objqueue.connect()
             objqueue.channel.basic_consume(
                 queue=cls.config['source']['queue'],
                 on_message_callback=cls.callback,
                 auto_ack=False
             )
             #cls.traceability = Traceability(**cls.config['traceability'])
             try:
                 objqueue.channel.start_consuming()
             except KeyboardInterrupt:                    
                 objqueue.disconnect()
                 objqueue.channel.stop_consuming()
                 break
         except (exceptions.ConnectionClosedByBroker,exceptions.AMQPChannelError,exceptions.AMQPConnectionError) as error_connection:
             print('Conexion cerrada con a RabbitMQ', error_connection)
             continue
示例#25
0
    "CrimeEvent", "SocialEvent", "CulturalEvent", "TransportationEvent",
    "HealthEvent", "SportEvent", "EnvironmentalEvent", "FoodEvent"
]
label_list2 = [
    '<B-CRIME>', '<B-SOCIAL>', '<B-CULTURAL>', '<B-TRAFFIC>', '<B-HEALTH>',
    '<B-SPORT>', '<B-WEATHER>', '<B-FOOD>', '<I-CRIME>', '<I-SOCIAL>',
    '<I-CULTURAL>', '<I-TRAFFIC>', '<I-HEALTH>', '<I-SPORT>', '<I-WEATHER>',
    '<I-FOOD>'
]
Loc_label = ['<B-LOCATION>', '<I-LOCATION>']
gran_event_df = pd.read_csv(dictionary_folder + 'GranuralDic.csv', sep="<>")

#Message Bus setting:
Host = "server IP"
Port = 8007
rabbitmqconnection, rabbitmqchannel = RabbitMQ.establishConnection(Host, Port)
# declare exchange
exchange = 'event'
topic = 'Aarhus.Twitter'

#connecting to google translate API
Timer = NOW.minute
gs = goslate.Goslate()
while start_flag:
    Sleep = 0
    start = time.clock()
    loaded_data = load_data_from_mysqlDB(NOW, step, delay)
    trans_df, raw_df, noData_flag, Now, ED_flag = loaded_data[0], loaded_data[
        1], loaded_data[2], loaded_data[3], loaded_data[4]
    if noData_flag:
        stop = time.clock()
示例#26
0
def peek(queue):
    mq = RabbitMQ(queue=queue)
    msg = mq.basic_get()
    if msg:
        mq.publish(msg)
    return msg
示例#27
0
if True:
    configs = []
    with open('../config.txt', 'r') as f:
        configs = f.readlines()
    configs = [txt_config.strip('\n') for txt_config in configs]
    Config.DEMO_FOR = configs[0]
    Config.Rabbit.IP_ADDRESS = configs[1]

face_rec_graph = FaceGraph()
face_extractor = FacenetExtractor(face_rec_graph, model_path=Config.FACENET_DIR)
detector = MTCNNDetector(face_rec_graph)
preprocessor = Preprocessor()
matcher = FaissMatcher()
matcher._match_case = 'TCH'
matcher.build(Config.REG_IMAGE_FACE_DICT_FILE)
rb = RabbitMQ()

frame_readers = dict()
register_command = dict()  # {session_id: [[register_name, video_path]]}
removed_sessions = Queue()
sent_msg_queue = Queue()
start_time = time.time()

while True:
    # if time.time() - start_time >= 10.0:
    #     try:
    #         while True:
    #             rm_id = removed_sessions.get(False)
    #             frame_readers.pop(rm_id, None)
    #             sessions.pop(rm_id, None)
    #             register_command.pop(rm_id, None)
示例#28
0
import cv2
from scipy import misc
from preprocess import Preprocessor
from matcher import FaissMatcher, KdTreeMatcher
from cv_utils import create_if_not_exist
from rabbitmq import RabbitMQ
from config import Config
from pymongo import MongoClient
import argparse
import glob
import time

extractor_graph = FaceGraph()
face_extractor = FacenetExtractor(extractor_graph)

rabbit_mq = RabbitMQ((Config.Rabbit.USERNAME, Config.Rabbit.PASSWORD),
                     (Config.Rabbit.IP_ADDRESS, Config.Rabbit.PORT))

mongodb_client = MongoClient(Config.MongoDB.IP_ADDRESS,
                             Config.MongoDB.PORT,
                             username=Config.MongoDB.USERNAME,
                             password=Config.MongoDB.PASSWORD)

mongodb_db = mongodb_client[Config.MongoDB.DB_NAME]
mongodb_dashinfo = mongodb_db[Config.MongoDB.DASHINFO_COLS_NAME]
mongodb_faceinfo = mongodb_db[Config.MongoDB.FACEINFO_COLS_NAME]


def main(data_path, dashboard):
    #wipe data
    mongodb_dashinfo.remove({})
    mongodb_faceinfo.remove({})
示例#29
0
import pika
import sys
import time
from rabbitmq import RabbitMQ


def callback(ch, method, properties, body):
    print(" [x] Received %r" % body)
    time.sleep(body.count(b'.'))
    print(" [x] Done")
    ch.basic_ack(delivery_tag=method.delivery_tag)


comsumer = RabbitMQ()
comsumer.connect_to_queue()
comsumer.consume(callback)
示例#30
0
def main():
    queue = "vin"
    if len(sys.argv) >= 2:
        queue = sys.argv[1]
    mq = RabbitMQ(queue=queue)
    mq.start_consuming(callback)
示例#31
0
    def test_main(self):
        rb = RabbitMQ((Config.Rabbit.USERNAME, Config.Rabbit.PASSWORD),
                      (Config.Rabbit.IP_ADDRESS, Config.Rabbit.PORT))

        rb.channel.queue_purge(queue=rb.SEND_QUEUE_WORKER)

        main("../data/video/test_sample.mp4", "LOCAL")

        with open("test/unittest_cam_worker.pkl", "rb") as out:
            pickle_messages_dict = pickle.load(out)

        rb_messages_dict = {
            "display_images": [],
            "embedding_vectors": [],
            "recording_area": [],
            "display_image_bounding_boxes": [],
        }
        for _ in range(10):

            display_images, embedding_vectors, recording_areas, timestamp, \
                display_image_bounding_boxes = rb.receive_multi_embedding_message(
                                                rb.SEND_QUEUE_WORKER)

            for display_image in display_images:
                rb_messages_dict["display_images"] \
                                .append(np.asarray(display_image))

            for embedding_vector in embedding_vectors:
                rb_messages_dict["embedding_vectors"] \
                                .append(np.asarray(embedding_vector))

            for recording_area in recording_areas:
                rb_messages_dict["recording_area"] \
                                .append(np.asarray(recording_area))

            for display_image_bounding_box in display_image_bounding_boxes:
                rb_messages_dict["display_image_bounding_boxes"] \
                                .append(np.asarray(display_image_bounding_box))

        self.assertEqual(len(pickle_messages_dict["display_images"]),
                         len(rb_messages_dict["display_images"]))

        self.assertEqual(len(pickle_messages_dict["embedding_vectors"]),
                         len(rb_messages_dict["embedding_vectors"]))

        self.assertEqual(len(pickle_messages_dict["recording_area"]),
                         len(rb_messages_dict["recording_area"]))

        self.assertEqual(
            len(pickle_messages_dict["display_image_bounding_boxes"]),
            len(rb_messages_dict["display_image_bounding_boxes"]))

        for index in range(len(pickle_messages_dict["display_images"])):
            self.assertEqual(
                (rb_messages_dict["display_images"][index] ==
                 pickle_messages_dict["display_images"][index]).all(), True)

        for index in range(len(pickle_messages_dict["embedding_vectors"])):
            self.assertEqual(
                (rb_messages_dict["embedding_vectors"][index] ==
                 pickle_messages_dict["embedding_vectors"][index]).all(), True)

        for index in range(len(pickle_messages_dict["recording_area"])):
            self.assertEqual(
                (rb_messages_dict["recording_area"][index] ==
                 pickle_messages_dict["recording_area"][index]).all(), True)

        for index in range(
                len(pickle_messages_dict["display_image_bounding_boxes"])):
            self.assertEqual(
                (rb_messages_dict["display_image_bounding_boxes"][index] ==
                 pickle_messages_dict["display_image_bounding_boxes"][index]
                 ).all(), True)
示例#32
0
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))
示例#33
0
start_flag=1
CRFDic_tag=Load_Tag('CRFDic_tag.txt')
CNN_NER_tag=Load_Tag('CNN_NER_tag.txt')
CRFDic_tag.pop(-1)
CNN_Loc_tag=CNN_NER_tag[:7]
LocTags=['B-LOCATION>','I-LOCATION>']+CNN_Loc_tag
label_list=["-CRIME>", "-SOCIAL>", "-CULTURAL>", "-TRAFFIC>", "-HEALTH>", "-SPORT>", "-WEATHER>","-FOOD>"]
Type_list=["CrimeEvent", "SocialEvent", "CulturalEvent", "TransportationEvent", "HealthEvent", "SportEvent", "EnvironmentalEvent","FoodEvent"]
label_list2=['<B-CRIME>', '<B-SOCIAL>', '<B-CULTURAL>', '<B-TRAFFIC>', '<B-HEALTH>', '<B-SPORT>', '<B-WEATHER>', '<B-FOOD>', '<I-CRIME>', '<I-SOCIAL>', '<I-CULTURAL>', '<I-TRAFFIC>', '<I-HEALTH>', '<I-SPORT>', '<I-WEATHER>', '<I-FOOD>']
Loc_label=[ '<B-LOCATION>','<I-LOCATION>']
gran_event_df=pd.read_csv(dictionary_folder+'GranuralDic.csv', sep="<>")

#Message Bus setting:
Host = "server IP"
Port = 8007
rabbitmqconnection, rabbitmqchannel = RabbitMQ.establishConnection(Host, Port)
# declare exchange
exchange = 'event'
topic = 'Aarhus.Twitter'

#connecting to google translate API
Timer=NOW.minute
gs = goslate.Goslate()
while start_flag:
    Sleep=0
    start = time.clock()
    loaded_data=load_data_from_mysqlDB(NOW,step,delay)
    trans_df,raw_df,noData_flag,Now,ED_flag=loaded_data[0],loaded_data[1],loaded_data[2],loaded_data[3],loaded_data[4]
    if noData_flag:
        stop=time.clock()
        processing_time=stop-start
示例#34
0
    Config.MongoDB.PORT,
    username=Config.MongoDB.USERNAME,
    password=Config.MongoDB.PASSWORD)
mongodb_db = mongodb_client[Config.MongoDB.DB_NAME]
mongodb_lockers = mongodb_db['lockers']
mongodb_lockersinfo = mongodb_db['lockersinfo']
mongodb_logs = mongodb_db['logs']

face_rec_graph = FaceGraph()
face_extractor = FacenetExtractor(face_rec_graph, model_path=Config.FACENET_DIR)
coeff_graph = FaceGraph()
coeff_extractor = FacenetExtractor(coeff_graph, model_path=Config.COEFF_DIR)
detector = MTCNNDetector(face_rec_graph)
preprocessor = Preprocessor()
spoofing_detector = FaceSpoofingModel3()
rb = RabbitMQ()
rb.channel.queue_declare(queue='{}-lockid'.format(Config.MAIN_NAME))

# Temp Config
LISTEN_FROM_QUEUE = False


def general_process(lock_id, detector, preprocessor, face_extractor,
                    blynk_locker):
    '''
    INPUT: lock_id
    '''
    # Get locker infomation
    # lock_id = 'query from mongo'
    locker_info = mongodb_lockersinfo.find({'lock_id': lock_id})[0]
    this_locker = mongodb_lockers.find({'lock_id': lock_id})[0]
示例#35
0
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)
示例#36
0
import pika
import sys
from rabbitmq import RabbitMQ

publisher = RabbitMQ()
publisher.connect_to_queue()
publisher.publish_to_queue('Hello world')
publisher.close()
示例#37
0
def cam_worker_function(cam_url, area):
    '''
    Cam worker function
    '''
    print("Cam URL: {}".format(cam_url))
    print("Area: {}".format(area))

    # Modify Config
    Config.Track.TRACKING_QUEUE_CAM_TO_CENTRAL = True

    rabbit_mq = RabbitMQ((Config.Rabbit.USERNAME, Config.Rabbit.PASSWORD),
                         (Config.Rabbit.IP_ADDRESS, Config.Rabbit.PORT))

    frame_counter = 0

    # Variables holding the correlation trackers and the name per faceid
    list_of_trackers = TrackersList()

    face_rec_graph = FaceGraph()
    face_extractor = FacenetExtractor(face_rec_graph)
    detector = MTCNNDetector(face_rec_graph)
    preprocessor = Preprocessor()
    matcher = KdTreeMatcher()
    if Config.CALC_FPS:
        start_time = time.time()
    if args.cam_url is not None:
        frame_reader = URLFrameReader(args.cam_url, scale_factor=1.5)
    else:
        frame_reader = RabbitFrameReader(rabbit_mq)

    try:
        while True:  # frame_reader.has_next():
            frame = frame_reader.next_frame()
            if frame is None:
                print("Waiting for the new image")
                list_of_trackers.check_delete_trackers(matcher,
                                                       rabbit_mq,
                                                       history_mode=False)
                continue

            print("Frame ID: %d" % frame_counter)

            if Config.CALC_FPS:
                fps_counter = time.time()

            list_of_trackers.update_dlib_trackers(frame)

            if frame_counter % Config.Frame.FRAME_INTERVAL == 0:
                origin_bbs, points = detector.detect_face(frame)
                for i, origin_bb in enumerate(origin_bbs):
                    display_face, _ = CropperUtils.crop_display_face(
                        frame, origin_bb)
                    print("Display face shape")
                    print(display_face.shape)
                    if 0 in display_face.shape:
                        continue
                    cropped_face = CropperUtils.crop_face(frame, origin_bb)

                    # Calculate embedding
                    preprocessed_image = preprocessor.process(cropped_face)
                    emb_array, coeff = face_extractor.extract_features(
                        preprocessed_image)

                    # Calculate angle
                    angle = FaceAngleUtils.calc_angle(points[:, i])

                    # TODO: refractor matching_detected_face_with_trackers
                    matched_fid = list_of_trackers.matching_face_with_trackers(
                        frame, origin_bb, emb_array)

                    # Update list_of_trackers
                    list_of_trackers.update_trackers_list(
                        matched_fid, origin_bb, display_face, emb_array, angle,
                        area, frame_counter, matcher, rabbit_mq)

                    if Config.Track.TRACKING_QUEUE_CAM_TO_CENTRAL:
                        track_tuple = (matched_fid, display_face, emb_array,
                                       area, time.time(), origin_bb, angle)
                        rabbit_mq.send_tracking(
                            track_tuple,
                            rabbit_mq.RECEIVE_CAM_WORKER_TRACKING_QUEUE)

            # Check detete current trackers time
            list_of_trackers.check_delete_trackers(matcher,
                                                   rabbit_mq,
                                                   history_mode=False)

            frame_counter += 1
            if Config.CALC_FPS:
                print("FPS: %f" % (1 / (time.time() - fps_counter)))

    except KeyboardInterrupt:
        print('Keyboard Interrupt !!! Release All !!!')
        if Config.CALC_FPS:
            print('Time elapsed: {}'.format(time.time() - start_time))
            print('Avg FPS: {}'.format(
                (frame_counter + 1) / (time.time() - start_time)))
        frame_reader.release()
def sendMessage(_tuple):
	msg, exchange, key = _tuple
	print "resending event", msg, "on routing key", key
	RabbitMQ.sendMessage(msg, exchange, key)
示例#39
0
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))