MiSnapController

Coordinates the analysis of a Frame with evaluations to determine its quality. Use MiSnapController.create for creating an instance of this class.

NOTE: Ensure that the license in MiSnapSettings has the required features enabled for the target use case.

Samples

import android.os.Bundle
import android.view.View
import androidx.fragment.app.Fragment
import androidx.lifecycle.LiveData
import com.miteksystems.misnap.apputil.LicenseFetcher
import com.miteksystems.misnap.controller.MiSnapController
import com.miteksystems.misnap.controller.MiSnapController.ErrorResult
import com.miteksystems.misnap.controller.MiSnapController.FrameResult
import com.miteksystems.misnap.core.Frame
import com.miteksystems.misnap.core.MiSnapSettings
fun main() { 
   //sampleStart 
   /**
 * This example demonstrates a direct integration with MiSnap SDK's document analysis science through
 * the [MiSnapController], this type of integration is best suited for developers that want to
 * interface with the science directly and that will take care of supplying the frames themselves.
 *
 * NOTE: Ensure that the provided license has all the necessary features enabled for the target
 *  MiSnap session.
 *
 * @see com.miteksystems.misnap.examples.science for examples on how to directly interface with other
 * MiSnap SDK sciences.
 */
private class DocumentAnalysis : Fragment() {

    /**
     * Fetch the Misnap SDK license.
     * Good practice: Handle the license in a way that it is remotely updatable.
     */
    private val license by lazy {  
        LicenseFetcher.fetch()
    }

    private lateinit var misnapController: MiSnapController

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        misnapController = initDocumentAnalysis()

        /**
         * Call [startAnalysis] once the controller is ready to analyze [Frame]s.
         */
    }

    private fun startAnalysis(frame: Frame) {
        misnapController.analyzeFrame(frame, forceFrameResult = false)
    }

    /**
     * Create a [MiSnapController] capable of analyzing frames for a Document session, then observe
     * the different [LiveData] objects to get notified about feedback results, final results, errors,
     * etc.
     * Once the controller is ready and initialized create a [Frame] object and use the [MiSnapController.analyzeFrame]
     * method to analyze the frame.
     *
     * @see com.miteksystems.misnap.examples.science.FrameFromNativeCamera for examples on how to
     * build a [Frame] object from different camera APIs.
     */
    private fun initDocumentAnalysis(): MiSnapController {

        val misnapSettings = MiSnapSettings(MiSnapSettings.UseCase.CHECK_FRONT, license).apply {
            analysis.document.check.geo = MiSnapSettings.Analysis.Document.Check.Geo.US

            analysis.document.trigger = MiSnapSettings.Analysis.Document.Trigger.AUTO

            // Optionally enable on device document classification
            analysis.document.enableDocumentClassification = true

            // Optionally enable barcode extraction.
            analysis.document.barcodeExtractionRequirement =
                MiSnapSettings.Analysis.Document.ExtractionRequirement.OPTIONAL
        }

        return MiSnapController.create(requireContext(), misnapSettings).apply {
            /**
             * Observe the [MiSnapController.feedbackResult] [LiveData] to handle the feedback from
             * the analyzed frames and handle them accordingly, e.g. by showing the corresponding
             * instructions on screen based on the [MiSnapController.FeedbackResult.userAction],
             * showing the detected document corners using [MiSnapController.FeedbackResult.corners]
             * or the detected glare corners in [MiSnapController.FeedbackResult.glareCorners].
             */
            feedbackResult.observe(viewLifecycleOwner) { feedbackResult ->

            }

            /**
             * Observe the [MiSnapController.frameResult] [LiveData] to handle the successful results
             * of a session, e.g. by collecting the frame data in [FrameResult.DocumentAnalysis.frame]
             * to send it to the server.
             */
            frameResult.observe(viewLifecycleOwner) { result ->
                when (result) {
                    is FrameResult.DocumentAnalysis -> {

                    }
                    else -> {}
                }
            }

            /**
             * Observe the [MiSnapController.errorResult] [LiveData] to handle errors during the
             * analysis of frames.
             *
             * @see [ErrorResult] for all the possible error types emitted.
             */
            errorResult.observe(viewLifecycleOwner) { result ->
                when (result) {
                    is ErrorResult.DocumentDetection -> {
                    }
                    is ErrorResult.DocumentAnalysis -> {
                    }
                    is ErrorResult.BarcodeDetection -> {
                    }
                    is ErrorResult.BarcodeAnalysis -> {
                    }
                    is ErrorResult.DocumentClassification -> {

                    }
                    else -> {}
                }
            }
        }
    }
} 
   //sampleEnd
}
import android.os.Bundle
import android.view.View
import androidx.fragment.app.Fragment
import androidx.lifecycle.LiveData
import com.miteksystems.misnap.apputil.LicenseFetcher
import com.miteksystems.misnap.controller.MiSnapController
import com.miteksystems.misnap.controller.MiSnapController.ErrorResult
import com.miteksystems.misnap.controller.MiSnapController.FrameResult
import com.miteksystems.misnap.core.Frame
import com.miteksystems.misnap.core.MiSnapSettings
fun main() { 
   //sampleStart 
   /**
 * This example demonstrates a direct integration with MiSnap SDK's barcode analysis science through
 * the [MiSnapController], this type of integration is best suited for developers that want to
 * interface with the science directly and that will take care of supplying the frames themselves.
 *
 * NOTE: Ensure that the provided license has all the necessary features enabled for the target
 *  MiSnap session.
 *
 * @see com.miteksystems.misnap.examples.science for examples on how to directly interface with other
 * MiSnap SDK sciences.
 */
private class BarcodeAnalysis : Fragment() {

    /**
     * Fetch the Misnap SDK license.
     * Good practice: Handle the license in a way that it is remotely updatable.
     */
    private val license by lazy {  
        LicenseFetcher.fetch()
    }

    private lateinit var misnapController: MiSnapController

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        misnapController = initBarcodeAnalysis()

        /**
         * Call [startAnalysis] once the controller is ready to analyze [Frame]s.
         */
    }

    private fun startAnalysis(frame: Frame) {
        misnapController.analyzeFrame(frame)
    }

    /**
     * Create a [MiSnapController] capable of analyzing frames for a Barcode session, then observe
     * the different [LiveData] objects to get notified about feedback results, final results, errors,
     * etc.
     * Once the controller is ready and initialized create a [Frame] object and use the [MiSnapController.analyzeFrame]
     * method to analyze the frame.
     *
     * @see com.miteksystems.misnap.examples.science.FrameFromNativeCamera for examples on how to
     * build a [Frame] object from different camera APIs.
     */
    private fun initBarcodeAnalysis(): MiSnapController {
        val misnapSettings = MiSnapSettings(MiSnapSettings.UseCase.BARCODE, license).apply {
            analysis.barcode.trigger = MiSnapSettings.Analysis.Barcode.Trigger.AUTO
        }

        return MiSnapController.create(requireContext(), misnapSettings).apply {
            /**
             * Observe the [MiSnapController.feedbackResult] [LiveData] to handle the feedback from
             * the analyzed frames and handle them accordingly, e.g. by showing the corresponding
             * instructions on screen based on the [MiSnapController.FeedbackResult.userAction],
             * showing the detected document corners using [MiSnapController.FeedbackResult.corners]
             * or the detected glare corners in [MiSnapController.FeedbackResult.glareCorners].
             */
            feedbackResult.observe(viewLifecycleOwner) { feedbackResult ->

            }

            /**
             * Observe the [MiSnapController.frameResult] [LiveData] to handle the successful results
             * of a session, e.g. by collecting the barcode data in [FrameResult.BarcodeAnalysis.barcode]
             * to send it to the server.
             */
            frameResult.observe(viewLifecycleOwner) { result ->
                when (result) {
                    is FrameResult.BarcodeAnalysis -> {

                    }
                    else -> {}
                }
            }

            /**
             * Observe the [MiSnapController.errorResult] [LiveData] to handle errors during the
             * analysis of frames.
             *
             * @see [ErrorResult] for all the possible error types emitted.
             */
            errorResult.observe(viewLifecycleOwner) { result ->
                when (result) {
                    is ErrorResult.BarcodeAnalysis -> {
                    }
                    else -> {}
                }
            }
        }
    }
} 
   //sampleEnd
}
import android.os.Bundle
import android.view.View
import androidx.fragment.app.Fragment
import androidx.lifecycle.LiveData
import com.miteksystems.misnap.apputil.LicenseFetcher
import com.miteksystems.misnap.controller.MiSnapController
import com.miteksystems.misnap.controller.MiSnapController.ErrorResult
import com.miteksystems.misnap.controller.MiSnapController.FrameResult
import com.miteksystems.misnap.core.Frame
import com.miteksystems.misnap.core.MiSnapSettings
fun main() { 
   //sampleStart 
   /**
 * This example demonstrates a direct integration with MiSnap SDK's face analysis science through
 * the [MiSnapController], this type of integration is best suited for developers that want to
 * interface with the science directly and that will take care of supplying the frames themselves.
 *
 * NOTE: Ensure that the provided license has all the necessary features enabled for the target
 *  MiSnap session.
 *
 * @see com.miteksystems.misnap.examples.science for examples on how to directly interface with other
 * MiSnap SDK sciences.
 */
private class FaceAnalysis : Fragment() {

    /**
     * Fetch the Misnap SDK license.
     * Good practice: Handle the license in a way that it is remotely updatable.
     */
    private val license by lazy {  
        LicenseFetcher.fetch()
    }

    private lateinit var misnapController: MiSnapController

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        misnapController = initFaceAnalysis()

        /**
         * Call [startAnalysis] once the controller is ready to analyze [Frame]s.
         */
    }

    private fun startAnalysis(frame: Frame) {
        misnapController.analyzeFrame(frame)
    }

    /**
     * Create a [MiSnapController] capable of analyzing frames for a selfie session, then observe
     * the different [LiveData] objects to get notified about feedback results, final results, errors,
     * etc.
     * Once the controller is ready and initialized create a [Frame] object and use the [MiSnapController.analyzeFrame]
     * method to analyze the frame.
     *
     * @see com.miteksystems.misnap.examples.science.FrameFromNativeCamera for examples on how to
     * build a [Frame] object from different camera APIs.
     */
    private fun initFaceAnalysis(): MiSnapController {
        val misnapSettings = MiSnapSettings(MiSnapSettings.UseCase.FACE, license).apply {
            analysis.face.trigger = MiSnapSettings.Analysis.Face.Trigger.AUTO
        }

        return MiSnapController.create(requireContext(), misnapSettings).apply {
            /**
             * Observe the [MiSnapController.feedbackResult] [LiveData] to handle the feedback from
             * the analyzed frames and handle them accordingly, e.g. by showing the corresponding
             * instructions on screen based on the [MiSnapController.FeedbackResult.userAction] or
             * showing the detected face bounding box corners using [MiSnapController.FeedbackResult.corners].
             */
            feedbackResult.observe(viewLifecycleOwner) { feedbackResult ->

            }

            /**
             * Observe the [MiSnapController.frameResult] [LiveData] to handle the successful results
             * of a session, e.g. by collecting the frame data in [FrameResult.FaceAnalysis.frame]
             * to send it to the server.
             */
            frameResult.observe(viewLifecycleOwner) { result ->
                when (result) {
                    is FrameResult.FaceAnalysis -> {

                    }
                    else -> {}
                }
            }

            /**
             * Observe the [MiSnapController.errorResult] [LiveData] to handle errors during the
             * analysis of frames.
             *
             * @see [ErrorResult] for all the possible error types emitted.
             */
            errorResult.observe(viewLifecycleOwner) { result ->
                when (result) {
                    is ErrorResult.FaceAnalysis -> {
                    }
                    else -> {}
                }
            }
        }
    }
} 
   //sampleEnd
}

