Esempio n. 1
0
    def __init__(self, video_list, fps=10.0):
        """Given a list a video, uses MultipleVideoLoader object to loaded all videos and
        sample at spefic fps on a diferent thread.
        Args:
            video_list (dict): contais the path of all four video where the key identifies
            the ID of the camera.
            fps (float): frequency of sample of the video.
        """
        self.log = Logger("VideoLoaderThread")

        if len(video_list) == 0:
            self.log.warn("You are trying to initialize with a empty list of videos")

        self.video_loader = MultipleVideoLoader(video_list)
        self.num_samples = self.video_loader.n_frames()
        self.count_sample = 0
        self.fps = fps
        info = {
            "total_samples": self.num_samples
        }
        self.log.info('{}', str(info).replace("'", '"'))
        self.run = True
        self.queue = queue.Queue()
        self.thread = threading.Thread(target=self._reader, daemon=True)
        self.thread.start()
Esempio n. 2
0
def create_exporter(service_name, uri):
    """ Funtion to create the exporter in the Zipkin instrumentation.

    Parameters
    ----------
    service_name: str
        Name of the service the will appear on zipkin.
    uri: str
        Zipkin URI.

    Returns
    -------
    ZipkinExporter
        The OpenCensus Zipkin Trace Exporter is a trace exporter that exports data to Zipkin.
    """
    log = Logger(name="CreateExporter")
    zipkin_ok = re.match("http:\\/\\/([a-zA-Z0-9\\.]+)(:(\\d+))?", uri)
    if not zipkin_ok:
        log.critical(
            "Invalid zipkin uri \"{}\", expected http://<hostname>:<port>",
            uri)
    exporter = ZipkinExporter(service_name=service_name,
                              host_name=zipkin_ok.group(1),
                              port=zipkin_ok.group(3),
                              transport=AsyncTransport)
    return exporter
Esempio n. 3
0
def load_options():
    log = Logger(name='LoadOptions')
    op_file = sys.argv[1] if len(sys.argv) > 1 else 'options.json'
    try:
        with open(op_file, 'r') as f:
            try:
                op = Parse(f.read(), SkeletonsHeatmapOptions())
                log.info('Options: \n{}', op)
            except Exception as ex:
                log.critical('Unable to load options from \'{}\'. \n{}',
                             op_file, ex)
                sys.exit(-1)
            except:
                log.critical('Unable to load options from \'{}\'', op_file)
                sys.exit(-1)
    except Exception as ex:
        log.critical('Unable to open file \'{}\'', op_file)
        sys.exit(-1)

    message = op.DESCRIPTOR.full_name
    # validation
    if op.period_ms < 200:
        message += " 'period_ms' field must be equal or greater than 200. "
        message += "Given {}".format(op.period_ms)
        raise Exception(message)
    if op.period_ms > 1000:
        message += " 'period_ms' field must be equal or less than 1000. "
        message += "Given {}".format(op.period_ms)
        raise Exception(message)

    return op
Esempio n. 4
0
def main():
    service_name = 'SkeletonsDetector.Detect'

    op = load_options()
    sd = RPCSkeletonsDetector(op)

    log = Logger(name=service_name)
    channel = Channel(op.broker_uri)
    log.info('Connected to broker {}', op.broker_uri)
    provider = ServiceProvider(channel)
    provider.add_interceptor(LogInterceptor())

    max_batch_size = max(100, op.zipkin_batch_size)
    exporter = ZipkinExporter(
        service_name=service_name,
        host_name=op.zipkin_host,
        port=op.zipkin_port,
        transport=BackgroundThreadTransport(max_batch_size=max_batch_size),
    )
    tracing = TracingInterceptor(exporter=exporter)

    provider.delegate(topic='SkeletonsDetector.Detect',
                      function=partial(RPCSkeletonsDetector.detect, sd),
                      request_type=Image,
                      reply_type=ObjectAnnotations)

    provider.run()
    def __init__(self,
                 channel,
                 max_requests,
                 min_requests=None,
                 log_level=Logger.INFO,
                 zipkin_exporter=None):

        if min_requests is None:
            min_requests = max_requests
        if min_requests < 0:
            min_requests = 0
        if min_requests > max_requests:
            raise Exception("'min_requests' must be lower than 'max_requests'")

        self._channel = channel
        self._subscription = Subscription(self._channel)

        self._do_tracing = zipkin_exporter is not None
        self._zipkin_exporter = zipkin_exporter

        self._log = Logger(name='RequestManager')
        self._log.set_level(level=log_level)

        self._min_requests = min_requests
        self._max_requests = max_requests
        self._can_request = True

        self._requests = {}
