def lambda_handler(base_64_string: str, context): ocr = OCR(debug_mode=False, aws_request_id=context.aws_request_id) (recognized_text, status_code, conf) = ocr.parse_image(base_64_string=base_64_string) return { 'conf': json.dumps(conf), 'text': json.dumps(recognized_text), 'statusCode': json.dumps(status_code) }
def lambda_handler(base_64_string: str, context): ocr = OCR(debug_mode=False, aws_request_id=context.aws_request_id) (status_code, recognized_text, confidence_values) = ocr.parse_image(base_64_string=base_64_string) return { 'statusCode': json.dumps(status_code), 'recognizedText': json.dumps(recognized_text), 'confidenceValues': json.dumps(confidence_values) }
print('=====================================') # Convert file to encoded Base64 string. file_path = test_files_path.format(file_name) with open(file_path, 'rb') as image_file: base_64_string = base64.b64encode(image_file.read()) # Create OCR object. ocr = OCR(debug_mode=True) # Create temp_files directory. os.makedirs(ocr.temp_files_directory_path, exist_ok=True) # Get output. (_, recognized_text, _) = ocr.parse_image(base_64_string=base_64_string) # Delete temp_files directory. shutil.rmtree(ocr.temp_files_directory_path) # Case: test passed. if recognized_text == expected_text: print(test_passed.format(file_name)) # Case: test failed. else: print(test_failed.format(file_name, expected_text, recognized_text)) print('\n\n\n')
# Execute test cases. print('\n') for file_name, expected_text in test_cases: # Convert file to encoded Base64 string. file_path = test_files_path.format(file_name) with open(file_path, 'rb') as image_file: base_64_string = base64.b64encode(image_file.read()) # Create OCR object. ocr = OCR(debug_mode=True) # Create temp_files directory. os.makedirs(ocr.temp_files_directory_path, exist_ok=True) # Get output. (recognized_text, _, _) = ocr.parse_image(base_64_string=base_64_string) # Delete temp_files directory. shutil.rmtree(ocr.temp_files_directory_path) # Case: test passed. if recognized_text == expected_text: print(test_passed.format(file_name)) # Case: test failed. else: print(test_failed.format(file_name, expected_text, recognized_text)) print('\n\n\n')