Example #1
0
        public void AddFromPageOrc(string m_FileName)
        {
            string ext = Path.GetExtension(m_FileName);

            m_strPath = m_FileName;
            int pageSelectIndex = 0;

            m_PageOld = SmartOcrSdkExports.OCR_GetPageCount();
            if (m_PageOld > m_Page)
            {
                for (int i = m_Page; i < m_PageOld; i++)
                {
                    var nPageIndex = m_Page;
                    SmartOcrSdkExports.OCR_RemovePage(nPageIndex);
                }
                lstLoadedImages.Items.Clear();
            }
            if (ext == ".pdf")
            {
                SmartOcrSdkExports.OCR_AddPagesFromPDF(m_FileName, null, IntPtr.Zero);
            }
            else
            {
                SmartOcrSdkExports.OCR_AddPageFromImage(m_FileName);
            }
            int nPageCount = SmartOcrSdkExports.OCR_GetPageCount() - m_Page;
            int index      = lstLoadedImages.Items.Count;

            if (nPageCount > 1)
            {
                for (int i = 0; i < nPageCount; i++)
                {
                    pageSelectIndex++;
                    string filePath = "";
                    filePath = m_FileName + "_page" + pageSelectIndex;
                    lstLoadedImages.Items.Add(filePath);
                }
            }
            else
            {
                lstLoadedImages.Items.Add(m_FileName);
            }
            // Automatically select the first item
            if (lstLoadedImages.SelectedItem == null)
            {
                lstLoadedImages.SelectedIndex = 0;
            }
        }
Example #2
0
        void btnChooseFile_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                string ext             = Path.GetExtension(openFileDialog.FileName);
                string fileName        = openFileDialog.FileName;
                int    pageSelectIndex = 0;
                int    nPageCount_1    = SmartOcrSdkExports.OCR_GetPageCount();
                if (ext == ".pdf")
                {
                    SmartOcrSdkExports.OCR_AddPagesFromPDF(fileName, null, IntPtr.Zero);
                }
                else
                {
                    SmartOcrSdkExports.OCR_AddPageFromImage(fileName);
                }
                int nPageCount = SmartOcrSdkExports.OCR_GetPageCount() - nPageCount_1;
                int index      = lstLoadedImages.Items.Count;

                if (nPageCount > 1)
                {
                    for (int i = 0; i < nPageCount; i++)
                    {
                        pageSelectIndex++;
                        string filePath = "";
                        filePath = fileName + "_page" + pageSelectIndex;
                        lstLoadedImages.Items.Add(filePath);
                    }
                }
                else
                {
                    lstLoadedImages.Items.Add(fileName);
                }
                // Automatically select the first item
                if (lstLoadedImages.SelectedItem == null)
                {
                    lstLoadedImages.SelectedIndex = 0;
                }
                else
                {
                    lstLoadedImages.SelectedIndex = lstLoadedImages.Items.Count - nPageCount;
                }
            }
        }
Example #3
0
        private void btnLoad_Click(object sender, EventArgs e)
        {
            const string strFilters = "*.png;*.bmp;*.tif;*.tiff;*.jpg;*.jpeg;*.gif";

            string[] arrFilters = strFilters.Split(';');
            foreach (string strFilter in arrFilters)
            {
                // Get files for each filter
                string[] arrImgFiles = Directory.GetFiles(m_strModulePath + "\\Test_Images", strFilter);

                // Load files
                foreach (string strImg in arrImgFiles)
                {
                    #region Tuan
                    // OCR_AddPageFromImage_W
                    // DeleteAllRegionsInPage  ( int  nPageIndex )

                    //   OCR_DeleteRegionInPage  ( int  nPageIndex,  int  nRegionIndex  )   : Xóa 1 vùng cho 1 trang cụ thể

                    //ExternalGetRecognizedText

                    //OCR_LoadRegionTemplate_A

                    //OCR_RecognizeRegions

                    // OCR_SaveRegionTemplate_W
                    #endregion

                    int res = SmartOcrSdkExports.OCR_AddPageFromImage(strImg);
                    // Add to the list only if we successfully loaded the image
                    if (res != SmartOcrSdkExports.RES_ERROR)
                    {
                        lstLoadedImages.Items.Add(strImg);

                        // Automatically select the first item
                        if (lstLoadedImages.SelectedItem == null)
                        {
                            lstLoadedImages.SelectedIndex = 0;
                        }
                    }
                }
            }

            if (lstLoadedImages.SelectedItem == null)
            {
                MessageBox.Show("Could not find the test images.\n" +
                                "The demo application searches for test images in \"Test_Images\" folder.\n" +
                                "This folder must be located in the same directory with the application.");
            }
            #region
            // Demo: Scan
            // - Init scan, should be called only once
            // SmartOcrSdkExports.OCR_InitScan();
            //

            /* Additional scan tune if required
             * int len = SmartOcrSdkExports.OCR_GetScanners(null, 0);
             * if (len > 0)
             * {
             *  StringBuilder sb = new StringBuilder(len);
             *  SmartOcrSdkExports.OCR_GetScanners(sb, len);
             *  string[] arrScanners = sb.ToString().Replace("\r", "").Split('\n');
             *  if(arrScanners.Length > 0)
             *      SmartOcrSdkExports.OCR_SetActiveScanner(arrScanners[0]);
             * }
             */
            // - Perform scan (async)
            // SmartOcrSdkExports.OCR_PerformScan(new OcrScanCallbackDelegate(OcrScanCallback), 0, IntPtr.Zero);
            #endregion
        }