Esempio n. 6
0
    def __init__(self, broker_uri, management_uri, log_level):
        self.log = Logger(name="BrokerEvents", level=log_level)

        self.log.debug("broker_uri='{}'", broker_uri)
        self.channel = Channel(broker_uri)
        self.subscription = Subscription(self.channel)
        self.subscription.subscribe(topic="binding.*")

        self.log.debug("management_uri='{}'", management_uri)
        self.consumers = self.query_consumers_http(management_uri)
Esempio n. 7
0
def create_exporter(service_name, uri):
    log = Logger(name="CreateExporter")
    zipkin_ok = re.match("http:\\/\\/([a-zA-Z0-9\\.]+)(:(\\d+))?", uri)
    if not zipkin_ok:
        log.critical(
            "Invalid zipkin uri \"{}\", expected http://<hostname>:<port>",
            uri)
    exporter = ZipkinExporter(service_name=service_name,
                              host_name=zipkin_ok.group(1),
                              port=zipkin_ok.group(3),
                              transport=AsyncTransport)
    return exporter
Esempio n. 8
0
class BrokerEvents(object):
    def __init__(self, broker_uri, management_uri, log_level):
        self.log = Logger(name="BrokerEvents", level=log_level)

        self.log.debug("broker_uri='{}'", broker_uri)
        self.channel = Channel(broker_uri)
        self.subscription = Subscription(self.channel)
        self.subscription.subscribe(topic="binding.*")

        self.log.debug("management_uri='{}'", management_uri)
        self.consumers = self.query_consumers_http(management_uri)

    def run(self):
        while True:
            msg = self.channel.consume()
            self.log.debug("topic='{}' metadata={}", msg.topic, msg.metadata)

            if msg.metadata["destination_kind"] != "queue" or \
               msg.metadata["source_name"] != "is":
                continue

            event = msg.topic.split('.')[-1]
            topic = msg.metadata["routing_key"]
            queue = msg.metadata["destination_name"]

            if event == "created":
                self.consumers.info[topic].consumers.append(queue)
            elif event == "deleted":
                self.consumers.info[topic].consumers.remove(queue)
                if len(self.consumers.info[topic].consumers) == 0:
                    del self.consumers.info[topic]

            self.log.info("event='{}' topic='{}' queue='{}'", event, topic,
                          queue)

            self.channel.publish(
                Message(content=self.consumers),
                topic="BrokerEvents.Consumers",
            )

    @staticmethod
    def query_consumers_http(management_uri):
        reply = requests.get(management_uri + "/api/bindings")
        if reply.status_code != 200:
            why = "Failed to query management API, code={}".format(
                reply.status_code)
            raise RuntimeError(why)

        bindings = reply.json()
        bindings = [
            b for b in bindings
            if b["destination_type"] == "queue" and b["source"] == "is"
        ]

        consumers = ConsumerList()
        for b in bindings:
            consumers.info[b["routing_key"]].consumers.append(b["destination"])
        return consumers
Esempio n. 9
0
def load_options():
    log = Logger(name='LoadOptions')
    op_file = sys.argv[1] if len(sys.argv) > 1 else 'options.json'
    try:
        with open(op_file, 'r') as f:
            try:
                op = Parse(f.read(), ObjectAnnotationsTransformerOptions())
                log.info('Options: \n{}', op)
            except Exception as ex:
                log.critical('Unable to load options from \'{}\'. \n{}',
                             op_file, ex)
            except:
                log.critical('Unable to load options from \'{}\'', op_file)
    except Exception as ex:
        log.critical('Unable to open file \'{}\'', op_file)

    return op
