Translate from C# to AHK complicated?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Albireo
Posts: 1747
Joined: 16 Oct 2013, 13:53

Translate from C# to AHK complicated?

Post by Albireo » 04 Sep 2020, 04:54

Is it complicated to understand / translate this code below from C# to AHK?

Code: Select all

static void ProcessTemplateDotNet() 
{
    string inputFile = @"C:\Temp\Template Samples\w2-example.jpg";
    string templateLib = @"C:\Temp\Template Samples\Templates.tlz";
    string outputFile = @"C:\Temp\Output.xml";  
    int conf = 0;
    int matching = 0;

    if (File.Exists(outputFile))
        File.Delete(outputFile);

    //Initialize Engine
    Engine.Init(null, null);                                    
    //Create a settings collection
    //Load the template library.
    //Load the input file
    using(SettingCollection sett = new SettingCollection())
    using (FormTemplateLibrary formLibrary = new FormTemplateLibrary(templateLib, sett))
    using (ImageFile inputImageFile = 
new ImageFile(inputFile, FILEOPENMODE.IMGF_READ, IMF_FORMAT.FF_SIZE, sett))
    {                
        //Modify any recognition settings                
        sett.DTXTOutputformat = DTXTOUTPUTFORMATS.DTXT_XMLCOORD;
        //Iterate through the pages
        for (int i = 0; i < inputImageFile.PageCount; i++)
        {
            //Load a page from the input file
            using (Page page = new Page(inputImageFile, i, sett))
            {                                              
                FormTemplateCollection templateCollection = null;
                //Pre-process the document (rotate, deskew, etc.)
                page.Preprocess();
                //Find any templates that match thie input page
                MatchingFormTemplate matchingTemplate = 
page.FindFormTemplate(formLibrary, out templateCollection, out conf, out matching);
                //Get detailed information about the match, useful for debugging.
                string findInfo = templateCollection.FindInfo;
                if (matching != 0)
                {
                    //Apply the matching template to the page.
                    page.ApplyFormTemplate(matchingTemplate);
                    //Recognize (OCR) the page.
                    page.Recognize(outputFile);                            
                    //Iterate through the recognized zones
                    foreach (OCRZone zone in page.OCRZones)
                    {
                        Console.WriteLine("Name: {0} \n\rValue: {1}", 
zone.Name, zone.Text);                            
                    }
                }
                //Free the template collection
                if (templateCollection != null)
                    templateCollection.Dispose();
            }
        }
    }
    //Close the engine.
    Engine.ForceQuit();
}

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Translate from C# to AHK complicated?

Post by BoBo » 04 Sep 2020, 05:21

No, for someone who knows how to do it. :yawn:
Yes, for you & me.
Question: what exactly is this code for (let's guess you know it, bc you've selected it for a specific reason!)??

Albireo
Posts: 1747
Joined: 16 Oct 2013, 13:53

Re: Translate from C# to AHK complicated?

Post by Albireo » 04 Sep 2020, 07:31

Right now I'm testing the OCR solution Vis2 - Image to Text OCR () (with tesseract), but does not work flawlessly, (right now)
If I do not manage to translate PDF to text (by myself) with reliable results. The interpretation must be solved in another way.
Hopefully I find a solution (but do not know right now how)

I check if KOFAX has a working solution. The code shows how to programmatically extract data from a template library. (Nuance Omnipage Capture SDK and Nuance Form Template Editor (FTE)) If I not can use their APIs with AHK, their solution is not as interesting.

Most things I understand in the C# code (but there are instructions, I have no idea what these perform)

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Translate from C# to AHK complicated?

Post by BoBo » 04 Sep 2020, 08:13

I'd guess the number of cpp&AHK supporters isn't overwhelming, so getting in touch with people inside :arrow: that forum section might be your last resort. Good luck :)

User avatar
Xtra
Posts: 2744
Joined: 02 Oct 2015, 12:15

Re: Translate from C# to AHK complicated?

Post by Xtra » 04 Sep 2020, 10:31

Albireo wrote:
04 Sep 2020, 07:31
If I do not manage to translate PDF to text (by myself) with reliable results.
If you open the PDF and the text can be selected (contents not an image) and copy paste text out of the PDF then PDF2Text tool will work and be reliable.

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Translate from C# to AHK complicated?

Post by swagfag » 04 Sep 2020, 12:14

why dont u use the apparently available c api instead?
http://csdklab.com/WebHelp/recapi/PLRECOG.html

Albireo
Posts: 1747
Joined: 16 Oct 2013, 13:53

Re: Translate from C# to AHK complicated?

Post by Albireo » 06 Sep 2020, 16:22

Thanks!
Good suggestion, will probably come back, if it becomes relevant for translating C # to AHK (does not seem impossible)
- or can there be complications?

Post Reply

Return to “Ask for Help (v1)”