Пример #1
0
def index(): 

    # Get scale and compute image width
    scale, scale_options = common_args.get_scale(config,flask.request)
    redis_tools.set_str(db,'scale', scale)
    image_width, image_height = get_image_size(scale)

    ip_iface_ext = redis_tools.get_str(db,'ip_iface_ext')
    mjpeg_info_dict = redis_tools.get_dict(db,'mjpeg_info_dict')
    mjpeg_info = sorted(mjpeg_info_dict.items(), cmp=mjpeg_info_cmp)

    # Build dict of urls for single camera views
    single_view_url = {}
    for camera in mjpeg_info_dict:
        single_view_url[camera] = flask.url_for('single_camera_view.page',camera=camera)
        
    render_dict = {
            'scale'             : scale,
            'scale_options'     : scale_options,
            'image_width'       : image_width,
            'image_height'      : image_height,
            'ip_iface_ext'      : ip_iface_ext,
            'mjpeg_info'        : mjpeg_info,
            'single_view_url'   : single_view_url,
            }

    return flask.render_template('zoom_calibration.html',**render_dict)
Пример #2
0
def index():

    if flask.g.sijax.is_sijax_request: 
        flask.g.sijax.register_callback('calibrate_button', calibrate_button_handler)
        flask.g.sijax.register_callback('save_button', save_button_handler)
        flask.g.sijax.register_callback('reset_button_ok', reset_button_ok_handler)
        flask.g.sijax.register_callback('reset_button_cancel', reset_button_cancel_handler)
        flask.g.sijax.register_callback('timer_update', timer_update_handler)
        return flask.g.sijax.process_request()

    else:
        # Get scale and compute image width
        scale, scale_options = common_args.get_scale(config,flask.request)
        redis_tools.set_str(db,'scale', scale)
        image_width, image_height = get_image_size(scale)

        ip_iface_ext = redis_tools.get_str(db,'ip_iface_ext')
        mjpeg_info = redis_tools.get_dict(db,'mjpeg_info_dict')
        camera_pairs = redis_tools.get_dict(db,'camera_pairs_dict')
        camera_pairs_mjpeg_info = get_camera_pairs_mjpeg_info(camera_pairs, mjpeg_info)
        calibration_info = get_calibration_info()
            
        render_dict = {
                'scale': scale,
                'scale_options': scale_options,
                'image_width': image_width,
                'image_height': image_height,
                'ip_iface_ext': ip_iface_ext,
                'camera_pairs': camera_pairs,
                'camera_pairs_mjpeg_info': camera_pairs_mjpeg_info,
                'calibration_info': calibration_info,
                }

        return flask.render_template('transform_2d_calibration.html',**render_dict)
Пример #3
0
def get_base_render_dict():
    """
    Creates the base render dictionary passed to all page templates.
    """
    ip_iface_ext = redis_tools.get_str(db, 'ip_iface_ext')
    tab_list = get_tab_list()
    render_dict = {
        'ip_iface_ext': ip_iface_ext,
        'tab_list': tab_list,
    }
    return render_dict
Пример #4
0
def timer_update_handler(obj_response):
    """
    Callback for the timer update function. Resets the modified times for the camera 
    calibration files.
    """
    current_mode = redis_tools.get_str(db, 'current_mode')
    for mode in OPERATING_MODES:
        if mode == current_mode:
            obj_response.attr('#{0}'.format(mode), 'checked', 'checked')
        else:
            obj_response.attr('#{0}'.format(mode), 'checked', '')
Пример #5
0
def show_extra_video(video):
    """
    Handles requests to view the requested extra video streams.
    """
    ip_iface_ext = redis_tools.get_str(db, 'ip_iface_ext')
    tab_list = get_tab_list()
    extra_video_mjpeg_info = get_extra_video_mjpeg_info(video)
    mjpeg_info_dict = redis_tools.get_dict(db, 'mjpeg_info_dict')
    render_dict = get_base_render_dict()
    page_render_dict = {
        'extra_video_name': video,
        'extra_video_mjpeg_info': extra_video_mjpeg_info,
    }
    render_dict.update(page_render_dict)
    return flask.render_template('tracking_2d_extra_video.html', **render_dict)