Esempio n. 10
0
def main():
    service_name = 'SkeletonsDetector.Detection'
    re_topic = re.compile(r'CameraGateway.(\w+).Frame')

    op = load_options()
    sd = SkeletonsDetector(op)

    log = Logger(name=service_name)
    channel = StreamChannel(op.broker_uri)
    log.info('Connected to broker {}', op.broker_uri)

    max_batch_size = max(100, op.zipkin_batch_size)
    exporter = ZipkinExporter(
        service_name=service_name,
        host_name=op.zipkin_host,
        port=op.zipkin_port,
        transport=BackgroundThreadTransport(max_batch_size=max_batch_size),
    )

    subscription = Subscription(channel=channel, name=service_name)
    subscription.subscribe('CameraGateway.*.Frame')

    while True:
        msg, dropped = channel.consume(return_dropped=True)

        tracer = Tracer(exporter, span_context=msg.extract_tracing())
        span = tracer.start_span(name='detection_and_render')
        detection_span = None

        with tracer.span(name='unpack'):
            im = msg.unpack(Image)
            im_np = get_np_image(im)
        with tracer.span(name='detection') as _span:
            skeletons = sd.detect(im_np)
            detection_span = _span
        with tracer.span(name='pack_and_publish_detections'):
            sks_msg = Message()
            sks_msg.topic = re_topic.sub(r'SkeletonsDetector.\1.Detection',
                                         msg.topic)
            sks_msg.inject_tracing(span)
            sks_msg.pack(skeletons)
            channel.publish(sks_msg)
        with tracer.span(name='render_pack_publish'):
            im_rendered = draw_skeletons(im_np, skeletons)
            rendered_msg = Message()
            rendered_msg.topic = re_topic.sub(r'SkeletonsDetector.\1.Rendered',
                                              msg.topic)
            rendered_msg.pack(get_pb_image(im_rendered))
            channel.publish(rendered_msg)

        span.add_attribute('Detections', len(skeletons.objects))
        tracer.end_span()
        log.info('detections = {:2d}, dropped_messages = {:2d}',
                 len(skeletons.objects), dropped)
        log.info('took_ms = {{ detection: {:5.2f}, service: {:5.2f}}}',
                 span_duration_ms(detection_span), span_duration_ms(span))
Esempio n. 11
0
 def __init__(self, channel, driver, robot_par):
     self.channel = channel
     self.driver = driver
     self.param = robot_par
     now = time()    # time in seconds
     #self.last_speed_command = now
     self.last_sampling = now
     self.sonar_topic = "RobotGateway.{}.SonarScan"
     self.pose_topic = "RobotGateway.{}.Pose"
     self.log = Logger(name="gatewayLog")
Esempio n. 12
0
def load_options():
    log = Logger(name='LoadingOptions')
    op_file = sys.argv[1] if len(sys.argv) > 1 else 'options.json'
    try:
        with open(op_file, 'r') as f:
            try:
                op = Parse(f.read(), GestureRecognizierOptions())
                log.info('GestureRecognizierOptions: \n{}', op)
                return op
            except Exception as ex:
                log.critical('Unable to load options from \'{}\'. \n{}', op_file, ex)
    except Exception as ex:
        log.critical('Unable to open file \'{}\'', op_file)
Esempio n. 13
0
def main():
    log = Logger(name="Parser")
    parser = argparse.ArgumentParser(description='Broker events service')
    parser.add_argument('--config',
                        dest='config',
                        type=str,
                        default="config.json",
                        help='path to configuration file')

    args = parser.parse_args()
    with open(args.config) as f:
        config = json.load(f)
        log.info("{}", config)

    service = BrokerEvents(
        broker_uri=config["broker_uri"],
        management_uri=config["management_uri"],
        log_level=logging.getLevelName(config["log_level"]),
    )

    service.run()
Esempio n. 14
0
def main():
    service_name = 'FaceDetector.Detect'
    log = Logger(name=service_name)

    op = load_options()
    detector = RPCFaceDetector(op.model)

    channel = Channel(op.broker_uri)
    log.info('Connected to broker {}', op.broker_uri)

    provider = ServiceProvider(channel)
    provider.add_interceptor(LogInterceptor())

    exporter = create_exporter(service_name=service_name, uri=op.zipkin_uri)
    tracing = TracingInterceptor(exporter=exporter)
    provider.add_interceptor(tracing)

    provider.delegate(topic='FaceDetector.Detect',
                      function=detector.detect,
                      request_type=Image,
                      reply_type=ObjectAnnotations)

    provider.run()
Esempio n. 15
0
def load_options():
    log = Logger(name='LoadOptions')
    op_file = sys.argv[1] if len(sys.argv) > 1 else 'options.json'
    try:
        with open(op_file, 'r') as f:
            try:
                op = Parse(f.read(), options_pb2.RobotGatewayOptions())
                log.info('Options: \n{}', op)
            except Exception as ex:
                log.critical('Unable to load options from \'{}\'. \n{}',
                             op_file, ex)
            except:
                log.critical('Unable to load options from \'{}\'', op_file)
    except Exception as ex:
        log.critical('Unable to open file \'{}\'', op_file)

    message = op.DESCRIPTOR.full_name
    # validation
    if op.robot_parameters.sampling_rate < 0.1:
        message += " 'sampling_rate' field must be equal or greater than 0.1. "
        message += "Given {}".format(op.robot_parameters.sampling_rate)
        raise Exception(message)

    return op
