Video Decoding Methods
Note:
- You have to include
DynamsoftCameraEnhancer
when using Video Decoding Methods.DynamsoftCameraEnhancer
provide APIs that help you quickly deploy a camera module and capture video streaming for barcode decoding.- Through Video Decoding Methods you can control whether to start video streaming barcode decoding and get the barcode results.
- Be sure that your
DynamsoftBarcodeReader
version is 8.9.0+ andDynamsoftCameraEnhancer
is 2.1.0+ when using the methods on this page.
Method | Description |
---|---|
setCameraEnhancer |
Bind a Camera Enhancer instance to the Barcode Reader. |
startScanning |
Start the barcode reading thread. |
stopScanning |
Stop the barcode reading thread. |
setDBRTextResultListener |
Set callback function to process text results generated during frame decoding. |
setDBRIntermediateResultListener |
Set callback function to process intermediate results generated during frame decoding. |
enableResultVerification |
Enable Result Verification feature to improve the accuracy of barcode results for video streaming barcode decoding. |
enableDuplicateFilter |
Enable Duplicate Filter feature to filter out the duplicate results in the period of 3000ms for video barcode decoding. |
setCameraEnhancer
Bind a DynamsoftCameraEnhancer
instance to the Barcode Reader.
- (void)setCameraEnhancer:(DynamsoftCameraEnhancer* _Nonnull)cameraInstance;
Parameters
cameraInstance
: An instance of Dynamsoft Camera Enhancer
.
Code Snippet
This code snippet displays a complete code on how to add DynamsoftCameraEnhancer to your project and start to use Video Decoding Methods to decode and get barcode results from the video streaming.
- Objective-C
- Swift
/* Be sure that you have import the following headers when using video decoding methods */ #import <DynamsoftBarcodeReader/DynamsoftBarcodeReader.h> #import <DynamsoftCameraEnhancer/DynamsoftCameraEnhancer.h> /* You have to add DBRTextResultListener to your interface. */ @interface ViewController ()<DBRTextResultListener> @property(nonatomic, strong) DynamsoftBarcodeReader *barcodeReader; @property(nonatomic, strong) DynamsoftCameraEnhancer *dce; @property(nonatomic, strong) DCECameraView *dceView; @end @implementation ViewController - (void)viewDidLoad{ [super viewDidLoad]; [self configurationDBR]; } - (void)configurationDBR{ _barcodeReader = [[DynamsoftBarcodeReader alloc] init]; _dceView = [DCECameraView cameraWithFrame:self.view.bounds]; [self.view addSubview:_dceView]; _dce = [[DynamsoftCameraEnhancer alloc] initWithView:_dceView]; [_dce open]; [_barcodeReader setCameraEnhancer:_dce]; [_barcodeReader startScanning]; [_barcodeReader setDBRTextResultListener:self]; } - (void)textResultCallback:(NSInteger)frameId imageData:(iImageData *)imageData results:(NSArray<iTextResult *> *)results{ // Add your code to do when barcode result is returned. }
// Be sure that you have import the following headers when using video decoding methods import DynamsoftBarcodeReader import DynamsoftCameraEnhancer // You have to add setDBRTextResultListener to your class. class ViewController: UIViewController, DBRTextResultListener{ var SafeAreaBottomHeight:CGFloat = UIApplication.shared.statusBarFrame.size.height > 20 ? 34 : 0 var mainHeight = UIScreen.main.bounds.height var mainWidth = UIScreen.main.bounds.width var dce:DynamsoftCameraEnhancer! = nil var dceView:DCECameraView! = nil var barcodeReader:DynamsoftBarcodeReader! = nil override func viewDidLoad(){ super.viewDidLoad() configurationDBR() } override func viewWillAppear(_ animated: Bool) { barcodeReader.startScanning() } override func viewWillDisappear(_ animated: Bool) { barcodeReader.stopScanning() } func configurationDBR(){ barcodeReader = DynamsoftBarcodeReader.init() var barHeight = self.navigationController?.navigationBar.frame.height if UIApplication.shared.statusBarFrame.size.height <= 20 { barHeight = 20 } dceView = DCECameraView.init(frame: CGRect(x: 0, y: barHeight!, width: mainWidth, height: mainHeight - SafeAreaBottomHeight - barHeight!)) self.view.addSubview(dceView) dce = DynamsoftCameraEnhancer.init(view: dceView) dce.open() barcodeReader.setCameraEnhancer(dce) barcodeReader.setDBRTextResultListener(self) } func textResultCallback(_ frameId: Int, imageData: iImageData, results: [iTextResult]?){ // Add your code } }
startScanning
Start the video streaming barcode decoding thread. Please be sure that you have bound a DynamsoftCameraEnhacner
or ImageSource
to the barcode reader before you trigger startScanning
.
-(void)startScanning;
Code Snippet
You can view detailed code snippet in setCameraEnhancer
stopScanning
Stop the video streaming barcode decoding thread.
-(void)stopScanning;
Code Snippet
- Objective-C
- Swift
[_barcodeReader stopScanning];
barcodeReader.stopScanning()
setDBRTextResultListener
Set callback function to process text results generated during frame decoding.
-(void)setDBRTextResultListener:(id _Nullable)textResultListener;
Parameters
[in] textResultListener
: Callback function.
Code Snippet
You can view detailed code snippet in setCameraEnhancer
setDBRIntermediateResultListener
Set callback function to process intermediate results generated during frame decoding.
-(void)setDBRIntermediateResultListener:(id _Nullable)intermediateResultListener;
Parameters
[in] intermediateResultListener
: Callback function.
Code Snippet
The usage of intermediateResultListener
is similar to the textResultListener
. You can view detailed code snippet in setCameraEnhancer
and replace the textResultListener
code with the intermediateResultListener
code.
- Objective-C
- Swift
// You have to add DBRIntermediateResultListener to your interface. @interface ViewController ()<DBRIntermediateResultListener> - (void)configurationDBR{ _barcodeReader = [[DynamsoftBarcodeReader alloc] init]; [_barcodeReader setDBRIntermediateResultListener:self]; } - (void)intermediateResultCallback:(NSInteger)frameId imageData:(iImageData *)imageData results:(NSArray<iTextResult *> *)results{ // Add your code to execute when intermediate result is returned. }
// You have to add DBRIntermediateResultListener to your class. class ViewController: UIViewController, DBRIntermediateResultListener{ func configurationDBR(){ barcodeReader = DynamsoftBarcodeReader.init() barcodeReader.setDBRIntermediateResultListener(self) } func intermediateResultCallback(_ frameId: Int, imageData: iImageData, results: [iTextResult]?){ // Add your code to execute when intermediate result is returned. } }
enableResultVerification
Enable Result Verification on the barcode results of video streaming barcode decoding. This feature is not enabled by default.
There are 2 way for you to get barcode results:
- From the return value of
decode
methods when processing a single image. - From the
textResultCallback
when processing the video streaming.
Result verification feature only effects on the OneD barcode results you get from textResultCallback
.
@property (nonatomic, assign) BOOL enableResultVerification;
Parameters
boolean
value which stands for the target status of result verification mode.
Code Snippet
- Objective-C
- Swift
[barcodeReader enableResultVerification:true]; // To check the status of this mode [barcodeReader getEnableResultVerification]
barcodeReader.enableResultVerification = true // To check the status of this mode let x = barcodeReader.enableResultVerification
enableDuplicateFilter
Filter out the duplicate results in the period of 3000ms for video barcode decoding. Barcode results with the same text and format will be returned only once during the period.
There are 2 way for you to get barcode results:
- From the return value of
decode
methods when processing a single image. - From the
textResultCallback
when processing the video streaming.
Duplicate filter only effects on the duplicate results that output by textResultCallback
.
@property (nonatomic, assign) BOOL enableDuplicateFilter;
Parameters
boolean
value which stands for the target status of result duplicate filter mode.
Code Snippet
- Objective-C
- Swift
[barcodeReader enableDuplicateFilter:true]; // To check the status of this mode [barcodeReader getEnableDuplicateFilter]
barcodeReader.enableDuplicateFilter = true // To check the status of this mode let x = barcodeReader.enableDuplicateFilter