How to exclude pages from recognition in FlexiCapture 12 Distributed?

Question

How to exclude pages from recognition?

Answer

  1. Advanced workflow is required.
  2. Create an automatic script stage before recognition for batch processing. This script should remove the pages, save them as regular files in a temporary directory, save the name of the temp files and their amount:

    int from=1; // first page is 0
    int to=1;
    Random r = new Random();
    string fileName = "d://temp"+r.Next(1000000).ToString()+"_";

    //let's save the values for restoring
    Batch.Properties.Set("from",from);
    Batch.Properties.Set("to",count);
    Batch.Properties.Set("fileName",fileName);

    //save file and remove it from recognition
    for(int i=from;i<count&&i<to;i++){
    Documents[i].SaveAs(fileName + i.ToString() + ".jpg");
    Batch.DeleteDocument(Documents[i]);
    }

     

  3. Create additional automatic stage after recognition. Here you just need to load saved pages into an already recognized document:

    for(int i=Batch.Properties.Get("from"); i<Batch.Properties.Get("to"); i++){
    string fn = Batch.Properties.Get("fileName") + i.ToString() + ".jpg";
    IEditablePictureObject img = FCTools.LoadImage(fn);
    Batch.CreatePageFromImage(img,Documents[0],-1);
    }

     

  4. You can see that the second page is a part of the document. The counter in the License Manager has been decreased by one.

Additional information

Using scripts in ABBYY FlexiCapture
Workflow setup

Was this article helpful?

2 out of 2 found this helpful

Have more questions? Submit a request

Comments

1 comment

  • Avatar

    Nikita Shevchenko

    You can use Attachments instead of disk storage. Please use the next code as an example to skip recognition for some particular pages. In the next example, I have sent two images and the second one is skipped. 

    Perhaps we can skip converting to Base64 and attach an image directly. 

    //before recognition batch processing script
    using System;
    using System.Drawing;
    using System.IO;
    using System.Drawing.Imaging;

    //convert to base64
    ImageCodecInfo myImageCodecInfo;
    Encoder myEncoder;
    EncoderParameter myEncoderParameter;
    EncoderParameters myEncoderParameters;

    string mimeType = "image/jpeg";
    int j;
    ImageCodecInfo[] encoders;
    encoders = ImageCodecInfo.GetImageEncoders();
    for(j = 0; j < encoders.Length; ++j)
    {
    if(encoders[j].MimeType == mimeType){
        myImageCodecInfo =  encoders[j];
        break;
        }
    }

    myEncoder = Encoder.Quality;
    myEncoderParameters = new EncoderParameters(1);
    myEncoderParameter = new EncoderParameter(myEncoder, 25L);
    myEncoderParameters.Param[0] = myEncoderParameter;

    try{
    System.Drawing.Image image = System.Drawing.Image.FromHbitmap((System.IntPtr)Documents[1].Pages[0].Picture.Handle, (System.IntPtr)Documents[1].Pages[0].Picture.hPal);

    FCTools.ShowMessage("Image has been created:"+(image==null).ToString());
    {
    using (MemoryStream m = new MemoryStream())
    {
    FCTools.ShowMessage("Saving stream");
    //image.Save(m, image.RawFormat,myEncoderParameters);
    image.Save(m, System.Drawing.Imaging.ImageFormat.Jpeg);
    FCTools.ShowMessage("saved");
    byte[] imageBytes = m.ToArray();
    FCTools.ShowMessage("array");
    // Convert byte[] to Base64 String
    string base64String = Convert.ToBase64String(imageBytes);
    FCTools.ShowMessage("string"+base64String);

    //add an attachment
    var t = Documents[0].Attachments.AddNew("image");
    t.AsString = base64String;
    t.UploadAttachment();

        }
    }
    Batch.DeleteDocument(Documents[1]);
    }catch(Exception ex){FCTools.ShowMessage("Exception "+ex.Message);}


    //after Recognition batch processing script
    using System;
    using System.Drawing;
    using System.IO;

    //read an attachment
    string base64String = Documents[0].Attachments.Get("image").AsString;
    File.WriteAllText("d:/after",base64String);
    Bitmap bmpReturn = null;
                //Convert Base64 string to byte[]
                FCTools.ShowMessage("converting bytes");
                byte[] byteBuffer = Convert.FromBase64String(base64String);
                MemoryStream memoryStream = new MemoryStream(byteBuffer);

                memoryStream.Position = 0;
    FCTools.ShowMessage("Converting stream");
                bmpReturn = (Bitmap)Bitmap.FromStream(memoryStream);
                FCTools.ShowMessage("creating picture");
      IPictureObject po = FCTools.PictureFromHBitmap( bmpReturn.GetHbitmap().ToInt32() );
    FCTools.ShowMessage("adding image");
    Batch.CreatePageFromImage(po,Documents[Documents.Count-1],-1);

                memoryStream.Close();
                memoryStream = null;
                byteBuffer = null;
    0

Please sign in to leave a comment.