Video Detecting Methods
You are viewing a history document page of Dynamsoft Document Normalizer v1.0.30.
How to Implement Video Detecting
This code snippet displays a complete code on how to configure camera module, start detecting and get detection results from the video streaming.
- Objective-C
- Swift
@interface ViewController ()<DetectResultListener> @property(nonatomic, strong) DynamsoftDocumentNormalizer *ddn; @property(nonatomic, strong) DynamsoftCameraEnhancer *dce; @property(nonatomic, strong) DCECameraView *dceView; @end @implementation ViewController - (void)viewDidLoad{ [super viewDidLoad]; [self configurationDDN]; } - (void)configurationDDN{ _ddn = [[DynamsoftDocumentNormalizer alloc] init]; _dceView = [DCECameraView cameraWithFrame:self.view.bounds]; [self.view addSubview:_dceView]; _dce = [[DynamsoftCameraEnhancer alloc] initWithView:_dceView]; [_dce open]; [_ddn setImageSource:_dce]; [_ddn setDetectResultListener:self]; [_ddn startDetecting]; } - (void)detectResultCallback:(NSInteger)frameId imageData:(iImageData *)imageData results:(NSArray<iDetectQuadResult *> *)results{ // Add your code to do when barcode result is returned. }
class ViewController: UIViewController, DetectResultListener{ 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 ddn:DynamsoftDocumentNormalizer! = nil override func viewDidLoad() { super.viewDidLoad() configurationDDN() } func configurationDDN(){ ddn = DynamsoftDocumentNormalizer() var barHeight = self.navigationController?.navigationBar.frame.height if UIApplication.shared.statusBarFrame.size.height <= 20 { barHeight = 20 } dceView = DCECameraView(frame: CGRect(x: 0, y: barHeight!, width: mainWidth, height: mainHeight - SafeAreaBottomHeight - barHeight!)) self.view.addSubview(dceView) dce = DynamsoftCameraEnhancer(view: dceView) dce.open() ddn.setImageSource(dce) ddn.setDetectResultListener(self) ddn.startDetecting() } func detectResultCallback(_ frameId: Int, imageData: iImageData, results: [iDetectQuadResult]?){ // Add your code } }
Note:
DynamsoftCameraEnhancer
library is included when implementing Video Quad Detecting. It provides APIs that help you quickly deploy a camera module and capture video streaming for document normalizer.
Methods
Use the following methods to control the start/stop of video streaming document detecting and get the detection results.
Method | Description |
---|---|
setImageSource |
Sets an instance of ImageSource to get images. |
startDetecting |
Start the document quad detection thread in the video streaming scenario. |
stopDetecting |
Stop the document quad detection thread in the video streaming scenario. |
setDetectResultListener |
Set callback interface to process detection results generated during frame detecting. |
setImageSource
Sets an instance of ImageSource to get images. DynamsoftCameraEnhancer
is a specific implementation of ImageSource, which can help the Document Normalizer to acquire video frames continuously for recognition.
- Objective-C
- Swift
- (void)setImageSource:(ImageSource* _Nonnull)source;
func setImageSource(_ source: ImageSource?)
Parameters
[in] source
: An instance of ImageSource. If you are using Dynamsoft Camera Enhancer
(DCE) to capture camera frames, pass an instance of DynamsoftCameraEnhancer
.
Code Snippet
- Objective-C
- Swift
- (void)configurationDDN{ _ddn = [[DynamsoftDocumentNormalizer alloc] init]; _dce = [[DynamsoftCameraEnhancer alloc] initWithView:_dceView]; [_ddn setImageSource:_dce]; }
func configurationDDN(){ ddn = DynamsoftDocumentNormalizer() dce = DynamsoftCameraEnhancer(view: dceView) ddn.setImageSource(dce) }
startDetecting
Start the document quad detection thread in the video streaming scenario. Please be sure that you have bound a Camera Enhancer to the document normalizer before you trigger startDetecting
.
- Objective-C
- Swift
-(void)startDetecting
func startDetecting()
Code Snippet
- Objective-C
- Swift
[_ddn startDetecting];
ddn.startDetecting()
stopDetecting
Stop the document quad detection thread in the video streaming scenario.
- Objective-C
- Swift
-(void)stopDetecting
func stopDetecting()
Code Snippet
- Objective-C
- Swift
[_ddn stopDetecting];
ddn.stopDetecting()
setDetectResultListener
Set the callback interface to process detection results generated during frame detecting.
- Objective-C
- Swift
-(void)setDetectResultListener:(id<DetectResultListener>)detectResultListener;
func setDetectResultListener(_ listener: DetectResultListener)
Parameters
[in] detectResultListener
: The Callback interface.
Code Snippet
- Objective-C
- Swift
@interface ViewController ()<DetectResultListener> - (void)configurationDDN{ [_ddn setDetectResultListener:self]; } - (void)detectResultCallback:(NSInteger)frameId imageData:(iImageData *)imageData results:(NSArray<iDetectQuadResult *> *)results{ // Add your code to do when barcode result is returned. }
class ViewController: UIViewController, DetectResultListener{ func configurationDDN(){ ddn.setDetectResultListener(self) } func detectResultCallback(_ frameId: Int, imageData: iImageData, results: [iDetectQuadResult]?){ // Add your code } }