下面是提交的端到端示例ExtractBarcode请求使用JavaScript (Python)编程语言:
制作和处理LEADTOOLS CloudServices的ExtractBarcode请求结果的简单脚本。#为了运行这个脚本,需要添加以下更改:# 1)将应用程序ID放在appId变量中。# 1)向LEADTOOLS CloudServices执行一个ExtractBarcode请求。成功发出的请求将返回唯一标识符。# 2)然后我们将使用GUID查询服务——如果文件完成处理,主体将包含所有的#请求数据。# 3)我们将获取返回的json数据,解析它,并显示返回的所有信息。这个脚本使用了请求Python库。关于这个库的更多信息可以在这里找到:http://docs.python-requests.org/en/master/ import requests import sys import time servicesUrl = "https://azure.leadtools.com/api/" #应用程序ID。appId = "Replace with Application ID" #应用密码。firstPage = 1 #发送一个-1值将向服务表明文件中其余的页面应该被处理。 lastPage = -1 #A comma separated string of barcode symbologies. Passing an empty string will cause to service to use Popular by default. symbologies = "" # We will be uploading the file via a URl. Files can also be passed by adding a PostFile to the request. Only 1 file will be accepted per request. # The services will use the following priority when determining what a request is trying to do GUID > URL > Request Body Content fileURL = 'http://demo.leadtools.com/images/cloud_samples/barcode_sample.tif' baseRecognitionUrl = '{}Recognition/ExtractBarcode?firstPage={}&lastPage={}&fileurl={}&symbologies={}' formattedRecognitionUrl = baseRecognitionUrl.format( servicesUrl, firstPage, lastPage, fileURL, symbologies) request = requests.post(formattedRecognitionUrl, auth=(appId, password)) # If uploading a file alongside the HTTP request #baseRecognitionUrl ='{}Recognition/ExtractBarcode?firstPage={}&lastPage={}' #formattedRecognitionUrl = baseRecognitionUrl.format( # servicesUrl,firstPage, lastPage) #file = {'file' : open('path/to/file', 'rb')} #request = requests.post( # formattedRecognitionUrl, auth=(appId, password), files = file) if request.status_code != 200: print("Error sending the conversion request") print(request.text) sys.exit() # Grab the GUID from the Request guid = request.text print("Unique ID returned by the services: " + guid + "\n") # Now, we need to Query the results print("Now Querying Results....") baseQueryUrl = '{}Query?id={}' formattedQueryUrl = baseQueryUrl.format(servicesUrl, guid) while True: # Poll the services to determine if the request has finished processing request = requests.post(formattedQueryUrl, auth=(appId, password)) returnedData = request.json() if returnedData['FileStatus'] != 100 and returnedData['FileStatus'] != 123: break time.sleep(5) print("File finished processing with file status: " + str(returnedData['FileStatus'])) if returnedData['FileStatus'] != 200: sys.exit() try: print("Results:") returnedJson = returnedData['RequestData'] for requestObject in returnedJson: print("Service Type: " + requestObject['ServiceType']) if requestObject['ServiceType'] == 'Recognition' and requestObject['RecognitionType'] == 'Barcode': print("Barcode Data:") for barcodeData in requestObject['data']: print("Symbology: " + barcodeData['Symbology']) print("Value: " + barcodeData['Value']) print("Bounds: " + barcodeData['Bounds']) print("Rotation Angle: " + str(barcodeData['RotationAngle'])) print("-------------------------------------------") except Exception as e: print("Failed to Parse JSON") print(str(e))