Esempio n. 16
0
def main():
    service_name = "FaceDetector.Detection"
    log = Logger(name=service_name)
    op = load_options()
    face_detector = FaceDetector(op.model)

    channel = StreamChannel(op.broker_uri)
    log.info('Connected to broker {}', op.broker_uri)

    exporter = create_exporter(service_name=service_name, uri=op.zipkin_uri)

    subscription = Subscription(channel=channel, name=service_name)
    subscription.subscribe(topic='CameraGateway.*.Frame')

    while True:
        msg, dropped = channel.consume_last(return_dropped=True)

        tracer = Tracer(exporter, span_context=msg.extract_tracing())
        span = tracer.start_span(name='detection_and_render')
        detection_span = None

        with tracer.span(name='unpack'):
            im = msg.unpack(Image)
            im_np = to_np(im)

        with tracer.span(name='detection') as _span:
            camera_id = get_topic_id(msg.topic)
            faces = face_detector.detect(im_np)
            detection_span = _span

        with tracer.span(name='pack_and_publish_detections'):
            faces_msg = Message()
            faces_msg.topic = 'FaceDetector.{}.Detection'.format(camera_id)
            faces_msg.inject_tracing(span)
            faces_msg.pack(faces)
            channel.publish(faces_msg)

        with tracer.span(name='render_pack_publish'):
            img_rendered = draw_detection(im_np, faces)
            rendered_msg = Message()
            rendered_msg.topic = 'FaceDetector.{}.Rendered'.format(camera_id)
            rendered_msg.pack(to_image(img_rendered))
            channel.publish(rendered_msg)

        span.add_attribute('Detections', len(faces.objects))
        tracer.end_span()

        info = {
            'detections': len(faces.objects),
            'dropped_messages': dropped,
            'took_ms': {
                'detection': round(span_duration_ms(detection_span), 2),
                'service': round(span_duration_ms(span), 2)
            }
        }
        log.info('{}', str(info).replace("'", '"'))
Esempio n. 17
0
 def __init__(self, driver):
     self.driver = driver
     self.logger = Logger("CameraGateway")
