def recognize_from_storage(conf): api = OcrApi(conf) params = Parameters(LanguageGroup.ENGLISH, ResultType.Text, False, False, DSRPipeline.DsrNoFilter, DSRConfidence.Mid, False) res = api.get_recognize_from_storage(params, "file.png") print(res.text)
def recognize_from_content(conf): api = OcrApi(conf) params = Parameters(LanguageGroup.ENGLISH, ResultType.Text, False, False, DSRPipeline.DsrNoFilter, DSRConfidence.Mid, False) res = api.post_recognize_from_content('testdata/5.png', params) print(res.text)
def ocr_send_file(configuration): # Instantiate API Class api = OcrApi(configuration) params = Parameters(LanguageGroup.ENGLISH, ResultType.Text, False, False, DSRPipeline.DsrNoFilter, DSRConfidence.Mid, False) # Send request (Only English language supported for this request type) res = api.post_recognize_from_content(r"..\testdata\de_1.jpg", params) print(res.text)
def recognize_from_url(conf): api = OcrApi(conf) params = Parameters(LanguageGroup.ENGLISH, ResultType.Text, False, False, DSRPipeline.DsrNoFilter, DSRConfidence.Mid, False) res = api.post_recognize_from_url( "https://www.cs.uregina.ca/Links/class-info/425-nova/Lab4/Picts/enhance_text.jpg", params) print(res.text)
def ocr_from_url(configuration): # Instantiate API Class api = OcrApi(configuration) params = Parameters(LanguageGroup.ENGLISH, ResultType.Text, False, False, DSRPipeline.DsrNoFilter, DSRConfidence.Mid, False) # Send request (Only English language supported for this request type) res = api.post_recognize_from_url( "https://upload.wikimedia.org/wikipedia/commons/2/2f/Book_of_Abraham_FirstPage.png", params) print(res.text)
def ocr_from_aspose_storage(configuration): # Instantiate Storage API Class api_storage = asposeocrcloud.api.storage_api.StorageApi(configuration) # Upload file to storage api_storage.upload_file("5.png", r"..\testdata\5.png") params = Parameters(LanguageGroup.ENGLISH, ResultType.Text, False, False, DSRPipeline.DsrNoFilter, DSRConfidence.Mid, False) # Instantiate OCR API Class api_ocr = OcrApi(configuration) # Send request (Only English language supported for this request type) res = api_ocr.get_recognize_from_storage("5.png", params) print(res.text)
def ocr_regions_using_apose_storage(configuration): # image to recognize file_path = r"..\testdata\5.png" # setup regions of image to recognize regions = [ OCRRegion(OCRRect(243, 308, 2095, 964), 0), OCRRegion(OCRRect(240, 1045, 2108, 1826), 1), OCRRegion(OCRRect(237, 1916, 2083, 3180), 2), ] # Set options: Regions, Recognition language and Skew corrector request_data = OCRRequestData(regions=regions, language=LanguageGroup.ENGLISH, make_skew_correct=False) # Instantiate OCR API Class api_ocr = OcrApi(configuration) # Send request res = api_ocr.post_recognize_regions_from_content( request_data, file_path) # type: OcrResponse print(res.text)
def ocr_regions_from_url(configuration): # choose url of image to recognize url = "https://iili.io/JP2HFf.png" # setup regions of image to recognize regions = [ OCRRegion(OCRRect(243, 308, 2095, 964), 0), OCRRegion(OCRRect(240, 1045, 2108, 1826), 1), OCRRegion(OCRRect(237, 1916, 2083, 3180), 2), ] # Set options: Regions, Recognition language and Skew corrector request_data = OCRRequestData(regions=regions, language=LanguageGroup.ENGLISH, make_skew_correct=False) # Instantiate OCR API Class api_ocr = OcrApi(configuration) # Send request res = api_ocr.post_recognize_regions_from_url(request_data, url) # type: OcrResponse print(res.text)
class TestHelper(object): configuration = Configuration( apiKey="", appSid="", basePath="https://api.aspose.cloud/v3.0", authPath="https://api.aspose.cloud/connect/token", debug=False) if not configuration.api_key or not configuration.app_sid: raise Exception( "Setup AppSID and AppKEY in TestsHelper -> configuration.") client = Client(configuration) ocr = OcrApi(client) storage = StorageApi(client) current_dir = os.path.dirname(__file__) parent_dir = os.path.dirname(current_dir) test_src = os.path.join(parent_dir, 'testdata') test_dst = os.path.join(parent_dir, 'testresult') folder = 'OcrTestDoc' @classmethod def get_folder(cls): return cls.folder @classmethod def get_local_folder(cls): return cls.test_src @classmethod def get_local_dest_folder(cls): return cls.test_dst @classmethod def upload_file(cls, file_name): res = cls.storage.upload_file(os.path.join(cls.folder, file_name), os.path.join(cls.test_src, file_name)) return res @classmethod def download_file(cls, path): response = cls.storage.download_file(path) return response @classmethod def get_file_size(cls, file_name): return os.path.getsize(os.path.join(cls.test_src, file_name)) @classmethod def move_file(cls, src_file, dst_file): if os.path.isfile(src_file): copy2(src_file, dst_file) os.remove(src_file)
def ocr_regions_of_local_file(configuration): # Instantiate Storage API Class api_storage = asposeocrcloud.api.storage_api.StorageApi(configuration) # Upload file to storage api_storage.upload_file("5.png", r"..\testdata\5.png") # setup regions of image to recognize regions = [ OCRRegion(OCRRect(243, 308, 2095, 964), 0), OCRRegion(OCRRect(240, 1045, 2108, 1826), 1), OCRRegion(OCRRect(237, 1916, 2083, 3180), 2), ] # Set options: Regions, Recognition language and Skew corrector request_data = OCRRequestDataStorage(regions=regions, language=LanguageGroup.ENGLISH, make_skew_correct=False, file_name="5.png") # Instantiate OCR API Class api_ocr = OcrApi(configuration) # Send request res = api_ocr.post_recognize_regions_from_storage( request_data) # type: OcrResponse print(res.text)