Skip to content

Commit ed4a2c6

Browse files
committed
Add ScanBarcode endpoint
1 parent 51f889c commit ed4a2c6

File tree

11 files changed

+352
-13
lines changed

11 files changed

+352
-13
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ Class | Method | HTTP request | Description
170170
*BarcodeApi* | [**putBarcodeGenerateFile**](docs/BarcodeApi.md#putBarcodeGenerateFile) | **PUT** /barcode/{name}/generate | Generate barcode and save on server (from query params or from file with json or xml content)
171171
*BarcodeApi* | [**putBarcodeRecognizeFromBody**](docs/BarcodeApi.md#putBarcodeRecognizeFromBody) | **PUT** /barcode/{name}/recognize | Recognition of a barcode from file on server with parameters in body.
172172
*BarcodeApi* | [**putGenerateMultiple**](docs/BarcodeApi.md#putGenerateMultiple) | **PUT** /barcode/{name}/generateMultiple | Generate image with multiple barcodes and put new file on server
173+
*BarcodeApi* | [**scanBarcode**](docs/BarcodeApi.md#scanBarcode) | **POST** /barcode/scan | Quickly scan a barcode from an image.
173174
*FileApi* | [**copyFile**](docs/FileApi.md#copyFile) | **PUT** /barcode/storage/file/copy/{srcPath} | Copy file
174175
*FileApi* | [**deleteFile**](docs/FileApi.md#deleteFile) | **DELETE** /barcode/storage/file/{path} | Delete file
175176
*FileApi* | [**downloadFile**](docs/FileApi.md#downloadFile) | **GET** /barcode/storage/file/{path} | Download file

docs/BarcodeApi.md

+53-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Method | HTTP request | Description
1111
[**putBarcodeGenerateFile**](BarcodeApi.md#putBarcodeGenerateFile) | **PUT** /barcode/{name}/generate | Generate barcode and save on server (from query params or from file with json or xml content)
1212
[**putBarcodeRecognizeFromBody**](BarcodeApi.md#putBarcodeRecognizeFromBody) | **PUT** /barcode/{name}/recognize | Recognition of a barcode from file on server with parameters in body.
1313
[**putGenerateMultiple**](BarcodeApi.md#putGenerateMultiple) | **PUT** /barcode/{name}/generateMultiple | Generate image with multiple barcodes and put new file on server
14+
[**scanBarcode**](BarcodeApi.md#scanBarcode) | **POST** /barcode/scan | Quickly scan a barcode from an image.
1415

1516
## getBarcodeGenerate
1617

@@ -170,7 +171,7 @@ Name | Type | Description | Notes
170171
**allowAdditionalRestorations** | **Boolean**| Allows engine using additional image restorations to recognize corrupted barcodes. At this time, it is used only in MicroPdf417 barcode type. Default value: False. | [optional]
171172
**regionLikelihoodThresholdPercent** | **Double**| Sets threshold for detected regions that may contain barcodes. Value 0.7 means that bottom 70% of possible regions are filtered out and not processed further. Region likelihood threshold must be between [0.05, 0.9] Use high values for clear images with few barcodes. Use low values for images with many barcodes or for noisy images. Low value may lead to a bigger recognition time. | [optional]
172173
**scanWindowSizes** | **List<Integer>**| Scan window sizes in pixels. Allowed sizes are 10, 15, 20, 25, 30. Scanning with small window size takes more time and provides more accuracy but may fail in detecting very big barcodes. Combining of several window sizes can improve detection quality. | [optional]
173-
**similarity** | **Double**| Similarity coefficient depends on how homogeneous barcodes are. Use high value for for clear barcodes. Use low values to detect barcodes that ara partly damaged or not lighten evenly. Similarity coefficient must be between [0.5, 0.9] | [optional]
174+
**similarity** | **Double**| Similarity coefficient depends on how homogeneous barcodes are. Use high value for clear barcodes. Use low values to detect barcodes that ara partly damaged or not lighten evenly. Similarity coefficient must be between [0.5, 0.9] | [optional]
174175
**skipDiagonalSearch** | **Boolean**| Allows detector to skip search for diagonal barcodes. Setting it to false will increase detection time but allow to find diagonal barcodes that can be missed otherwise. Enabling of diagonal search leads to a bigger detection time. | [optional]
175176
**readTinyBarcodes** | **Boolean**| Allows engine to recognize tiny barcodes on large images. Ignored if AllowIncorrectBarcodes is set to True. Default value: False. | [optional]
176177
**australianPostEncodingTable** | **String**| Interpreting Type for the Customer Information of AustralianPost BarCode.Default is CustomerInformationInterpretingType.Other. | [optional] [enum: CTable, NTable, Other]
@@ -254,7 +255,7 @@ Name | Type | Description | Notes
254255
**allowAdditionalRestorations** | **Boolean**| Allows engine using additional image restorations to recognize corrupted barcodes. At this time, it is used only in MicroPdf417 barcode type. Default value: False. | [optional]
255256
**regionLikelihoodThresholdPercent** | **Double**| Sets threshold for detected regions that may contain barcodes. Value 0.7 means that bottom 70% of possible regions are filtered out and not processed further. Region likelihood threshold must be between [0.05, 0.9] Use high values for clear images with few barcodes. Use low values for images with many barcodes or for noisy images. Low value may lead to a bigger recognition time. | [optional]
256257
**scanWindowSizes** | **List<Integer>**| Scan window sizes in pixels. Allowed sizes are 10, 15, 20, 25, 30. Scanning with small window size takes more time and provides more accuracy but may fail in detecting very big barcodes. Combining of several window sizes can improve detection quality. | [optional]
257-
**similarity** | **Double**| Similarity coefficient depends on how homogeneous barcodes are. Use high value for for clear barcodes. Use low values to detect barcodes that ara partly damaged or not lighten evenly. Similarity coefficient must be between [0.5, 0.9] | [optional]
258+
**similarity** | **Double**| Similarity coefficient depends on how homogeneous barcodes are. Use high value for clear barcodes. Use low values to detect barcodes that ara partly damaged or not lighten evenly. Similarity coefficient must be between [0.5, 0.9] | [optional]
258259
**skipDiagonalSearch** | **Boolean**| Allows detector to skip search for diagonal barcodes. Setting it to false will increase detection time but allow to find diagonal barcodes that can be missed otherwise. Enabling of diagonal search leads to a bigger detection time. | [optional]
259260
**readTinyBarcodes** | **Boolean**| Allows engine to recognize tiny barcodes on large images. Ignored if AllowIncorrectBarcodes is set to True. Default value: False. | [optional]
260261
**australianPostEncodingTable** | **String**| Interpreting Type for the Customer Information of AustralianPost BarCode.Default is CustomerInformationInterpretingType.Other. | [optional] [enum: CTable, NTable, Other]
@@ -509,3 +510,53 @@ Name | Type | Description | Notes
509510

510511
[**ResultImageInfo**](ResultImageInfo.md)
511512

513+
## scanBarcode
514+
515+
> BarcodeResponseList scanBarcode(imageFile, decodeTypes, timeout)
516+
517+
Quickly scan a barcode from an image.
518+
519+
### scanBarcode example
520+
521+
```java
522+
// Import classes:
523+
import com.aspose.barcode.cloud.ApiClient;
524+
import com.aspose.barcode.cloud.ApiException;
525+
import com.aspose.barcode.cloud.Configuration;
526+
import com.aspose.barcode.cloud.auth.*;
527+
import com.aspose.barcode.cloud.api.BarcodeApi;
528+
529+
public class Main {
530+
531+
public static void main(String[] args) {
532+
533+
ApiClient client = new ApiClient(
534+
"Client Id from https://dashboard.aspose.cloud/applications",
535+
"Client Secret from https://dashboard.aspose.cloud/applications"
536+
);
537+
538+
BarcodeApi api = new BarcodeApi(client);
539+
File imageFile = new File("/path/to/file.txt"); // File | Image as file
540+
try {
541+
BarcodeResponseList result = api.scanBarcode(imageFile);
542+
System.out.println(result);
543+
} catch (ApiException e) {
544+
System.err.println("Exception when calling BarcodeApi.scanBarcode");
545+
e.printStackTrace();
546+
}
547+
}
548+
}
549+
```
550+
551+
### scanBarcode parameters
552+
553+
Name | Type | Description | Notes
554+
---- | ---- | ------------ | -----
555+
**imageFile** | **File**| Image as file |
556+
**decodeTypes** | [**List<DecodeBarcodeType>**](DecodeBarcodeType.md)| Types of barcode to recognize | [optional]
557+
**timeout** | **Integer**| Timeout of recognition process in milliseconds. Default value is 15_000 (15 seconds). Maximum value is 30_000 (1/2 minute). In case of a timeout RequestTimeout (408) status will be returned. Try reducing the image size to avoid timeout. | [optional]
558+
559+
### scanBarcode return type
560+
561+
[**BarcodeResponseList**](BarcodeResponseList.md)
562+

docs/ReaderParams.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Name | Type | Description | Notes
3535
**allowAdditionalRestorations** | **Boolean** | Allows engine using additional image restorations to recognize corrupted barcodes. At this time, it is used only in MicroPdf417 barcode type. Default value: False. | [optional]
3636
**regionLikelihoodThresholdPercent** | **Double** | Sets threshold for detected regions that may contain barcodes. Value 0.7 means that bottom 70% of possible regions are filtered out and not processed further. Region likelihood threshold must be between [0.05, 0.9] Use high values for clear images with few barcodes. Use low values for images with many barcodes or for noisy images. Low value may lead to a bigger recognition time. | [optional]
3737
**scanWindowSizes** | **List<Integer>** | Scan window sizes in pixels. Allowed sizes are 10, 15, 20, 25, 30. Scanning with small window size takes more time and provides more accuracy but may fail in detecting very big barcodes. Combining of several window sizes can improve detection quality. | [optional]
38-
**similarity** | **Double** | Similarity coefficient depends on how homogeneous barcodes are. Use high value for for clear barcodes. Use low values to detect barcodes that ara partly damaged or not lighten evenly. Similarity coefficient must be between [0.5, 0.9] | [optional]
38+
**similarity** | **Double** | Similarity coefficient depends on how homogeneous barcodes are. Use high value for clear barcodes. Use low values to detect barcodes that ara partly damaged or not lighten evenly. Similarity coefficient must be between [0.5, 0.9] | [optional]
3939
**skipDiagonalSearch** | **Boolean** | Allows detector to skip search for diagonal barcodes. Setting it to false will increase detection time but allow to find diagonal barcodes that can be missed otherwise. Enabling of diagonal search leads to a bigger detection time. | [optional]
4040
**readTinyBarcodes** | **Boolean** | Allows engine to recognize tiny barcodes on large images. Ignored if AllowIncorrectBarcodes is set to True. Default value: False. | [optional]
4141
**australianPostEncodingTable** | [**CustomerInformationInterpretingType**](CustomerInformationInterpretingType.md) | Interpreting Type for the Customer Information of AustralianPost BarCode.Default is CustomerInformationInterpretingType.Other. | [optional]

src/main/java/com/aspose/barcode/cloud/ApiClient.java

+14-3
Original file line numberDiff line numberDiff line change
@@ -894,8 +894,9 @@ public RequestBody buildRequestBodyFormEncoding(Map<String, Object> formParams)
894894
public RequestBody buildRequestBodyMultipart(Map<String, Object> formParams) {
895895
MultipartBuilder mpBuilder = new MultipartBuilder().type(MultipartBuilder.FORM);
896896
for (Entry<String, Object> param : formParams.entrySet()) {
897-
if (param.getValue() instanceof File) {
898-
File file = (File) param.getValue();
897+
Object paramValue = param.getValue();
898+
if (paramValue instanceof File) {
899+
File file = (File) paramValue;
899900
Headers partHeaders =
900901
Headers.of(
901902
"Content-Disposition",
@@ -906,13 +907,23 @@ public RequestBody buildRequestBodyMultipart(Map<String, Object> formParams) {
906907
+ "\"");
907908
MediaType mediaType = MediaType.parse(guessContentTypeFromFile(file));
908909
mpBuilder.addPart(partHeaders, RequestBody.create(mediaType, file));
910+
} else if (paramValue instanceof Collection) {
911+
Collection<Object> collection = (Collection<Object>) paramValue;
912+
for (Object item : collection) {
913+
Headers partHeaders =
914+
Headers.of(
915+
"Content-Disposition",
916+
"form-data; name=\"" + param.getKey() + "\"");
917+
mpBuilder.addPart(
918+
partHeaders, RequestBody.create(null, parameterToString(item)));
919+
}
909920
} else {
910921
Headers partHeaders =
911922
Headers.of(
912923
"Content-Disposition",
913924
"form-data; name=\"" + param.getKey() + "\"");
914925
mpBuilder.addPart(
915-
partHeaders, RequestBody.create(null, parameterToString(param.getValue())));
926+
partHeaders, RequestBody.create(null, parameterToString(paramValue)));
916927
}
917928
}
918929
return mpBuilder.build();

src/main/java/com/aspose/barcode/cloud/api/BarcodeApi.java

+169
Original file line numberDiff line numberDiff line change
@@ -1949,4 +1949,173 @@ public void onRequestProgress(
19491949
apiClient.executeAsync(call, returnType, callback);
19501950
return call;
19511951
}
1952+
1953+
/**
1954+
* Build call for scanBarcode
1955+
*
1956+
* @param request See {@link ScanBarcodeRequest}
1957+
* @param progressListener Progress listener
1958+
* @param progressRequestListener Progress request listener
1959+
* @return Call to execute
1960+
* @throws ApiException If fail to serialize the request body object
1961+
*/
1962+
@SuppressWarnings("removal")
1963+
protected com.squareup.okhttp.Call scanBarcodeCall(
1964+
ScanBarcodeRequest request,
1965+
final ProgressResponseBody.ProgressListener progressListener,
1966+
final ProgressRequestBody.ProgressRequestListener progressRequestListener)
1967+
throws ApiException {
1968+
Object postBody = null;
1969+
1970+
// create path and map variables
1971+
String path = "/barcode/scan";
1972+
1973+
List<Pair> queryParams = new ArrayList<>();
1974+
List<Pair> collectionQueryParams = new ArrayList<>();
1975+
Map<String, String> headerParams = new HashMap<>();
1976+
1977+
Map<String, Object> formParams = new HashMap<>();
1978+
if (request.imageFile != null) {
1979+
formParams.put("imageFile", request.imageFile);
1980+
}
1981+
1982+
if (request.decodeTypes != null) {
1983+
formParams.put("decodeTypes", request.decodeTypes);
1984+
}
1985+
1986+
if (request.timeout != null) {
1987+
formParams.put("timeout", request.timeout);
1988+
}
1989+
1990+
final String[] accepts = {"application/json"};
1991+
final String accept = apiClient.selectHeaderAccept(accepts);
1992+
if (accept != null) {
1993+
headerParams.put("Accept", accept);
1994+
}
1995+
1996+
final String[] contentTypes = {"multipart/form-data"};
1997+
final String contentType = apiClient.selectHeaderContentType(contentTypes);
1998+
headerParams.put("Content-Type", contentType);
1999+
2000+
if (progressListener != null) {
2001+
apiClient
2002+
.getHttpClient()
2003+
.networkInterceptors()
2004+
.add(
2005+
new com.squareup.okhttp.Interceptor() {
2006+
@Override
2007+
public com.squareup.okhttp.Response intercept(
2008+
com.squareup.okhttp.Interceptor.Chain chain)
2009+
throws IOException {
2010+
com.squareup.okhttp.Response originalResponse =
2011+
chain.proceed(chain.request());
2012+
return originalResponse
2013+
.newBuilder()
2014+
.body(
2015+
new ProgressResponseBody(
2016+
originalResponse.body(),
2017+
progressListener))
2018+
.build();
2019+
}
2020+
});
2021+
}
2022+
2023+
return apiClient.buildCall(
2024+
path,
2025+
"POST",
2026+
queryParams,
2027+
collectionQueryParams,
2028+
postBody,
2029+
headerParams,
2030+
formParams,
2031+
progressRequestListener);
2032+
}
2033+
2034+
private com.squareup.okhttp.Call scanBarcodeValidateBeforeCall(
2035+
ScanBarcodeRequest request,
2036+
final ProgressResponseBody.ProgressListener progressListener,
2037+
final ProgressRequestBody.ProgressRequestListener progressRequestListener)
2038+
throws ApiException {
2039+
2040+
// verify the required parameter 'request.imageFile' is set
2041+
if (request.imageFile == null) {
2042+
throw new ApiException(
2043+
"Missing the required parameter 'request.imageFile'"
2044+
+ " when calling scanBarcode(...)");
2045+
}
2046+
2047+
com.squareup.okhttp.Call call =
2048+
scanBarcodeCall(request, progressListener, progressRequestListener);
2049+
return call;
2050+
}
2051+
2052+
/**
2053+
* Quickly scan a barcode from an image.
2054+
*
2055+
* @param request See {@link ScanBarcodeRequest}
2056+
* @return BarcodeResponseList
2057+
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the
2058+
* response body
2059+
*/
2060+
public BarcodeResponseList scanBarcode(ScanBarcodeRequest request) throws ApiException {
2061+
ApiResponse<BarcodeResponseList> resp = scanBarcodeWithHttpInfo(request);
2062+
return resp.getData();
2063+
}
2064+
2065+
/**
2066+
* Quickly scan a barcode from an image.
2067+
*
2068+
* @param request See {@link ScanBarcodeRequest}
2069+
* @return ApiResponse&lt;BarcodeResponseList&gt;
2070+
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the
2071+
* response body
2072+
*/
2073+
public ApiResponse<BarcodeResponseList> scanBarcodeWithHttpInfo(ScanBarcodeRequest request)
2074+
throws ApiException {
2075+
com.squareup.okhttp.Call call = scanBarcodeValidateBeforeCall(request, null, null);
2076+
Type returnType = new TypeToken<BarcodeResponseList>() {}.getType();
2077+
return apiClient.execute(call, returnType);
2078+
}
2079+
2080+
/**
2081+
* Quickly scan a barcode from an image. (asynchronously)
2082+
*
2083+
* @param request See {@link ScanBarcodeRequest}
2084+
* @param callback The callback to be executed when the API call finishes
2085+
* @return The request call
2086+
* @throws ApiException If fail to process the API call, e.g. serializing the request body
2087+
* object
2088+
*/
2089+
public com.squareup.okhttp.Call scanBarcodeAsync(
2090+
ScanBarcodeRequest request, final ApiCallback<BarcodeResponseList> callback)
2091+
throws ApiException {
2092+
2093+
ProgressResponseBody.ProgressListener progressListener = null;
2094+
ProgressRequestBody.ProgressRequestListener progressRequestListener = null;
2095+
2096+
if (callback != null) {
2097+
progressListener =
2098+
new ProgressResponseBody.ProgressListener() {
2099+
@Override
2100+
public void update(long bytesRead, long contentLength, boolean done) {
2101+
callback.onDownloadProgress(bytesRead, contentLength, done);
2102+
}
2103+
};
2104+
2105+
progressRequestListener =
2106+
new ProgressRequestBody.ProgressRequestListener() {
2107+
@Override
2108+
public void onRequestProgress(
2109+
long bytesWritten, long contentLength, boolean done) {
2110+
callback.onUploadProgress(bytesWritten, contentLength, done);
2111+
}
2112+
};
2113+
}
2114+
2115+
com.squareup.okhttp.Call call =
2116+
scanBarcodeValidateBeforeCall(request, progressListener, progressRequestListener);
2117+
Type returnType = new TypeToken<BarcodeResponseList>() {}.getType();
2118+
apiClient.executeAsync(call, returnType, callback);
2119+
return call;
2120+
}
19522121
}

0 commit comments

Comments
 (0)