Пример #1
0
        public static void Run()
        {
            // ExStart:1
            // Instantiate Aspose Storage Cloud API SDK
            StorageApi storageApi = new StorageApi(Common.APP_KEY, Common.APP_SID, Common.BASEPATH);

            // Instantiate Aspose OCR Cloud API SDK
            OcrApi ocrApi = new OcrApi(Common.APP_KEY, Common.APP_SID, Common.BASEPATH);

            // Set the image file name
            String name = "Sampleocr.bmp";

            // Set the language of the document.
            String language = "English";

            // Set X and Y coordinate to recognize text inside..
            int?rectX = 150;
            int?rectY = 100;

            //Set Width and Height to recognize text inside.
            int?rectWidth  = 1000;
            int?rectHeight = 300;

            //Set the spelling correction is used.
            bool?useDefaultDictionaries = true;

            //Set 3rd party cloud storage server (if any)
            String storage = "";
            String folder  = "";

            try
            {
                //upload source file to aspose cloud storage
                storageApi.PutCreate(name, "", "", System.IO.File.ReadAllBytes(Common.GetDataDir() + name));

                // invoke Aspose.OCR Cloud SDK API to extract text and partsinfo from an image
                OCRResponse apiResponse = ocrApi.GetRecognizeDocument(name, language, rectX, rectY, rectWidth, rectHeight, useDefaultDictionaries, storage, folder);

                if (apiResponse != null)
                {
                    Console.WriteLine("Codetext: " + apiResponse.Text + "\n");

                    Console.WriteLine("Extract OCR or HOCR Text from a specific Block, Done!");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("error:" + ex.Message + "\n" + ex.StackTrace);
            }
            // ExEnd:1
        }
Пример #2
0
        static string RecognizeFromStorage(Configuration conf)
        {
            string name = "10.png";

            OcrApi  api     = new OcrApi(conf);
            FileApi fileApi = new FileApi(conf /* or AppSid & AppKey*/);

            fileApi.UploadFile(new UploadFileRequest(name, System.IO.File.OpenRead(name)));

            GetRecognizeDocumentRequest request = new GetRecognizeDocumentRequest(name);
            OCRResponse response = api.GetRecognizeDocument(request);

            return(response.Text);
        }
        public string Convert(Stream file, string fileName, string language)
        {
            LanguageEnum lg = LanguageEnum.English;

            System.Enum.TryParse <LanguageEnum>(language, true, out lg);

            UploadFileRequest uploadFileRequest = new UploadFileRequest()
            {
                path = fileName,
                File = file
            };

            OCRFileApi.UploadFile(uploadFileRequest);

            GetRecognizeDocumentRequest request = new GetRecognizeDocumentRequest(name: fileName, language: lg);
            OCRResponse response = OCRCloudApi.GetRecognizeDocument(request);

            OCRFileApi.DeleteFile(new DeleteFileRequest(path: fileName));

            return(response.Text);
        }
Пример #4
0
        public void TestGetRecognizeDocument()
        {
            OcrApi     target     = new OcrApi(APIKEY, APPSID, BASEPATH);
            StorageApi storageApi = new StorageApi(APIKEY, APPSID, BASEPATH);

            string name                   = "Sampleocr.bmp";
            string language               = "english";
            int?   rectX                  = null;
            int?   rectY                  = null;
            int?   rectWidth              = null;
            int?   rectHeight             = null;
            bool?  useDefaultDictionaries = null;
            string storage                = null;
            string folder                 = null;

            storageApi.PutCreate(name, "", "", System.IO.File.ReadAllBytes("\\temp\\ocr\\resources\\" + name));

            Com.Aspose.OCR.Model.OCRResponse actual;
            actual = target.GetRecognizeDocument(name, language, rectX, rectY, rectWidth, rectHeight, useDefaultDictionaries, storage, folder);

            Assert.AreEqual("200", actual.Code);
            Assert.IsInstanceOfType(new OCRResponse(), actual.GetType());
        }