Base Implementation
Start to scan
- Swift
- Obj-C
//Instanciate the scanner
let scan = SmartScanner()
//Create a view and use it like a standard UIView
let preview = scan.previewView(withViewSize: self.view.bounds)
scan.scDelegate = self
self.view.insertSubview(preview!, at: 0)
//Set the type of code to decode
scan.setDecodingType(CODE_OCRB.rawValue andSubType: CODE_ICAO_9303_PASSPORT.rawValue)
//For some types of OCR the camera orientation should be specified
scan.setDecoding(UIApplication.shared.statusBarOrientation)
//Customize your ROI if needed, this need to be done after setting the type of code
let regionOfInterest = CGRect(x: 0.0, y: 0.0, width: 160, height: 160)
scan.setRegionOfInterest(regionOfInterest)
//Create the SmartScanner object reference
SmartScanner* sc;
//Init SmartScanner when needed, and set the delegate
sc = [[SmartScanner alloc] init];
sc.scDelegate = self;
//Retrieve the preview screen and display it on your view
UIView* preview = [sc previewViewWithViewSize:self.view.bounds];
[self.view addSubview:preview];
[sc setDecodingType: CODE_OCRB andSubType: CODE_ICAO_9303_IDCARD];
//Eventually set a custom ROI (This must be done after setting the decoding type)
[sc setRegionOfInterest:CGRectMake(0, 0, 300, 300)] ;
//For some types of OCR the camera orientation should be specified
[sc setDecodingOrientation:[UIApplication sharedApplication].statusBarOrientation ];
Select the type of code you want to decode
You can use a combination of any type or subtype that is enabled in the version you have. At any point you can set another decoding type (Verify the enabled types of your SmartScan version by calling the version function).
Thoses are referenced in the enums
In the header file IcareDecodersCodes.hpp
SmartDecodingSubTypes
SmartDecodingTypes
For example
- Swift
- Obj-C
//Use the rawValue of the enums
var typeOfCode : UInt64 = CODE_OCRB.rawValue
var subtypeOfCode : UInt64 = CODE_BVR.rawValue | CODE_ICAO_9303_IDCARD.rawValue
//Configuring what type of content to scan.
scan.setDecodingType(typeOfCode, andSubType: subtypeOfCode)
#define TypeToDecode (CODE_OCRB | CODE_EU_PLATES )
#define SubTypeToDecode (CODE_PLT_ALL | CODE_ICAO_9303_PASSPORT | CODE_ICAO_9303_IDCARD | CODE_FRENCH_IDS | CODE_ROMANIAN_IDS | CODE_ROMANIAN_IDS | CODE_ROMANIAN_IDS)
[sc setDecodingType: TypeToDecode andSubType: SubTypeToDecode];
Retrieve the results by implementing the delegate protocol
- Swift
- Obj-C
func smartScan(_ smartScanner: SmartScanner, found smartScannerResult: SmartScanResult) {
print("Result : \(smartScannerResult.content) type : \(smartScannerResult.metadata)")
}
- (void)SmartScan:(SmartScanner *)smartScanner foundResult:(SmartScanResult *)smartScannerResult
{
NSString* message = [NSString stringWithFormat:@"Smartscan : %@ with type : %@", smartScannerResult.content, smartScannerResult.metadata];
NSLog(@"%@", message);
}
Release the resources when you don't need to use the smartscanner anymore
- Swift
- Obj-C
sc?.closeCameraStream()
sc = nil
[sc closeCameraStream];
sc = nil;