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 and checks use case 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.
 *
 * Notes:
 * - Ensure the provided license enables the required features for your sessions.
 * - Real-Time Security is NOT compatible with controller-based science integrations.
 *
 * See also:
 * - Frame building example: com.miteksystems.misnap.examples.science.FrameFromNativeCamera
 */
class CheckAnalysis : Fragment() {
    private val license by lazy { LicenseFetcher.fetch() }
    private lateinit var misnapController: MiSnapController

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        misnapController = initCheckAnalysis()
        /**
         * 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 for check use case, 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 initCheckAnalysis(): MiSnapController {
        //Set MiSnap settings for checks (E.g., CHECK_FRONT).
        val settings = 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
        }

        return MiSnapController.create(requireContext(), settings).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) { feedback ->

            }

            /**
             * 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) { err ->
                when (err) {
                    is ErrorResult.DocumentAnalysis -> {  }
                    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 document analysis science and identity use case 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.
 *
 * Example: document analysis for IDs / Passports (science-level) using MiSnapController.
 *
 * Notes:
 * - Ensure the provided license enables the required features for your sessions.
 * - Real-Time Security is NOT compatible with controller-based science integrations.
 *
 * See also:
 * @see com.miteksystems.misnap.examples.science.FrameFromNativeCamera for examples on how to
 * build a [Frame] object from camera APIs.
 * @see com.miteksystems.misnap.examples.science for examples on how to directly interface with other
 * MiSnap SDK sciences.
 */
class IdentityDocumentAnalysis : Fragment() {
    private val license by lazy { LicenseFetcher.fetch() }
    private lateinit var misnapController: MiSnapController

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        misnapController = initDocumentAnalysisForId()
        /**
         * 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 for Id use case, 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 initDocumentAnalysisForId(): MiSnapController {
        //Set MiSnap settings for IDs (e.g., ID_FRONT / ID_BACK / PASSPORT).
        val misnapSettings = MiSnapSettings(MiSnapSettings.UseCase.ID_FRONT, license).apply {
            analysis.document.trigger = MiSnapSettings.Analysis.Document.Trigger.AUTO

            // Optional: enable on-device document classification when you need doc type inference.
            // analysis.document.enableDocumentClassification = true

            // Optional: If you integrate MRZ detection via feature-detector,
            // configure your MRZ processing pipeline accordingly
        }

        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) { feedback ->

            }

            /**
             * 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) { err ->
                when (err) {
                    is ErrorResult.DocumentAnalysis -> {

                    }
                    is ErrorResult.DocumentClassification -> { /* if classifier enabled */ }
                    is ErrorResult.DocumentDetection -> {

                    }
                    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.Barcode
import com.miteksystems.misnap.core.Frame
import com.miteksystems.misnap.core.MiSnapSettings
import com.miteksystems.misnap.core.Vds
import com.miteksystems.misnap.workflow.MiSnapFinalResult
import com.miteksystems.misnap.workflow.MiSnapFinalResult.BarcodeSession
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 depending on if it's a VDS or regular Barcode scan.
             */
            frameResult.observe(viewLifecycleOwner) { result ->
                when (result) {
                    is FrameResult.BarcodeAnalysis -> {
                        /**
                         * Recover the session data from the results.
                         * Please see [MiSnapFinalResult.BarcodeSession] for more information on the available data.
                         */
                        val jpegImageBytes = result.frame
                        val licenseExpiredNotification = result.licenseExpired
                        val mibiData = result.misnapMibiData
                        val sessionWarnings = result.warnings
                        val barcode: Barcode? = result.barcode
                        val rts = result.rts
                        /**
                         * Handle the VDS results from the barcode if a VDS barcode was scanned.
                         * Otherwise handle the results as a regular barcode session.
                         * NOTE: if the scan is a VDS, the raw barcode contents are not available.
                         */
                        barcode?.let { barcodeResult ->
                            if (barcode.isVds == true) {
                                val vdsResult: Vds? = barcodeResult.vds
                                val encryptedPayload = vdsResult?.encryptedPayload
                                val vdsHeader: Vds.VdsHeader? = vdsResult?.header
                                val country = vdsHeader?.country
                                val featureDefinitionReference = vdsHeader?.featureDefinitionReference
                                val typeCategory = vdsHeader?.typeCategory
                            } else {
                                val rawBarcode = barcode.rawBarcode
                                val encodedBarcode = barcode.encodedBarcode
                            }
                        }
                    }
                    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.