Пример #6
0
def index():

    if flask.g.sijax.is_sijax_request:
        flask.g.sijax.register_callback('calibrate_button_onclick', calibrate_button_handler)
        flask.g.sijax.register_callback('save_button_onclick', save_button_handler)
        flask.g.sijax.register_callback('reset_button_ok', reset_button_ok_handler)
        flask.g.sijax.register_callback('reset_button_cancel', reset_button_cancel_handler)
        flask.g.sijax.register_callback('timer_update', timer_update_handler)
        return flask.g.sijax.process_request()

    else:
        # Get scale and compute image width
        scale, scale_options = common_args.get_scale(config,flask.request)
        redis_tools.set_str(db,'scale', scale)
        image_width, image_height = get_image_size(scale)

        ip_iface_ext = redis_tools.get_str(db,'ip_iface_ext')
        mjpeg_info_dict = redis_tools.get_dict(db,'mjpeg_info_dict')
        mjpeg_info = sorted(mjpeg_info_dict.items(), cmp=mjpeg_info_cmp)
        target_info = redis_tools.get_dict(db,'target_info')

        # Get list of current camera calibration files
        calibration_info = get_camera_calibration_info()

        # Build dict of urls for single camera views
        single_view_url = {}
        for camera in mjpeg_info_dict:
            single_view_url[camera] = flask.url_for('single_camera_view.page',camera=camera)
            
        render_dict = {
                'scale'             : scale,
                'scale_options'     : scale_options,
                'image_width'       : image_width,
                'image_height'      : image_height,
                'ip_iface_ext'      : ip_iface_ext,
                'mjpeg_info'        : mjpeg_info,
                'target_info'       : target_info,
                'calibration_info'  : calibration_info,
                'single_view_url'   : single_view_url,
                }

        return flask.render_template('camera_calibration.html',**render_dict)
Пример #7
0
def show_control():
    """
    Tracking program main control page. Enables users to start/stop recording and 
    displays information about the running system.
    """
    if flask.g.sijax.is_sijax_request:
        flask.g.sijax.register_callback('mode_change_request',
                                        mode_change_handler)
        flask.g.sijax.register_callback('timer_update', timer_update_handler)
        return flask.g.sijax.process_request()
    else:
        current_mode = redis_tools.get_str(db, 'current_mode')
        watchdog_mjpeg_info = get_watchdog_mjpeg_info()
        regions_dict = redis_tools.get_dict(db, 'regions_dict')
        extra_video_dict = redis_tools.get_dict(db, 'extra_video_dict')
        homography_cal_info = get_homography_calibration_info()
        transform_2d_cal_info = get_transform_2d_calibration_info()
        camera_cal_info = get_camera_calibration_info()
        logging_params_dict = redis_tools.get_dict(db, 'logging_params_dict')
        camera_assignment = get_camera_assignment()
        all_cameras_sorted = camera_assignment.keys()
        all_cameras_sorted.sort(cmp=camera_name_cmp)
        camera_pairs_dict = get_camera_pairs_dict()

        render_dict = get_base_render_dict()
        page_render_dict = {
            'operating_modes': OPERATING_MODES,
            'current_mode': current_mode,
            'watchdog_mjpeg_info': watchdog_mjpeg_info,
            'regions_dict': regions_dict,
            'extra_video_dict': extra_video_dict,
            'logging_params_dict': logging_params_dict,
            'homography_cal_info': homography_cal_info,
            'transform_2d_cal_info': transform_2d_cal_info,
            'camera_cal_info': camera_cal_info,
            'camera_assignment': camera_assignment,
            'all_cameras_sorted': all_cameras_sorted,
            'camera_pairs_dict': camera_pairs_dict,
        }
        render_dict.update(page_render_dict)
        return flask.render_template('tracking_2d_control.html', **render_dict)
