Example #1
0
def correct_template(template_image_path, template_data_dir, omr_api,
                     storage_api):
    """
    Run template correction
    :param template_image_path: Path to template image
    :param template_data_dir: Path to template data file (.omr)
    :param omr_api: OMR API Instance
    :param storage_api: StorageApi Instance
    :return: Correction response
    """

    image_file_name = os.path.basename(template_image_path)
    # upload template image
    upload_file(template_image_path, image_file_name, storage_api)

    # locate generated template file (.omr) and provide it's data as function parameter
    template_data_path = os.path.join(
        template_data_dir,
        os.path.splitext(image_file_name)[0] + '.omr')
    function_param = serialize_files([template_data_path])
    call_params = OMRFunctionParam(function_param=function_param,
                                   additional_param='')

    # call template correction
    result = omr_api.post_run_omr_task(name=image_file_name,
                                       action_name='CorrectTemplate',
                                       param=call_params)
    return result
Example #2
0
def generate_template(omr_api, template_file_path, logos_folder):
    """
    Generate new template based on provided text description
    :param omr_api: OMR API Instance
    :param template_file_path: Path to template text description
    :param logos_folder: Name of the cloud folder with logo images
    :return: Generation response
    """
    file_name = os.path.basename(template_file_path)
    # upload template text description
    upload_file(template_file_path, file_name)
    
    # provide function parameters
    call_params = OMRFunctionParam(function_param=json.dumps(dict(ExtraStoragePath=logos_folder)), additional_param='')
    result = omr_api.post_run_omr_task(name=file_name,
                                       action_name='GenerateTemplate',
                                       param=call_params)
    return result
Example #3
0
def finalize_template(omr_api, template_id, corrected_template_path):
    """
    Run template finalization
    :param omr_api:  OMR API Instance
    :param template_id: Template id received after template correction
    :param corrected_template_path: Path to corrected template (.omrcr)
    :return: Finalization response
    """
    
    template_file_name = os.path.basename(corrected_template_path)
    # upload corrected template data on cloud
    upload_file(corrected_template_path, template_file_name)
    # provide template id as function parameter
    call_params = OMRFunctionParam(function_param=template_id, additional_param='')
    # call template finalization
    result = omr_api.post_run_omr_task(name=template_file_name,
                                       action_name='FinalizeTemplate',
                                       param=call_params)
    return result
Example #4
0
def recognize_image(omr_api, template_id, image_path):
    """
    Runs mark recognition on image
    :param omr_api: OMR API Instance
    :param template_id: Template ID
    :param image_path: Path to the image
    :return: Recognition response
    """
    image_file_name = os.path.basename(image_path)
    # upload image on cloud
    upload_file(image_path, image_file_name)
    
    # provide template id as function parameter
    call_params = OMRFunctionParam(function_param=template_id, additional_param='')
    
    # call image recognition
    result = omr_api.post_run_omr_task(name=image_file_name,
                                       action_name='RecognizeImage',
                                       param=call_params)
    return result