Hi Team,
In the below code output.RecognitionText become Empty post compression. Can you pls tell what is the issue with the below code
static byte[] Decompress(MemoryStream InputMemStream)
{
try
{
InputMemStream.Position = 0;
using (var outputStream = new MemoryStream())
{
using (var decompressStream = new BrotliStream(InputMemStream, CompressionMode.Decompress))
{
decompressStream.CopyTo(outputStream);
}
return outputStream.ToArray();
}
}
catch (Exception ex)
{
throw new Exception("--> at Decompress() " + ex.Message + " StackTrace " + ex.StackTrace + ex?.InnerException?.Message);
}
}
static byte[] Compress(byte[] bytes)
{
using (var memoryStream = new MemoryStream())
{
using (var brotliStream = new BrotliStream(memoryStream, CompressionLevel.Fastest))
{
brotliStream.Write(bytes, 0, bytes.Length);
}
return memoryStream.ToArray();
}
}
public static void CompressionText(string path = "")
{
RecognitionSettings drsMultiplePage = new()
{
AllowedCharacters = CharactersAllowedType.ALL,
LinesFiltration = true,
UpscaleSmallFont = true,
DetectAreasMode = DetectAreasMode.COMBINE,
ThreadsCount = 0,
};
AsposeOcr api = new AsposeOcr();
License lic = new License();
lic.SetLicense("Aspose.Total.NET.lic");
string Filename = "2pagetiff.tiff";
string imgPath = @"C:\\Users\\gpatil\\Downloads\\" + Filename;
PreprocessingFilter pp = new PreprocessingFilter();
OcrInput ocrInput = new OcrInput(InputType.TIFF, pp);
ocrInput.Add(imgPath);
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
List<RecognitionResult> result = new List<RecognitionResult>();
try
{
result = api.Recognize(ocrInput, drsMultiplePage);
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
string inputStr = JsonConvert.SerializeObject(result);
string strResult = string.Empty;
byte[] inputBytes = Encoding.UTF8.GetBytes(inputStr);
using (MemoryStream msstream = new MemoryStream(Compress(inputBytes)))
{
strResult = Encoding.UTF8.GetString(Decompress(msstream));
var output = JsonConvert.DeserializeObject<List<RecognitionResult>>(strResult);
}
}