Пример #8
0
def index():

    if flask.g.sijax.is_sijax_request:
        flask.g.sijax.register_callback('assignment_change',
                                        assignment_change_handler)
        flask.g.sijax.register_callback('clear_form', clear_form_handler)
        flask.g.sijax.register_callback('assignment_save',
                                        assignment_save_handler)
        flask.g.sijax.register_callback('assignment_load',
                                        assignment_load_handler)
        flask.g.sijax.register_callback('timer_update', timer_update_handler)
        flask.g.sijax.register_callback('test', test_handler)
        return flask.g.sijax.process_request()

    else:
        # Get scale and compute image width
        scale, scale_options = common_args.get_scale(config, flask.request)
        image_width = int(config.camera_image['width'] * float(scale))
        image_height = int(config.camera_image['height'] * float(scale))

        camera_assignment = redis_tools.get_dict(db, 'camera_assignment')
        mjpeg_info_dict = redis_tools.get_dict(db, 'mjpeg_info_dict')
        ip_iface_ext = redis_tools.get_str(db, 'ip_iface_ext')
        select_values = create_select_values(mjpeg_info_dict)

        render_dict = {
            'mjpeg_info_dict': mjpeg_info_dict,
            'camera_assignment': camera_assignment,
            'select_values': select_values,
            'ip_iface_ext': ip_iface_ext,
            'scale_options': scale_options,
            'scale': scale,
            'image_width': image_width,
            'image_height': image_height,
        }

        redis_tools.set_dict(db, 'camera_assignment', camera_assignment)
        return flask.render_template('camera_assignment.html', **render_dict)
Пример #9
0
def mode_change_handler(obj_response, new_mode):

    old_mode = redis_tools.get_str(db, 'current_mode')
    new_mode = str(new_mode)

    if old_mode == new_mode:
        return

    redis_tools.set_str(db, 'current_mode', new_mode)
    frame_rate = redis_tools.get_dict(db, 'frame_rate_dict')['tracking_2d']
    regions_dict = redis_tools.get_dict(db, 'regions_dict')

    # Stop camera triggers
    camera_trigger.stop()
    time.sleep(0.5)  # wait for all frames to pass throught the system
    reset_rand_sync()

    if old_mode == 'recording' or new_mode == 'recording':

        # Find logging and avi recording commands
        service_list = mct_introspection.get_services()
        logging_nodes = get_logging_nodes(service_list)
        recording_nodes = get_recording_nodes(service_list)

        if (old_mode == 'recording') and (new_mode != 'recording'):

            # Stop logging and recording
            for node in logging_nodes:
                tracking_pts_logger.stop_logging(node)
            for node in recording_nodes:
                avi_writer.stop_recording(node, 'dummy.avi', frame_rate)

        if new_mode == 'recording':

            # Create sub-directory for log files.
            log_dir_base = redis_tools.get_dict(
                db, 'logging_params_dict')['directory']
            log_dir = os.path.join(log_dir_base,
                                   datetime.datetime.now().isoformat())
            os.mkdir(log_dir)

            # Start loggers
            for node in logging_nodes:
                filename = '_'.join(node.split('/')[1:3])
                filename = os.path.join(log_dir, '{0}.json'.format(filename))
                tracking_pts_logger.start_logging(node, filename)

            # Start avi recordings
            for node in recording_nodes:
                filename = '_'.join(node.split('/')[1:3])
                filename = os.path.join(log_dir, '{0}.avi'.format(filename))
                avi_writer.start_recording(node, filename, frame_rate)

    if new_mode in ('preview', 'recording'):
        regions_dict = redis_tools.get_dict(db, 'regions_dict')
        # Reset frame drop correctors and restart camera triggers
        frame_drop_corrector.reset_all()
        frame_drop_watchdog.reset()

        # Reset image_stitcher and three_point_tracker synchronizer for all tracking regions
        for region in regions_dict:
            image_stitcher.reset(region)
            three_point_tracker_synchronizer.reset(region)

        camera_trigger.start(frame_rate)