DynamsoftLabelRecognizer
@interface DynamsoftLabelRecognizer : NSObject
Initialization Method Summary
Method | Description |
---|---|
init |
Create an instance of Dynamsoft Label Recognizer. |
initLicense |
Initializes the label Recognizer license. |
Settings Method Summary
Method | Description |
---|---|
getRuntimeSettings |
Gets the current settings and saves it into a class. |
updateRuntimeSettings |
Updates runtime settings with a given class. |
resetRuntimeSettings |
Resets the runtime settings. |
appendSettingsFromString |
Appends LabelRecognizerParameter settings in a string to the SDK object. |
appendSettingsFromFile |
Appends LabelRecognizerParameter settings from a file to the SDK object. |
outputSettingsToFile |
Outputs LabelRecognizerParameter settings into a file (JSON file). |
clearAppendedSettings |
Clear all appended LabelRecognizerParameter settings in the SDK object. |
updateReferenceRegionFromBarcodeResults |
Updates reference region which is defined with source type LST_BARCODE. |
getModeArgument |
Get argument value for the specified mode parameter. |
setModeArgument |
Set argument value for the specified mode parameter. |
appendCharacterModel |
Appends CharacterModel to the SDK object. |
eraseAllCharacterModels |
Erases all CharacterModels the SDK object currently loaded. |
eraseCharacterModelByName |
Erases a name specified CharacterModel from the SDK object. |
Video Scanning Method Summary
Method | Description |
---|---|
setImageSource |
Set an instance of ImageSource as the source of video label scanning. User can either implement the interface ImageSource or use DynamsoftCameraEnhancer . |
setLabelResultListener |
Register a LabelResultListener to obtain video label recognition results. |
startScanning |
Start video label recognition. |
stopScanning |
Stop video label recognition. |
Recognizing Method Summary
Method | Description |
---|---|
recognizeBuffer |
Recognizes text from memory buffer containing image pixels in defined format. |
recognizeFile |
Recognizes text from a specified image file. |
recognizeImage |
Recognizes text from an image in memory. |
General Method Summary
Method | Description |
---|---|
getVersion |
Returns the version number string for the SDK. |
Initialization Method Details
init
Initializes DynamsoftLabelRecognizer.
- (instancetype _Nonnull)init;
Return value
The instance of DynamsoftLabelRecognizer.
Code Snippet
- Objective-C
- Swift
DynamsoftLabelRecognizer *recognizer; recognizer = [[DynamsoftLabelRecognizer alloc] init];
let recognizer = DynamsoftLabelRecognizer.init()
initLicense
Initializes the label Recognizer license.
+ (void)initLicense:(NString* _Nullable)license verificationDelegate:(id _Nullable)connectionDelegate;
Parameters
[in] license
The product keys.
[in,out] connectionDelegate
The delegate to handle callback when license server returns.
Code Snippet
- Objective-C
- Swift
- ```objc [DynamsoftLabelRecognizer initLicense:@”t0260NwAAAHV*******” verificationDelegate:self];
- (void)DLRLicenseVerificationCallback:(bool)isSuccess error:(NSError * )error
{
//TODO: add your code for license verification
}
```
- ```swift DynamsoftLabelRecognizer.initLicense(license:”t0260NwAAAHV*******”, verificationDelegate: self)
func DLRLicenseVerificationCallback(_ isSuccess: Bool, error: Error?) { //TODO: add your code for license verification }
## Settings Method Details
### appendCharacterModel
Appends CharacterModel to the SDK object.
```objc
+ (void)appendCharacterModel:(NSString*)name prototxtBuffer:(NSData*)prototxtBuffer txtBuffer:(NSData*)txtBuffer characterModelBuffer:(NSData*)characterModelBuffer
Parameters
name
A unique name for the appended CharacterModel.
prototxtBuffer
The .prototxt file data of the CharacterModel in a byte array.
txtBuffer
The .txt file data of the CharacterModel in a byte array.
characterModelBuffer
The .caffemodel file data of the CharacterModel in a byte array.
Code Snippet
- Objective-C
- Swift
//construct prototxtBuffer, txtBuffer and characterModelBuffer [DynamsoftLabelRecognizer appendCharacterModel:@"your model name" prototxtBuffer: prototxtBuffer txtBuffer: txtBuffer characterModelBuffer: characterModelBuffer];
//construct prototxtBuffer, txtBuffer and characterModelBuffer DynamsoftLabelRecognizer.appendCharacterModel("your model name", prototxtBuffer: prototxtBuffer, txtBuffer: txtBuffer, characterModelBuffer: characterModelBuffer)
eraseAllCharacterModels
Erases all CharacterModels the SDK object currently loaded.
+ (void)eraseAllCharacterModels;
Code Snippet
- Objective-C
- Swift
[DynamsoftLabelRecognizer eraseAllCharacterModels];
DynamsoftLabelRecognizer.eraseAllCharacterModels()
eraseCharacterModelByName
Erases a name specified CharacterModel from the SDK object.
+ (void)eraseCharacterModelByName:(NSString*)name
Parameters
name
A unique name representing the CharacterModel to erase.
Code Snippet
- Objective-C
- Swift
[DynamsoftLabelRecognizer eraseCharacterModelByName:@"your model name"];
DynamsoftLabelRecognizer.eraseCharacterModelByName("your model name")
appendSettingsFromFile
Appends LabelRecognizerParameter settings in a file to the SDK object.
- (void)appendSettingsFromFile:(NSString*)filePath error:(NSError**)error
Parameters
filePath
The settings file path.
[in,out] error
Input a pointer to an error object. If an error occurs, this pointer is set to an actual error object containing the error information. You may specify nil for this parameter if you do not want the error information.
Code Snippet
- Objective-C
- Swift
- ```objc DynamsoftLabelRecognizer *recognizer; recognizer = [[DynamsoftLabelRecognizer alloc] init];
NSError __autoreleasing * error; [recognizer appendSettingsFromFile:@”your file path” error:&error];
2.
```swift
let recognizer = DynamsoftLabelRecognizer()
let error: NSError? = NSError()
recognizer.appendSettingsFromFile("your file path", error:&error)
appendSettingsFromString
Append a new template string to the current label Recognizer instance.
- (void)appendSettingsFromString:(NSString*)content error:(NSError**)error
Parameters
content
A JSON string that represents the content of the settings.
[in,out] error
Input a pointer to an error object. If an error occurs, this pointer is set to an actual error object containing the error information. You may specify nil for this parameter if you do not want the error information.
Code Snippet
- Objective-C
- Swift
- ```objc DynamsoftLabelRecognizer *recognizer; recognizer = [[DynamsoftLabelRecognizer alloc] init];
NSError __autoreleasing * error; [recognizer appendSettingsFromString:@”{"LabelRecognizerParameter":{"Name":"P1", "RegionPredetectionModes":[{"Mode":"RPM_GENERAL_HSV_CONTRAST"}], "ReferenceRegionNameArray": ["R1"]},"ReferenceRegion":{"Name":"R1","Localization":{"SourceType":"LST_PREDETECTED_REGION","RegionPredetectionModesIndex":0},"TextAreaNameArray":["T1"]},"TextArea":{"Name":"T1","CharacterModelName":"Number"}}” error:&error];
2.
```swift
let recognizer = DynamsoftLabelRecognizer()
let error: NSError? = NSError()
recognizer.appendSettingsFromString("{\"LabelRecognizerParameter\":{\"Name\":\"P1\", \"RegionPredetectionModes\":[{\"Mode\":\"RPM_GENERAL_HSV_CONTRAST\"}], \"ReferenceRegionNameArray\": [\"R1\"]},\"ReferenceRegion\":{\"Name\":\"R1\",\"Localization\":{\"SourceType\":\"LST_PREDETECTED_REGION\",\"RegionPredetectionModesIndex\":0},\"TextAreaNameArray\":[\"T1\"]},\"TextArea\":{\"Name\":\"T1\",\"CharacterModelName\":\"Number\"}}", error:&error)
clearAppendedSettings
Clear all appended parameter settings of the current label Recognizer instance.
- (void)clearAppendedSettings:(NSError**)error;
Parameters
[in,out] error
Input a pointer to an error object. If an error occurs, this pointer is set to an actual error object containing the error information. You may specify nil for this parameter if you do not want the error information.
Code Snippet
- Objective-C
- Swift
DynamsoftLabelRecognizer *recognizer; recognizer = [[DynamsoftLabelRecognizer alloc] init]; NSError __autoreleasing * error; [recognizer clearAppendedSettings:&error];
let recognizer = DynamsoftLabelRecognizer() let error: NSError? = NSError() recognizer.clearAppendedSettings(&error)
getModeArgument
Get argument value for the specified mode parameter.
- (NSString* _Nonnull)getModeArgument:(NSString* _Nonnull)modeName index:(NSInteger)index argumentName:(NSString* _Nonnull)argumentName error:(NSError* _Nullable * _Nullable)error;
Parameters
modeName
: The mode parameter name to get argument.
index
: The array index of mode parameter to indicate a specific mode.
argumentName
: The name of the argument to get.
[in,out] error
Input a pointer to an error object. If an error occurs, this pointer is set to an actual error object containing the error information. You may specify nil for this parameter if you do not want the error information.
Return value
the optional argument for a specified mode in Modes parameters.
Remark
Check follow link for available modes and arguments:
Code Snippet
- Objective-C
- Swift
- ```objc DynamsoftLabelRecognizer *recognizer; recognizer = [[DynamsoftLabelRecognizer alloc] init];
NSError __autoreleasing * error; NSString *argumentValue = [recognizer getModeArgument:@”RegionPredetectionModes” index:0 argumentName:@”AspectRatioRange” error:&error];
2.
```swift
let recognizer = DynamsoftLabelRecognizer()
let error: NSError? = NSError()
let argumentValue = recognizer.getModeArgument("RegionPredetectionModes", index:0, argumentName:"AspectRatioRange", error:&error)
getRuntimeSettings
Get current settings and save them into a iDLRRuntimeSettings
class object.
- (iDLRRuntimeSettings*)getRuntimeSettings:(NSError**)error;
Parameters
[in,out] error
Input a pointer to an error object. If an error occurs, this pointer is set to an actual error object containing the error information. You may specify nil for this parameter if you do not want the error information.
Return value
The class object of runtime settings.
Code Snippet
- Objective-C
- Swift
DynamsoftLabelRecognizer *recognizer; recognizer = [[DynamsoftLabelRecognizer alloc] init]; NSError __autoreleasing * error; iDLRRuntimeSettings* settings = [recognizer getRuntimeSettings:&error];
let recognizer = DynamsoftLabelRecognizer() let error: NSError? = NSError() let settings = recognizer.getRuntimeSettings(&error)
outputSettingsToFile
Outputs runtime settings and save them into a settings file (JSON file).
- (void)outputSettingsToFile:(NSString*)filePath templateName:(NSString*)templateName error:(NSError**)error
Parameters
filePath
The path of the output file which stores current settings.
templateName
A unique name for declaring current runtime settings.
[in,out] error
Input a pointer to an error object. If an error occurs, this pointer is set to an actual error object containing the error information. You may specify nil for this parameter if you do not want the error information.
Code Snippet
- Objective-C
- Swift
DynamsoftLabelRecognizer *recognizer; recognizer = [[DynamsoftLabelRecognizer alloc] init]; NSError __autoreleasing * error; [recognizer outputSettingsToFile:@"your saving file path" templateName:@"currentRuntimeSettings" error:&error];
let recognizer = DynamsoftLabelRecognizer() let error: NSError? = NSError() recognizer.outputSettingsToFile("your saving file path", templateName:"currentRuntimeSettings", error:&error)
resetRuntimeSettings
Reset all runtime settings to default values.
- (void)resetRuntimeSettings:(NSError**)error;
Parameters
[in,out] error
Input a pointer to an error object. If an error occurs, this pointer is set to an actual error object containing the error information. You may specify nil for this parameter if you do not want the error information.
Code Snippet
- Objective-C
- Swift
- ```objc DynamsoftLabelRecognizer *recognizer; recognizer = [[DynamsoftLabelRecognizer alloc] init];
NSError __autoreleasing * error; [recognizer resetRuntimeSettings:&error];
2.
```swift
let recognizer = DynamsoftLabelRecognizer()
let error: NSError? = NSError()
recognizer.resetRuntimeSettings(error:&error)
setModeArgument
Set argument value for the specified mode parameter.
- (void)setModeArgument:(NSString* _Nonnull)modeName index:(NSInteger)index argumentName:(NSString* _Nonnull)argumentName argumentValue:(NSString* _Nonnull)argumentValue error:(NSError* _Nullable * _Nullable)error;
Parameters
modeName
: The mode parameter name to set argument.
index
: The array index of mode parameter to indicate a specific mode.
argumentName
: The name of the argument to set.
argumentValue
: The value of the argument to set.
[in,out] error
Input a pointer to an error object. If an error occurs, this pointer is set to an actual error object containing the error information. You may specify nil for this parameter if you do not want the error information.
Remark
Check follow link for available modes and arguments:
Code Snippet
- Objective-C
- Swift
DynamsoftLabelRecognizer *recognizer; recognizer = [[DynamsoftLabelRecognizer alloc] init]; NSError __autoreleasing * _Nullable error; [recognizer setModeArgument:@"RegionPredetectionModes" index:0 argumentName:@"AspectRatioRange" argumentValue:"100" error:&error];
let recognizer = DynamsoftLabelRecognizer() let error: NSError? = NSError() recognizer.setModeArgument("RegionPredetectionModes", index:0, argumentName:"AspectRatioRange", argumentValue:"100", error:&error)
updateReferenceRegionFromBarcodeResults
Updates reference region which is defined with source type LST_BARCODE.
- (void)updateReferenceRegionFromBarcodeResults:(NSArray<iBarcodeResult*>*)barcodeResults templateName:(NSString *)templateName error:(NSError**)error
Parameters
barcodeResults
The barcode results used to localize reference region. See also iBarcodeResult
.
templateName
The template name. A template name is the value of key LabelRecognizerParameter.Name defined in JSON formatted settings. If no template name is specified, current runtime settings will be used.
[in,out] error
Input a pointer to an error object. If an error occurs, this pointer is set to an actual error object containing the error information. You may specify nil for this parameter if you do not want the error information.
Code Snippet
- Objective-C
- Swift
DynamsoftLabelRecognizer *recognizer; recognizer = [[DynamsoftLabelRecognizer alloc] init]; NSArray<iBarcodeResult*> *textResults; //get textResults from Dynamsoft Barcode Reader SDK NSError __autoreleasing *error; [recognizer appendSettingsFromString:@"{\"LabelRecognizerParameter\":{\"Name\":\"P1\", \"RegionPredetectionModes\":[{\"Mode\":\"RPM_GENERAL_HSV_CONTRAST\"}], \"ReferenceRegionNameArray\": [\"R1\"]},\"ReferenceRegion\":{\"Name\":\"R1\",\"Localization\":{\"SourceType\":\"LST_BARCODE\"},\"TextAreaNameArray\":[\"T1\"]},\"TextArea\":{\"Name\":\"T1\",\"CharacterModelName\":\"Number\"}}" error:&error]; [recognizer updateReferenceRegionFromBarcodeResults:textResults templateName:@"P1" error:&error];
let recognizer = DynamsoftLabelRecognizer() var textResults = [iBarcodeResult]() //get textResults from Dynamsoft Barcode Reader SDK let error: NSError? = NSError() recognizer.appendSettingsFromString("{\"LabelRecognizerParameter\":{\"Name\":\"P1\", \"RegionPredetectionModes\":[{\"Mode\":\"RPM_GENERAL_HSV_CONTRAST\"}], \"ReferenceRegionNameArray\": [\"R1\"]},\"ReferenceRegion\":{\"Name\":\"R1\",\"Localization\":{\"SourceType\":\"LST_BARCODE\"},\"TextAreaNameArray\":[\"T1\"]},\"TextArea\":{\"Name\":\"T1\",\"CharacterModelName\":\"Number\"}}", error:&error) recognizer.updateReferenceRegionFromBarcodeResults(textResults, templateName:"P1", error:&error)
updateRuntimeSettings
Update runtime settings with a given iDLRRuntimeSettings
class object.
- (void)updateRuntimeSettings:(iDLRRuntimeSettings*)settings error:(NSError**)error
Parameters
settings
The class object of template settings.
[in,out] error
Input a pointer to an error object. If an error occurs, this pointer is set to an actual error object containing the error information. You may specify nil for this parameter if you do not want the error information.
Code Snippet
- Objective-C
- Swift
DynamsoftLabelRecognizer *recognizer; recognizer = [[DynamsoftLabelRecognizer alloc] init]; NSError __autoreleasing * error; iDLRRuntimeSettings *settings; settings.maxThreadCount = 4; [recognizer updateRuntimeSettings:settings error:&error];
let recognizer = DynamsoftLabelRecognizer() let error: NSError? = NSError() let settings = recognizer.getRuntimeSettings(&error) settings.maxThreadCount = 4; recognizer.updateRuntimeSettings(settings, error:&error);
Video Scanning Method Details
setImageSource
Set an instance of ImageSource
as the source of video label scanning. User can either implement the interface ImageSource
or use DynamsoftCameraEnhancer
.
- (void)setImageSource:(id<ImageSource>)source;
Parameters
[in] source
A instance of protocol ImageSource
.
Code Snippet
setLabelResultListener
Register a LabelResultListener to obtain video label recognition results.
- (void)setLabelResultListener:(nullable id<LabelResultListener>)listener
Parameters
[in] source
A instance of protocol LabelResultListener
.
Code Snippet
startScanning
Start video label recognition.
- (void)startScanning;
stopScanning
Stop video label recognition.
- (void)stopScanning;
Recognizing Method Details
recognizeBuffer
Recognizes text from the memory buffer containing image pixels in defined format.
- (NSArray<iDLRResult*>*)recognizeBuffer:(iImageData*)imageData templateName:(NSString*)templateName error:(NSError**)error
Parameters
[in] imageData
An object of iImageData
that represents an image.
[in,out] error
Input a pointer to an error object. If an error occurs, this pointer is set to an actual error object containing the error information. You may specify nil for this parameter if you do not want the error information.
Return value
All results recognized successfully.
Code Snippet
- Objective-C
- Swift
DynamsoftLabelRecognizer *recognizer; recognizer = [[DynamsoftLabelRecognizer alloc] init]; iImageData *imageData = [[iImageData alloc] init]; //construct imageData NSError __autoreleasing * error; NSArray<iDLRResult*>* result = [recognizer recognizeBuffer:imageData templateName:@"" error:&error];
let recognizer = DynamsoftLabelRecognizer() let imageData = iImageData.init() let error: NSError? = NSError() //construct imageData let result = recognizer.recognizeBuffer(imageData:imageData, templateName:"", error:&error)
recognizeFile
Recognizes text from a specified image file.
- (NSArray<iDLRResult*>*)recognizeFile:(NSString*)name templateName:(NSString*)templateName error:(NSError**)error
Parameters
[in] name
A string defining the file path.
[in,out] error
Input a pointer to an error object. If an error occurs, this pointer is set to an actual error object containing the error information. You may specify nil for this parameter if you do not want the error information.
Return value
All results recognized successfully.
Code Snippet
- Objective-C
- Swift
DynamsoftLabelRecognizer *recognizer; recognizer = [[DynamsoftLabelRecognizer alloc] init]; NSError __autoreleasing * error; NSArray<iDLRResult*>* result = [recognizer recognizeFile:@"your file path" templateName:@"" error:&error];
let recognizer = DynamsoftLabelRecognizer() let error: NSError? = NSError() let result = recognizer.recognizeFile("your file path", templateName:"", error:&error)
recognizeImage
Recognizes text from a UIImage
.
- (NSArray<iDLRResult*>* _Nullable)recognizeImage:(UIImage* _Nonnull)image
error:(NSError* _Nullable * _Nullable)error;
Parameters
[in] image
An object of UIImage
.
[in, out] error
Input a pointer to an error object. If an error occurs, this pointer is set to an actual error object containing the error information. You may specify nil for this parameter if you do not want the error information.
Return value
All results recognized successfully.
Code Snippet
- Objective-C
- Swift
DynamsoftLabelRecognizer *recognizer; recognizer = [[DynamsoftLabelRecognizer alloc] init]; NSError __autoreleasing * error; UIImage *image = [[UIImage alloc] init]; NSArray<iDLRResult*>* result = [recognizer recognizeImage:image withTemplate:@"" error:&error];
let recognizer = DynamsoftLabelRecognizer() let error: NSError? = NSError() let image: UIImage? = UIImage() let result = recognizer.recognizeImage(image:image withTemplate:"" error:&error)
recognizeFileInMemory
Recognizes text from an image file in memory.
- (NSArray<iDLRResult*>* _Nullable)recognizeFileInMemory:(NSData* _Nonnull)fileBytes
error:(NSError**)error
Parameters
[in] fileBytes
The image file in memory.
[in, out] error
Input a pointer to an error object. If an error occurs, this pointer is set to an actual error object containing the error information. You may specify nil for this parameter if you do not want the error information.
Return value
All results recognized successfully.
Code Snippet
General Method Details
getVersion
Get version information of SDK.
- (NSString*)getVersion;
Return value
The version information string.
Code Snippet
- Objective-C
- Swift
DynamsoftLabelRecognizer *recognizer; recognizer = [[DynamsoftLabelRecognizer alloc] init]; NSString* versionInfo = [recognizer getVersion];
let recognizer = DynamsoftLabelRecognizer.init() let versionInfo = recognizer.getVersion();