Esempio n. 18
0
class CameraGateway(object):
    def __init__(self, driver):
        self.driver = driver
        self.logger = Logger("CameraGateway")

    def get_config(self, field_selector, ctx):
        fields = field_selector.fields
        camera_config = CameraConfig()

        if CameraConfigFields.Value("ALL") in fields or \
           CameraConfigFields.Value("SAMPLING_SETTINGS") in fields:
            get_val(self.driver.get_sampling_rate,
                    camera_config.sampling.frequency, "value")
            get_val(self.driver.get_delay, camera_config.sampling.delay,
                    "value")

        if CameraConfigFields.Value("ALL") in fields or \
           CameraConfigFields.Value("IMAGE_SETTINGS") in fields:
            get_obj(self.driver.get_resolution, camera_config.image.resolution)
            get_obj(self.driver.get_image_format, camera_config.image.format)
            get_val(self.driver.get_color_space,
                    camera_config.image.color_space, "value")
            get_obj(self.driver.get_region_of_interest,
                    camera_config.image.region)

        if CameraConfigFields.Value("ALL") in fields or \
           CameraConfigFields.Value("CAMERA_SETTINGS") in fields:
            get_obj(self.driver.get_brightness,
                    camera_config.camera.brightness)
            get_obj(self.driver.get_exposure, camera_config.camera.exposure)
            get_obj(self.driver.get_focus, camera_config.camera.focus)
            get_obj(self.driver.get_gain, camera_config.camera.gain)
            get_obj(self.driver.get_gamma, camera_config.camera.gamma)
            get_obj(self.driver.get_hue, camera_config.camera.hue)
            get_obj(self.driver.get_iris, camera_config.camera.iris)
            get_obj(self.driver.get_saturation,
                    camera_config.camera.saturation)
            get_obj(self.driver.get_sharpness, camera_config.camera.sharpness)
            get_obj(self.driver.get_shutter, camera_config.camera.shutter)
            get_obj(self.driver.get_white_balance_bu,
                    camera_config.camera.white_balance_bu)
            get_obj(self.driver.get_white_balance_rv,
                    camera_config.camera.white_balance_rv)
            get_obj(self.driver.get_zoom, camera_config.camera.zoom)

        return camera_config

    def set_config(self, camera_config, ctx):
        if camera_config.HasField("sampling"):
            if camera_config.sampling.HasField("frequency"):
                self.driver.set_sampling_rate(
                    camera_config.sampling.frequency.value)
            if camera_config.sampling.HasField("delay"):
                self.driver.set_delay(camera_config.sampling.delay.value)

        if camera_config.HasField("image"):
            if camera_config.image.HasField("resolution"):
                self.driver.set_resolution(camera_config.image.resolution)
            if camera_config.image.HasField("format"):
                self.driver.set_image_format(camera_config.image.format)
            if camera_config.image.HasField("color_space"):
                self.driver.set_color_space(
                    camera_config.image.color_space.value)
            if camera_config.image.HasField("region"):
                self.driver.set_region_of_interest(camera_config.image.region)

        if camera_config.HasField("camera"):
            if camera_config.camera.HasField("brightness"):
                self.driver.set_brightness(camera_config.camera.brightness)
            if camera_config.camera.HasField("exposure"):
                self.driver.set_exposure(camera_config.camera.exposure)
            if camera_config.camera.HasField("focus"):
                self.driver.set_focus(camera_config.camera.focus)
            if camera_config.camera.HasField("gain"):
                self.driver.set_gain(camera_config.camera.gain)
            if camera_config.camera.HasField("gamma"):
                self.driver.set_gamma(camera_config.camera.gamma)
            if camera_config.camera.HasField("hue"):
                self.driver.set_hue(camera_config.camera.hue)
            if camera_config.camera.HasField("iris"):
                self.driver.set_iris(camera_config.camera.iris)
            if camera_config.camera.HasField("saturation"):
                self.driver.set_saturation(camera_config.camera.saturation)
            if camera_config.camera.HasField("sharpness"):
                self.driver.set_sharpness(camera_config.camera.sharpness)
            if camera_config.camera.HasField("shutter"):
                self.driver.set_shutter(camera_config.camera.shutter)
            if camera_config.camera.HasField("white_balance_bu"):
                self.driver.set_white_balance_bu(
                    camera_config.camera.white_balance_bu)
            if camera_config.camera.HasField("white_balance_rv"):
                self.driver.set_white_balance_rv(
                    camera_config.camera.white_balance_rv)
            if camera_config.camera.HasField("zoom"):
                self.driver.set_zoom(camera_config.camera.zoom)
        return Empty()

    def run(self, id, broker_uri):
        service_name = "CameraGateway.{}".format(id)

        channel = Channel(broker_uri)
        server = ServiceProvider(channel)

        logging = LogInterceptor()
        server.add_interceptor(logging)

        server.delegate(topic=service_name + ".GetConfig",
                        request_type=FieldSelector,
                        reply_type=CameraConfig,
                        function=self.get_config)

        server.delegate(topic=service_name + ".SetConfig",
                        request_type=CameraConfig,
                        reply_type=Empty,
                        function=self.set_config)

        self.driver.start_capture()
        self.logger.info("Listening for requests")

        while True:
            image = self.driver.grab_image()
            channel.publish(Message(content=image),
                            topic=service_name + ".Frame")

            pose = self.driver.get_pose()
            frameTransList = FrameTransformations()
            frameTransList.tfs.extend([pose])
            channel.publish(Message(content=frameTransList),
                            topic=service_name + ".FrameTransformations")

            try:
                message = channel.consume(timeout=0)
                if server.should_serve(message):
                    server.serve(message)
            except socket.timeout:
                pass
def load_options():
    log = Logger(name='LoadingOptions')
    op_file = sys.argv[1] if len(sys.argv) > 1 else 'options.json'
    try:
        with open(op_file, 'r') as f:
            try:
                op = Parse(f.read(), Options())
                mem_frac = op.per_process_gpu_memory_fraction
                if mem_frac < 0.0 or mem_frac > 1.0:
                    log.critical(
                        "Invalid value for 'per_process_gpu_memory_fraction': {}. Must be in [0.0, 1.0]",
                        mem_frac)
                log.info('Options: \n{}', op)
                return op
            except Exception as ex:
                log.critical('Unable to load options from \'{}\'. \n{}',
                             op_file, ex)
            except:
                log.critical('Unable to load options from \'{}\'', op_file)
    except Exception as ex:
        log.critical('Unable to open file \'{}\'', op_file)
Esempio n. 20
0
import argparse
import dateutil.parser as dp 
from is_wire.core import Message, Logger
from utils import get_pb_image, StreamChannel
from cv2 import VideoCapture, CAP_PROP_FPS
from sys import exit


def span_duration_ms(span):
    dt = dp.parse(span.end_time) - dp.parse(span.start_time)
    return dt.total_seconds() * 1000.0

service_name = 'CameraGateway.Frame'
log = Logger(name=service_name)

parser = argparse.ArgumentParser(
    description='Utility to capture a sequence of images from multiples cameras'
)
parser.add_argument(
    '--id', '-i', type=int, required=False, help='Camera ID', default=0)
