Resource Base
Table of contents

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.

DocumentNormalizer normalizer;
CameraEnhancer mCameraEnhancer;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Be sure that you have added a cameraView in the layout file.
    DCECameraView cameraView = findViewById(R.id.cameraView);

    try {
        // Create an instance of Dynamsoft Document Normalizer.
        normalizer = new DocumentNormalizer();
    } catch (DocumentNormalizerException e) {
        e.printStackTrace();
    }
    mCameraEnhancer = new CameraEnhancer(MainActivity.this);
    mCameraEnhancer.setCameraView(cameraView);

    // Bind the Camera Enhancer instance to the Document Normalizer instance.
    normalizer.setImageSource(mCameraEnhancer);

    // Result callback configurations
    DetectResultListener mDetectResultListener = new DetectResultListener() {
        // Obtain the detected quad detection results and display.
        @Override
        public void detectResultCallback(int id, ImageData imageData, DetectedQuadResult[] detectedResults) {
            // Add your code to execute when quad detection results are returned.
        }
    };

    normalizer.setDetectResultListener(mDetectResultListener);
}

@Override
public void onResume() {
    // Open the camera and start video quad detecting 
    try {
        mCameraEnhancer.open();
    } catch (CameraEnhancerException e) {
        e.printStackTrace();
    }
    normalizer.startDetecting();
    super.onResume();
}

@Override
public void onPause() {
    // Stop video quad detecting 
    try {
        mCameraEnhancer.close();
    } catch (CameraEnhancerException e) {
        e.printStackTrace();
    }
    normalizer.stopDetecting();
    super.onPause();
}

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. CameraEnhancer is a specific implementation of ImageSource, which can help the Document Normalizer to acquire video frames continuously for recognition.

void setImageSource(ImageSource source)

Parameters

[in] source: An instance of ImageSource. If you are using Dynamsoft Camera Enhancer(DCE) to capture camera frames, pass an instance of CameraEnhancer.

Code Snippet

// Create an instance of DynamsoftCameraEnhancer and set it as the image source.
DCECameraView cameraView = findViewById(R.id.cameraView);
CameraEnhancer mCameraEnhancer; = new CameraEnhancer(MainActivity.this);
mCameraEnhancer.setCameraView(cameraView);
normalizer.setImageSource(mCameraEnhancer);

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.

void startDetecting()

Code Snippet

normalizer.startDetecting();

stopDetecting

Stop the document quad detection thread in the video streaming scenario.

void stopDetecting()

Code Snippet

normalizer.startDetecting();

setDetectResultListener

Set the callback interface to process detection results generated during frame detecting.

void setDetectResultListener(DetectResultListener detectResultListener)

Parameters

[in] detectResultListener: The Callback interface.

Code Snippet

// Result callback configurations
DetectResultListener mDetectResultListener = new DetectResultListener() {
    // Obtain the detected quad detection results and display.
    @Override
    public void detectResultCallback(int id, ImageData imageData, DetectedQuadResult[] detectedResults) {
        // Add your code to execute when quad detection results are returned.
    }
};
normalizer.setDetectResultListener(mDetectResultListener);

This page is compatible for:

Version 1.0

Is this page helpful?

YesYes NoNo

In this article:

latest version

  • Latest version
  • Version 2.x
    • Version 2.2.10
    • Version 2.0.20
    • Version 2.0.10
    • Version 2.0.10
  • Version 1.x
    • Version 1.0.30
    • Version 1.0.21
    • Version 1.0.20
    • Version 1.0.12
    • Version 1.0.11
    • Version 1.0.10
    • Version 1.0.0
    • Version 1.0.30
    • Version 1.0.21
    • Version 1.0.20
    • Version 1.0.12
    • Version 1.0.11
    • Version 1.0.10
    • Version 1.0.0
    • Version 1.0.5
    • Version 1.0.4
    • Version 1.0.3
    • Version 1.0.2
    • Version 1.0.1
    • Version 1.0.0
Change +
© 2003–2024 Dynamsoft. All rights reserved.
Privacy Statement / Site Map / Home / Purchase / Support