Ejemplo n.º 1
0
class TestAsposeOcrCloud(unittest.TestCase):
    def setUp(self):

        with open('setup.json') as json_file:
            data = json.load(json_file)

        self.storageApiClient = asposestoragecloud.ApiClient.ApiClient(
            apiKey=str(data['app_key']),
            appSid=str(data['app_sid']),
            debug=True,
            apiServer=str(data['product_uri']))
        self.storageApi = StorageApi(self.storageApiClient)

        self.apiClient = asposeocrcloud.ApiClient.ApiClient(
            apiKey=str(data['app_key']),
            appSid=str(data['app_sid']),
            debug=True,
            apiServer=str(data['product_uri']))
        self.ocrApi = OcrApi(self.apiClient)

        self.output_path = str(data['output_location'])

    def testGetRecognizeDocument(self):

        try:
            name = "Sampleocr.bmp"

            response = self.storageApi.PutCreate(name, './data/' + name)
            response = self.ocrApi.GetRecognizeDocument(name)

            self.assertIsInstance(response, OCRResponse.OCRResponse)
            self.assertEqual(response.Status, 'OK')

        except ApiException as ex:
            print "Exception"
            print "Code: " + str(ex.code)
            print "Mesage: " + ex.message
            raise ex

    def testPostOcrFromUrlOrContent(self):

        try:
            name = "Sampleocr.bmp"

            response = self.ocrApi.PostOcrFromUrlOrContent(file='./data/' +
                                                           name,
                                                           language="english")

            self.assertIsInstance(response, OCRResponse.OCRResponse)
            self.assertEqual(response.Status, 'OK')

        except ApiException as ex:
            print "Exception"
            print "Code: " + str(ex.code)
            print "Mesage: " + ex.message
            raise ex
Ejemplo n.º 2
0
    def setUp(self):

        with open('setup.json') as json_file:
            data = json.load(json_file)

        self.storageApiClient = asposestoragecloud.ApiClient.ApiClient(
            apiKey=str(data['app_key']),
            appSid=str(data['app_sid']),
            debug=True,
            apiServer=str(data['product_uri']))
        self.storageApi = StorageApi(self.storageApiClient)

        self.apiClient = asposeocrcloud.ApiClient.ApiClient(
            apiKey=str(data['app_key']),
            appSid=str(data['app_sid']),
            debug=True,
            apiServer=str(data['product_uri']))
        self.ocrApi = OcrApi(self.apiClient)

        self.output_path = str(data['output_location'])
Ejemplo n.º 3
0
from asposeocrcloud.OcrApi import OcrApi
from asposeocrcloud.OcrApi import ApiException

import ConfigParser

config = ConfigParser.ConfigParser()
config.readfp(open(r'../../data/config.properties'))
apiKey = config.get('AppConfig', 'api_key')
appSid = config.get('AppConfig', 'app_sid')
out_folder = config.get('AppConfig', 'out_folder')
data_folder = "../../data/"  #resouece data folder

#ExStart:1
#Instantiate Aspose.OCR API SDK
api_client = asposeocrcloud.ApiClient.ApiClient(apiKey, appSid, False)
ocrApi = OcrApi(api_client)

#Set the image file url
url = "https://dl.dropboxusercontent.com/s/zj35mqdouoxy3rs/Sampleocr.bmp"

#Set the language of the document
language = 'English'

#Set the spelling correction is used
useDefaultDictionaries = 'true'

try:
    #invoke Aspose.OCR Cloud SDK API to extract image text from file url
    response = ocrApi.PostOcrFromUrlOrContent(
        file=None,
        url=url,
Ejemplo n.º 4
0
config = ConfigParser.ConfigParser()
config.readfp(open(r'../../data/config.properties'))
apiKey = config.get('AppConfig', 'api_key')
appSid = config.get('AppConfig', 'app_sid')
out_folder = config.get('AppConfig', 'out_folder')
data_folder = "../../data/" #resouece data folder

#ExStart:1
#Instantiate Aspose.Storage API SDK
storage_apiClient = asposestoragecloud.ApiClient.ApiClient(apiKey, appSid, False)
storageApi = StorageApi(storage_apiClient)

#Instantiate Aspose.OCR API SDK
api_client = asposeocrcloud.ApiClient.ApiClient(apiKey, appSid, False)
ocrApi = OcrApi(api_client);

#Set the image file name
name = 'Sampleocr.bmp';

#Set the language of the document
language = 'English';

#Set the spelling correction is used
useDefaultDictionaries = 'true';

try:
    #upload file to aspose cloud storage
    response = storageApi.PutCreate(name, data_folder + name)
    
    #invoke Aspose.OCR Cloud SDK API to extract text and partsinfo from an image
config = ConfigParser.ConfigParser()
config.readfp(open(r'../../data/config.properties'))
apiKey = config.get('AppConfig', 'api_key')
appSid = config.get('AppConfig', 'app_sid')
out_folder = config.get('AppConfig', 'out_folder')
data_folder = "../../data/" #resouece data folder

#ExStart:1
#Instantiate Aspose.Storage API SDK
storage_apiClient = asposestoragecloud.ApiClient.ApiClient(apiKey, appSid, False)
storageApi = StorageApi(storage_apiClient)

#Instantiate Aspose.OCR API SDK
api_client = asposeocrcloud.ApiClient.ApiClient(apiKey, appSid, False)
ocrApi = OcrApi(api_client);

#Set the image file name
name = 'Sampleocr.bmp';

#Set the language of the document
language = 'English';

#Set X and Y coordinate to recognize text inside
rectX = 150;
rectY = 100;

#Set Width and Height to recognize text inside
rectWidth = 1000;
rectHeight = 300;