parser.add_argument(
    '--device', '-d', type=int, required=False, help='Camera device. 0 for /dev/video0', default=0)
parser.add_argument(
    '--fps', '-f', type=int, required=False, help='FPS', default=10)
parser.add_argument(
    '--uri', '-u', type=str, required=False, help='broker_uri', default='amqp://localhost:5672')
args = parser.parse_args()

device = args.device
fps = args.fps
broker_uri = args.uri
Esempio n. 21
0
        log.critical('Unable to open file \'{}\'', op_file)

    message = op.DESCRIPTOR.full_name
    # validation
    if op.robot_parameters.sampling_rate < 0.1:
        message += " 'sampling_rate' field must be equal or greater than 0.1. "
        message += "Given {}".format(op.robot_parameters.sampling_rate)
        raise Exception(message)

    return op


# Carrega parametros do robo e endereco do broker do arquivo Json
op_config = load_options()

ATSPlog = Logger(name='unpack')

service_name = "RobotGateway.{}".format(op_config.robot_parameters.id)
sonar_topic = "RobotGateway.{}.SonarScan".format(op_config.robot_parameters.id)
pose_topic = "RobotGateway.{}.Pose".format(op_config.robot_parameters.id)

# instania channel passando endereco do broker
# estabelece conexao com o broker
channel = Channel(op_config.broker_uri)
ATSPlog.info("event=ChannelInitDone")

# Inscreve nos topicos que deseja receber mensagem
subscription = Subscription(channel)
subscription.subscribe(pose_topic)
subscription.subscribe(sonar_topic)
ATSPlog.info("SubscriptionsDone")
Esempio n. 22
0
import os
import json
from subprocess import Popen, PIPE, STDOUT
from is_wire.core import Logger

log = Logger(name="SplitSamples")

if not os.path.exists("samples"):
    log.critical("'samples' folder not found")
if not os.path.exists("samples/spots.json"):
    log.critical("'samples/spots.json' file not found")

with open("samples/spots.json", 'r') as f:
    spots = json.load(f)

ffmpeg_command = "ffmpeg -y -i gestures.MOV -ss {ss:.2f} -t {t:.2f} -an samples/{gesture:02d}.MOV"
for spot in spots:
    g_id = int(spot['gesture'])
    command = ffmpeg_command.format(ss=spot['ss'], t=spot['t'], gesture=g_id)
    process = Popen(command.split(), stdout=PIPE, stderr=STDOUT)
    log.info("{}", command)
    if process.wait() == 0:
        log.info("{} | {:.2f} + {:.2f}", g_id, spot['ss'], spot['t'])
    else:
        log.error("Failed to split video gesture: {}", g_id)
Esempio n. 23
0
from google.protobuf.json_format import MessageToDict

MIN_REQUESTS = 5
MAX_REQUESTS = 10
DEADLINE_SEC = 15.0


class State(Enum):
    MAKE_REQUESTS = 1
    RECV_REPLIES = 2
    CHECK_END_OF_VIDEO_AND_SAVE = 3
    CHECK_FOR_TIMEOUTED_REQUESTS = 4
    EXIT = 5


log = Logger(name='Request2dSkeletons')
options = load_options(print_options=False)

if not os.path.exists(options.folder):
    log.critical("Folder '{}' doesn't exist", options.folder)
    sys.exit(-1)

files = next(os.walk(options.folder))[2]  # only files from first folder level
video_files = list(filter(lambda x: x.endswith('.mp4'), files))

pending_videos = []
n_annotations = {}
for video_file in video_files:
    base_name = video_file.split('.')[0]
    annotation_file = '{}_2d.json'.format(base_name)
    annotation_path = os.path.join(options.folder, annotation_file)
Esempio n. 24
0
    file_results.write("Distância do tornozelo ao chão: %5.3f m" % alt_torn)
    file_results.write("\n")
    file_results.write("Tamanho da perna esquerda: %5.3f m" %
                       comprimento_medio_perna_esquerda)
    file_results.write("\n")
    file_results.write("Tamanho da perna direita: %5.3f m" %
                       comprimento_medio_perna_direita)
    file_results.write("\n")

    file_results.write("Altura média: %5.3f m" %
                       altura_media)  #(sum(altura_pessoa)/len(altura_pessoa)))
    file_results.write("\n")
    file_results.close()


log = Logger(name='WatchVideos')
with open('keymap.json', 'r') as f:
    keymap = json.load(f)
options = load_options(print_options=False)

if not os.path.exists(options.folder):
    log.critical("Folder '{}' doesn't exist", options.folder)