Types

Link copied to clipboard
object Companion
Link copied to clipboard
sealed class ErrorResult

Results of the analysis of a Frame that was not completed due to an error.

Link copied to clipboard
data class FeedbackResult(val userAction: UserAction, val corners: Array<IntArray> = emptyArray(), val glareCorners: Array<IntArray> = emptyArray(), val warnings: List<UserAction> = emptyList(), val metaData: MiSnapController.FeedbackResult.Metadata? = null)

Results of analyzing a Frame whose quality is not enough.

Link copied to clipboard
sealed class FrameResult

Results of analyzing a good quality Frame.

Functions

Link copied to clipboard
fun analyzeFrame(frame: Frame, forceFrameResult: Boolean = false)

Analyzes the provided Frame to evaluate whether or not the quality is sufficient.

Link copied to clipboard
fun cancel()

Cancels an ongoing Frame analysis request.

Link copied to clipboard
fun release()

Cancels an ongoing Frame analysis request and frees resources.

Properties

Link copied to clipboard

LiveData object that emits the results of an analyzed Frame that was not completed due to an error.

Link copied to clipboard

LiveData object that emits the results of an analyzed Frame that has been determined as not good enough.

Link copied to clipboard

LiveData object that emits the results of an analyzed Frame that has been determined as a good quality one.