Beispiel #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
Beispiel #2
0
#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
    response = ocrApi.GetRecognizeDocument(name, language=language,useDefaultDictionaries=useDefaultDictionaries )
    
    if response.Status == 'OK':
        print "Text :: " + response.Text     
        
        print "\n\nExtract OCR or HOCR Text from Images, Done!"
                        
except ApiException as ex:
            print "ApiException:"
            print "Code:" + str(ex.code)
            print "Message:" + ex.message    
#ExEnd:1    
#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;

#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
    response = ocrApi.GetRecognizeDocument(name,language=language,rectX=rectX,rectY=rectY,rectWidth=rectWidth,rectHeight=rectHeight,useDefaultDictionaries=useDefaultDictionaries )
    
    if response.Status == 'OK':
        print "Text :: " + response.Text     
        
        print "\n\nExtract OCR or HOCR Text from a specific Block, Done!"
                        
except ApiException as ex:
            print "ApiException:"
            print "Code:" + str(ex.code)
            print "Message:" + ex.message    
#ExEnd:1