/// <summary> /// Calls Generate template function and processes result /// </summary> /// <param name="descriptionFileName">Name of the description file</param> /// <param name="descriptionData">Template description data in bytes</param> /// <param name="imagesPath">Cloud storage folder where images are located</param> /// <param name="additionalParams">Internal parameters</param> /// <returns>Generated content with template and image</returns> public static TemplateGenerationContent GenerateTemplate(string descriptionFileName, byte[] descriptionData, string imagesPath, string additionalParams) { imagesPath = @"{ ""ExtraStoragePath"":""" + imagesPath + @"""}"; OMRResponse response = RunOmrTask(OmrFunctions.GenerateTemplate, descriptionFileName, descriptionData, imagesPath, false, false, additionalParams); OmrResponseContent responseResult = response.Payload.Result; CheckTaskResult(response.Payload.Result); byte[] template = responseResult.ResponseFiles.First(x => x.Name.Contains(".omr")).Data; byte[] imageFile = responseResult.ResponseFiles.First(x => x.Name.Contains(".png")).Data; TemplateViewModel templateViewModel = TemplateSerializer.JsonToTemplate(Encoding.UTF8.GetString(template)); templateViewModel.ImageFileFormat = ".png"; TemplateGenerationContent generationContent = new TemplateGenerationContent(); generationContent.ImageData = imageFile; generationContent.Template = templateViewModel; return(generationContent); }
/// <summary> /// Performs template correction /// </summary> /// <param name="imageName">The name of the template image</param> /// <param name="imageData">The template image data</param> /// <param name="templateData">The template data</param> /// <param name="wasUploaded">Indicates if image was already uploaded on cloud</param> /// <param name="additionalParams">The additional parameters</param> /// <returns>Corrected template</returns> public static TemplateViewModel CorrectTemplate(string imageName, byte[] imageData, string templateData, bool wasUploaded, string additionalParams) { OMRResponse response = RunOmrTask("CorrectTemplate", imageName, imageData, templateData, wasUploaded, false, additionalParams); OmrResponseContent responseResult = response.Payload.Result; CheckTaskResult(response.Payload.Result); byte[] correctedTemplateData = responseResult.ResponseFiles .First(x => x.Name.Equals("corrected_template.dat")) .Data; TemplateViewModel templateViewModel = TemplateSerializer.JsonToTemplate(Encoding.UTF8.GetString(correctedTemplateData)); templateViewModel.TemplateId = responseResult.TemplateId; return(templateViewModel); }
/// <summary> /// Performs template correction /// </summary> /// <param name="imageName">The name of the template image</param> /// <param name="imageData">The template image data</param> /// <param name="templateData">The template data</param> /// <param name="wasUploaded">Indicates if image was already uploaded on cloud</param> /// <param name="additionalParams">The additional parameters</param> /// <returns>Corrected template</returns> public static TemplateViewModel CorrectTemplate(string imageName, byte[] imageData, string templateData, bool wasUploaded, string additionalParams) { string packedTemplate = PackTemplate(imageName, templateData); OmrResponse response = RunOmrTask(OmrFunctions.CorrectTemplate, imageName, imageData, packedTemplate, wasUploaded, false, additionalParams); OmrResponseContent responseResult = response.Payload.Result; CheckTaskResult(response.Payload.Result); byte[] correctedTemplateData = responseResult.ResponseFiles .First(x => x.Name.Contains(".omrcr")) .Data; TemplateViewModel templateViewModel = TemplateSerializer.JsonToTemplate(Encoding.UTF8.GetString(correctedTemplateData)); templateViewModel.TemplateId = responseResult.TemplateId; return(templateViewModel); }