Exemplo n.º 1
0
        public OrionRecognize()
        {
            // TestDirectCallsToDLL(); //minimal code to demonstrate how to use DLL directly, without COM

            //it is a good idea to create NSOCR instance here instead of creting it in the same line with "NsOCR" definition
            //this way we can handle possible errors if NSOCR is not installed
            try
            {
                NsOCR = new NSOCRLib.NSOCRClass();
            }
            catch (Exception exc) //some error
            {
                string msg = "Cannot create NSOCR COM object instance. Possible reasons:\r\n - NSOCR.dll is missed.\r\n - NSOCR.dll was not registered with Regsvr32.\r\n - NSOCR.dll is x32 but this application is x64.\r\n";
                msg = msg + "\r\n Exception message:\r\n\r\n" + exc.Message;
                System.Windows.Forms.MessageBox.Show(msg);
                //Close();
                return;
            }

            // gr = PicBox.CreateGraphics();

            Inited = true; //NSOCR instance created successfully

            //get NSOCR version
            string val;

            NsOCR.Engine_GetVersion(out val);
            //Text = Text + " [ NSOCR version: " + val + " ] ";

            //init engine and create ocr-related objects
            if (true /*false*/) //change to "false" to reduce code and initialize engine + create main objects in one line
            {
                NsOCR.Engine_Initialize();
                NsOCR.Cfg_Create(out CfgObj);
                //load options, if path not specified, folder with NSOCR.dll will be checked
                NsOCR.Cfg_LoadOptions(CfgObj, "Config.dat");
                NsOCR.Ocr_Create(CfgObj, out OcrObj);
                NsOCR.Img_Create(OcrObj, out ImgObj);
            }
            else //do the same in one line
            {
                NsOCR.Engine_InitializeAdvanced(out CfgObj, out OcrObj, out ImgObj);
            }

            NsOCR.Scan_Create(CfgObj, out ScanObj);

            //bkRecognize.Enabled = false;

            NoEvent = true;
            //cbScale.SelectedIndex = 0;
            NoEvent = false;
            //bkSave.Enabled = false;

            //copy some settings to GUI
            //if (NsOCR.Cfg_GetOption(CfgObj, TNSOCR.BT_DEFAULT, "ImgAlizer/AutoScale", out val) < TNSOCR.ERROR_FIRST)
            //    cbScale.Enabled = (val == "1");

            this.ListZoneName = new List <OrionRecognizeZoneDetail>();
        }