Git Product home page Git Product logo

pisahkan-ktp's Introduction

PISAHKAN KTP: Indonesian ID Card (KTP) Information Segmentation

Beautiful Landscape

About

pisahkan_ktp is a Python function that extracts province, NIK, and personal information from an image of an Indonesian National Identity Card (KTP). It utilizes image processing techniques to locate and isolate relevant sections of the KTP image, then extracts text data accurately. The extracted information is returned in a structured format, facilitating further processing or integration into other applications.

Requirements

  • Python 3.7 or Higher
  • numpy
  • opencv-python
  • opencv-contrib-python
  • pythonRLSA

Key Features

  • Extracts province, NIK, and personal information from Indonesian National Identity Card (KTP) images.
  • Utilizes image processing techniques to locate and isolate relevant sections accurately.
  • Returns extracted information in a structured format for easy integration and further processing.

Usage

Manual Installation via Github

  1. Clone Repository
    git clone https://github.com/hanifabd/pisahkan-ktp
    
  2. Installation
    cd pisahkan-ktp && pip install dist/pisahkan_ktp-0.2.11-py3-none-any.whl
    

Installation Using Pip

  1. Installation
    pip install pisahkan-ktp

Inference

  1. Usage

    • Text Area

      • Standard Segmenter

        # Input ==> Image Path
        from pisahkan_ktp.ktp_segmenter import segmenter
        
        image_path = "./tests/sample.jpg"
        result = segmenter(image_path)
        print(result)
        
        # Input ==> Numpy Array Image ==> cv2.imread(image_path)
        from pisahkan_ktp.ktp_segmenter import segmenter_ndarray
        
        image_path = "./tests/sample.jpg"
        image = cv2.imread(image_path)
        result = segmenter_ndarray(image)
        print(result)
      • Adaptive Segmenter (Adjust contrast level in preprocessing)

        # Input ==> Image Path
        from pisahkan_ktp.ktp_segmenter import adaptive_segmenter
        
        image_path = "./tests/sample.jpg"
        result = adaptive_segmenter(image_path, contrast_factor=1.7, delta_contrast=0.7, gamma_factor=1.0)
        print(result)
        
        # Input ==> Numpy Array Image ==> cv2.imread(image_path)
        from pisahkan_ktp.ktp_segmenter import adaptive_segmenter_ndarray
        
        image_path = "./tests/sample.jpg"
        image = cv2.imread(image_path)
        result = adaptive_segmenter_ndarray(image, contrast_factor=1.7, delta_contrast=0.7, gamma_factor=1.0)
        print(result)
    • Pass-Photo & Signature

      # Input ==> Image Path
      from pisahkan_ktp.ktp_segmenter import getPassPhoto, getSignature
      
      image_path = "./tests/sample.jpg"
      result = getPassPhoto(image_path)
      # Output Image Numpy Array
      
      # Input ==> Numpy Array Image ==> cv2.imread(image_path)
      from pisahkan_ktp.ktp_segmenter import getPassPhotoNdarray, getSignatureNdarray
      
      image_path = "./tests/sample.jpg"
      image = cv2.imread(image_path)
      result = getPassPhotoNdarray(image)
      # Output Image Numpy Array

    NOTE!!! Input image must be a clear Indonesian ID Card (KTP) no/less background noise for optimal performance

  2. Result Text Area

    {
        "image": [originalImage],
        "provinsiArea": [segmented_provinsi_img_matrix_list],
        "nikArea": [segmented_nik_img_matrix_list],
        "detailArea": [segmented_detail_img_matrix_list],
    }
  3. Preview

    • Original Image

      Beautiful Landscape
    • Provinsi Area Cropped

      Beautiful Landscape
    • NIK Area Cropped

      Beautiful Landscape
    • Detail Area Cropped

      Beautiful Landscape

How to Show in Matplotlib

Input ==> Image Path

from pisahkan_ktp.ktp_segmenter import segmenter
import matplotlib.pyplot as plt
import cv2

def show_result(result_dict):
    num_boxes = len(result_dict)
    fig, axes = plt.subplots(num_boxes, 1)
    if num_boxes == 1:
        axes = [axes]
    for i, bbox in enumerate(result_dict):
        ax = axes[i]
        if bbox.size:
            ax.imshow(cv2.cvtColor(bbox, cv2.COLOR_BGR2RGB))
            ax.axis('off')
    plt.tight_layout()
    plt.show()

image_path = "./tests/sample.jpg"
result = segmenter(image_path)

# Close pop up window first to see other result -> VSCODE
show_result(result["provinsiArea"])
show_result(result["nikArea"])
show_result(result["detailArea"])

Input ==> Numpy Array Image ==> cv2.imread(image_path)

from pisahkan_ktp.ktp_segmenter import segmenter_ndarray
import matplotlib.pyplot as plt
import cv2

def show_result(result_dict):
    num_boxes = len(result_dict)
    fig, axes = plt.subplots(num_boxes, 1)
    if num_boxes == 1:
        axes = [axes]
    for i, bbox in enumerate(result_dict):
        ax = axes[i]
        if bbox.size:
            ax.imshow(cv2.cvtColor(bbox, cv2.COLOR_BGR2RGB))
            ax.axis('off')
    plt.tight_layout()
    plt.show()

image_path = "./tests/sample.jpg"
image = cv2.imread(image_path)
result = segmenter_ndarray(image)

# Close pop up window first to see other result
show_result(result["provinsiArea"])
show_result(result["nikArea"])
show_result(result["detailArea"])

pisahkan-ktp's People

Stargazers

Farrel Jonathan Vickeldo avatar AlbirrKarim avatar

Watchers

Hanif Yuli Abdillah P 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.