with open('gestures.json', 'r') as f:
    gestures = json.load(f)
    gestures = OrderedDict(sorted(gestures.items(), key=lambda kv: int(kv[0])))

parser = argparse.ArgumentParser(
    description='Utility to capture a sequence of images from multiples cameras'
)
parser.add_argument('--person',
#     channel.queue_declare(queue='Receive_information')
#     print("Recebido!")

# def receive_information():
#     channel.basic_consume(queue='Receive_information', on_message_callback=callback, auto_ack=True)
#     channel.start_consuming()


def place_images(output_image, images, x_offset=0, y_offset=0):
    w, h = images[0].shape[1], images[0].shape[0]
    output_image[0 + y_offset:h + y_offset, 0 + x_offset:w + x_offset, :] = images[0]
    output_image[0 + y_offset:h + y_offset, w + x_offset:2 * w + x_offset, :] = images[1]
    output_image[h + y_offset:2 * h + y_offset, 0 + x_offset:w + x_offset, :] = images[2]
    output_image[h + y_offset:2 * h + y_offset, w + x_offset:2 * w + x_offset, :] = images[3]

log = Logger(name='WatchVideos')
with open('keymap.json', 'r') as f:
    keymap = json.load(f)
options = load_options(print_options=False)

if not os.path.exists(options.folder):
    log.critical("Folder '{}' doesn't exist", options.folder)

with open('gestures.json', 'r') as f:
    gestures = json.load(f)
    gestures = OrderedDict(sorted(gestures.items(), key=lambda kv: int(kv[0])))

parser = argparse.ArgumentParser(
    description='Utility to capture a sequence of images from multiples cameras')
parser.add_argument('--person', '-p', type=int, required=True, help='ID to identity person')
parser.add_argument('--gesture', '-g', type=int, required=True, help='ID to identity gesture')
Esempio n. 26
0
    b, g, r = cv2.split(aux_diferenca_frame)
    zero_array = np.zeros_like(b)
    b = cv2.merge([b, zero_array, zero_array])
    g = cv2.merge([zero_array, g, zero_array])
    r = cv2.merge([zero_array, zero_array, r])
    resultado = None
    if (k <= int(num_frames / 6)):
        resultado = r
    elif (k > int(num_frames / 6) and (k <= int(2 * num_frames / 6))):
        resultado = g
    else:
        resultado = b
    return resultado


log = Logger(name='WatchVideos')
with open('keymap.json', 'r') as f:
    keymap = json.load(f)
options = load_options(print_options=False)

#categorias=['TIME_UP_GO_GRAYSCALE']
#categorias=['CAMINHADA_EM_CIRCULO_GRAYSCALE','IDA_E_VOLTA__DUAS_VEZES_GRAYSCALE']
categorias = [
    'TIME_UP_GO_GRAYSCALE', 'CAMINHADA_EM_CIRCULO_GRAYSCALE',
    'IDA_E_VOLTA__DUAS_VEZES_GRAYSCALE',
    'ELEVACAO_EXCESSIVA_DO_CALCANHAR_GRASCALE', 'CIRCUNDACAO_DO_PE_GRAYSCALE',
    'ASSIMETRIA_DO_COMPRIMENTO_DE_PASSO_GRAYSCALE'
]
for categoria in categorias:
    t = 0
    for l in range(0, 13):
Esempio n. 27
0
def main():

    service_name = "CameraGateway"
    log = Logger(service_name)
    options = load_options()
    camera = CameraGateway(fps=options["fps"])

    publish_channel = Channel(options['broker_uri'])
    rpc_channel = Channel(options['broker_uri'])
    server = ServiceProvider(rpc_channel)
    logging = LogInterceptor()
    server.add_interceptor(logging)

    server.delegate(topic=service_name + ".*.GetConfig",
                    request_type=FieldSelector,
                    reply_type=CameraConfig,
                    function=camera.get_config)

    server.delegate(topic=service_name + ".*.SetConfig",
                    request_type=CameraConfig,
                    reply_type=Empty,
                    function=camera.set_config)

    exporter = create_exporter(service_name=service_name,
                               uri=options["zipkin_uri"])

    while True:

        # iterate through videos listed
        for video in options['videos']:

            # id of the first sequence of videos
            person_id = video['person_id']
            gesture_id = video['gesture_id']

            # getting the path of the 4 videos
            video_files = {
                cam_id: os.path.join(
                    options['folder'],
                    'p{:03d}g{:02d}c{:02d}.mp4'.format(person_id, gesture_id,
                                                       cam_id))
                for cam_id in options["cameras_id"]
            }

            for iteration in range(video['iterations']):

                info = {
                    "person": person_id,
                    "gesture": gesture_id,
                    "iteration": iteration
                }
                log.info('{}', str(info).replace("'", '"'))

                # object that let get images from multiples videos files
                video_loader = FramesLoader(video_files)

                # iterate through all samples on video
                while True:

                    time_initial = time.time()

                    # listen server for messages about change
                    try:
                        message = rpc_channel.consume(timeout=0)
                        if server.should_serve(message):
                            server.serve(message)
                    except socket.timeout:
                        pass

                    frame_id, frames = video_loader.read()

                    for cam in sorted(frames.keys()):
                        tracer = Tracer(exporter)
                        span = tracer.start_span(name='frame')
                        pb_image = to_pb_image(frames[cam])
                        msg = Message(content=pb_image)
                        msg.inject_tracing(span)
                        topic = 'CameraGateway.{}.Frame'.format(cam)
                        publish_channel.publish(msg, topic=topic)
                        tracer.end_span()

                    took_ms = (time.time() - time_initial) * 1000

                    dt = (1 / camera.fps) - (took_ms / 1000)
                    if dt > 0:
                        time.sleep(dt)
                        info = {
                            "sample": frame_id,
                            "took_ms": took_ms,
                            "wait_ms": dt * 1000
                        }
                        log.info('{}', str(info).replace("'", '"'))

                    if frame_id >= (video_loader.num_samples - 1):
                        video_loader.release()
                        del video_loader
                        gc.collect()
                        break

        if options['loop'] is False:
            break
Esempio n. 28
0
from is_wire.core import Logger
from gateway import RobotGateway
from driver import PepperRobotDriver
import json
import sys
import os

log = Logger("Service")

config_path = "conf.json" if len(sys.argv) != 2 else sys.argv[1]
with open(config_path) as f:
    config = json.load(f)

log.info("config_file @'{}':\n{}", config_path, json.dumps(config, indent=4))


def env_or_default(env, default):
    value = os.environ[env] if env in os.environ else default
    log.info("{}='{}'".format(env, value))
    return value


broker_uri = env_or_default("BROKER_URI", config["broker_uri"])
robot_uri = env_or_default("ROBOT_URI", str(config["robot_uri"]))
robot_id = env_or_default("ROBOT_ID", config["robot_id"])

driver = PepperRobotDriver(robot_uri=robot_uri,
                           parameters=config["driver_params"])

service = RobotGateway(driver=driver)
service.run(id=robot_id, broker_uri=broker_uri)
from is_msgs.image_pb2 import ObjectAnnotations
from is_wire.core import Channel, Message, Subscription, Logger
from is_wire.core import Tracer, ZipkinExporter, BackgroundThreadTransport
from is_wire.core.utils import now
from utils import load_options
from heatmap import SkeletonsHeatmap

from builtins import super

class MyChannel(Channel):
    def consume_until(self, deadline):
        timeout = max([deadline - now(), 0.0])
        return super().consume(timeout=timeout)

service_name = 'Skeletons.Heatmap'
log = Logger(name=service_name)
ops = load_options()

channel = MyChannel(ops.broker_uri)
subscription = Subscription(channel)
exporter = ZipkinExporter(
    service_name=service_name,
    host_name=ops.zipkin_host,
    port=ops.zipkin_port,
    transport=BackgroundThreadTransport(max_batch_size=20),
)

subscription.subscribe('Skeletons.Localization')

sks_hm = SkeletonsHeatmap(ops)
    return altura_da_pessoa


def place_images(output_image, images, x_offset=0, y_offset=0):
    w, h = images[0].shape[1], images[0].shape[0]
    output_image[0 + y_offset:h + y_offset,
                 0 + x_offset:w + x_offset, :] = images[0]
    output_image[0 + y_offset:h + y_offset,
                 w + x_offset:2 * w + x_offset, :] = images[1]
    output_image[h + y_offset:2 * h + y_offset,
                 0 + x_offset:w + x_offset, :] = images[2]
    output_image[h + y_offset:2 * h + y_offset,
                 w + x_offset:2 * w + x_offset, :] = images[3]


log = Logger(name='WatchVideos')
with open('keymap.json', 'r') as f:
    keymap = json.load(f)
options = load_options(print_options=False)

if not os.path.exists(options.folder):
    log.critical("Folder '{}' doesn't exist", options.folder)

with open('gestures.json', 'r') as f:
    gestures = json.load(f)
    gestures = OrderedDict(sorted(gestures.items(), key=lambda kv: int(kv[0])))

parser = argparse.ArgumentParser(
    description='Utility to capture a sequence of images from multiples cameras'
)
parser.add_argument('--person',