Coder Social home page Coder Social logo

jama5262 / mpesa-biz-no-detector Goto Github PK

View Code? Open in Web Editor NEW
33.0 2.0 7.0 17.51 MB

An android detection library that uses Azure Computer Vision Read API to detect MPESA business and/or account numbers from images

Home Page: https://jitpack.io/#jama5262/MPESA-Biz-No-Detector

Kotlin 100.00%
azure mpesa android-library object-detection-and-tracking kotlin android-detection-library

mpesa-biz-no-detector's Introduction

MPESA-Biz-No-Detector

License: MIT

An android detection library that uses Azure Computer Vision Read API to detect MPESA business and/or account numbers from images

Demos

Start Vision Activity Pass a Bitmap

Prerequisite

  • Understanding of Microsoft Azure Cloud Service
  • An Azure subscription - Create one for free
  • Once you have your Azure subscription, create a Computer Vision resource in the Azure portal to get your key and endpoint. After it deploys, click Go to resource. You will need the key and endpoint from the resource you created to connect your application to the Computer Vision service. You can use the free pricing tier (F0) to try the service, and upgrade later to a paid tier for production.

Installation

Current Version:

Gradle

Add the following

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}
dependencies {
    implementation 'com.github.jama5262:MPESA-Biz-No-Detector:1.0.0'
}

Maven

<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>
<dependency>
    <groupId>com.github.jama5262</groupId>
    <artifactId>MPESA-Biz-No-Detector</artifactId>
    <version>1.0.0</version>
</dependency>

Great the project has been setup ๐Ÿ‘

Usage

There are a two ways you can use the library. Either:-

  1. Start a vision activity
  2. Pass your own bitmap image

Start vision activity

Add Permissions to Manifest

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />

Initialize MPESABizNoDetector by passing your Azure Vision credentials

const val CAMERA_REQUEST_CODE = 1

private val mpesaBizNoDetector = MPESABizNoDetector(
    "YOUR_AZURE_VISION_ENDPOINT",
    "YOUR_AZURE_VISION_KEY"
)

Start MPESABizNoDetectorActivity using the following code

//Make sure you have requested the user for CAMERA permission before continuing

private fun startVisionActivity() {
    mpesaBizNoDetector.startActivity(this@YourActivityClass, CAMERA_REQUEST_CODE)
}

// You can also start the `MPESABizNoDetectorActivity` from a Fragment. See below
private fun startVisionActivity() {
    mpesaBizNoDetector.startActivity(this@YourFragmentClass, CAMERA_REQUEST_CODE)
}

Override onActivityResult method in your activity or fragment to get the detected business number result

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    super.onActivityResult(requestCode, resultCode, data)
    if (requestCode == CAMERA_REQUEST_CODE) {
        if (resultCode == Activity.RESULT_OK) {
            val detectedBizNo = MPESABizNoDetector.getActivityResult(data!!)

            val type = detectedBizNo.type // TILL_NUMBER or PAYBILL
            val businessNo = detectedBizNo.businessNo
            // The account number can return null if the type is TILL_NUMBER or
            // no account number was detected in the image
            val accountNo = detectedBizNo.accountNo // Can return null
        }
    }
}

Pass your own bitmap image

Add Permissions to Manifest

<uses-permission android:name="android.permission.INTERNET" />

Initialize MPESABizNoDetector by passing your Azure Vision credentials

private val mpesaBizNoDetector = MPESABizNoDetector(
    "YOUR_AZURE_VISION_ENDPOINT",
    "YOUR_AZURE_VISION_KEY"
)

To detect from a bitmap image, use the following code

private suspend fun detectFromBitmapImage() {
    try {
        val bitmap = getBitmap() // Your bitmap image
        val detectedBizNo = mpesaBizNoDetector.detect(bitmap)
    } catch (e: VisionException) {
        //Vision detection failed, request user to try again
        Log.e(TAG, "Vision Error -> ${e.message}")
    } catch (e: BizNoSearchException) {
        //Image read detected but could not find a valid MPESA
        //business or account number from the image.
        //Request user to try another image and try again
        Log.e(TAG, "Biz number search error -> ${e.message}")
    } catch (e: Exception) {
        //Unknown error occured
        Log.e(TAG, "Error found -> ${e.message}")
    }
}

Support

Reach out to me at one of the following places!

License

MIT License

Copyright (c) 2020 Jama Mohamed

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

mpesa-biz-no-detector's People

Contributors

jama5262 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.