pisahkan-ktp


Namepisahkan-ktp JSON
Version 0.2.10 PyPI version JSON
download
home_pagehttps://github.com/hanifabd/pisahkan-ktp
SummaryPython package for detecting entities in text based on a dictionary and fuzzy similarity
upload_time2024-05-14 06:45:33
maintainerNone
docs_urlNone
authorHanif Yuli Abdillah P
requires_python>=3.7
licenseNone
keywords ktp segmentation segmentasi id-card identity-card
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # **PISAHKAN KTP: Indonesian ID Card (KTP) Information Segmentation**

<center><img src="./assets/OIG1.jpg" alt="Beautiful Landscape" width="250"></center>


## **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 .
    ```
### Installation Using Pip
1. Installation
    ```sh
    pip install pisahkan-ktp
    ```
### Inference
1. Usage
    - Text Area
        - Standard Segmenter
            ```py
            # 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)
            ```py
            # 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
        ```py
        # 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

3. Result Text Area
    ```json
    {
        "image": [originalImage],
        "provinsiArea": [segmented_provinsi_img_matrix_list],
        "nikArea": [segmented_nik_img_matrix_list],
        "detailArea": [segmented_detail_img_matrix_list],
    }
    ```

4. Preview
    - Original Image

        <img src="./tests/sample.jpg" alt="Beautiful Landscape" width="500">

    - Provinsi Area Cropped
        
        <img src="./assets/8-5-provinsi.jpg" alt="Beautiful Landscape" width="500">
    
    - NIK Area Cropped
        
        <img src="./assets/8-6-nik.jpg" alt="Beautiful Landscape" width="500">

    - Detail Area Cropped
        
        <img src="./assets/8-7-detail.jpg" alt="Beautiful Landscape" width="500">

## How to Show in Matplotlib
### Input ==> Image Path
```py
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)
```py
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"])
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/hanifabd/pisahkan-ktp",
    "name": "pisahkan-ktp",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "ktp, segmentation, segmentasi, id-card, identity-card",
    "author": "Hanif Yuli Abdillah P",
    "author_email": "hanifabd23@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/7a/ba/efaba7df0f7035fc00ec27a28a6a703ced05e4ac74d5f61e493f61af4a1b/pisahkan_ktp-0.2.10.tar.gz",
    "platform": null,
    "description": "# **PISAHKAN KTP: Indonesian ID Card (KTP) Information Segmentation**\n\n<center><img src=\"./assets/OIG1.jpg\" alt=\"Beautiful Landscape\" width=\"250\"></center>\n\n\n## **About**\n`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.\n\n## **Requirements**\n- Python 3.7 or Higher\n- numpy\n- opencv-python\n- opencv-contrib-python\n- pythonRLSA\n\n## **Key Features**\n- Extracts province, NIK, and personal information from Indonesian National Identity Card (KTP) images.\n- Utilizes image processing techniques to locate and isolate relevant sections accurately.\n- Returns extracted information in a structured format for easy integration and further processing.\n\n## Usage\n### Manual Installation via Github\n1. Clone Repository\n    ```\n    git clone https://github.com/hanifabd/pisahkan-ktp\n    ```\n2. Installation\n    ```\n    cd pisahkan-ktp && pip install .\n    ```\n### Installation Using Pip\n1. Installation\n    ```sh\n    pip install pisahkan-ktp\n    ```\n### Inference\n1. Usage\n    - Text Area\n        - Standard Segmenter\n            ```py\n            # Input ==> Image Path\n            from pisahkan_ktp.ktp_segmenter import segmenter\n\n            image_path = \"./tests/sample.jpg\"\n            result = segmenter(image_path)\n            print(result)\n\n            # Input ==> Numpy Array Image ==> cv2.imread(image_path)\n            from pisahkan_ktp.ktp_segmenter import segmenter_ndarray\n\n            image_path = \"./tests/sample.jpg\"\n            image = cv2.imread(image_path)\n            result = segmenter_ndarray(image)\n            print(result)\n            ```\n        \n        - Adaptive Segmenter (Adjust contrast level in preprocessing)\n            ```py\n            # Input ==> Image Path\n            from pisahkan_ktp.ktp_segmenter import adaptive_segmenter\n    \n            image_path = \"./tests/sample.jpg\"\n            result = adaptive_segmenter(image_path, contrast_factor=1.7, delta_contrast=0.7, gamma_factor=1.0)\n            print(result)\n    \n            # Input ==> Numpy Array Image ==> cv2.imread(image_path)\n            from pisahkan_ktp.ktp_segmenter import adaptive_segmenter_ndarray\n    \n            image_path = \"./tests/sample.jpg\"\n            image = cv2.imread(image_path)\n            result = adaptive_segmenter_ndarray(image, contrast_factor=1.7, delta_contrast=0.7, gamma_factor=1.0)\n            print(result)\n            ```\n\n    - Pass-Photo & Signature\n        ```py\n        # Input ==> Image Path\n        from pisahkan_ktp.ktp_segmenter import getPassPhoto, getSignature\n\n        image_path = \"./tests/sample.jpg\"\n        result = getPassPhoto(image_path)\n        # Output Image Numpy Array\n\n        # Input ==> Numpy Array Image ==> cv2.imread(image_path)\n        from pisahkan_ktp.ktp_segmenter import getPassPhotoNdarray, getSignatureNdarray\n\n        image_path = \"./tests/sample.jpg\"\n        image = cv2.imread(image_path)\n        result = getPassPhotoNdarray(image)\n        # Output Image Numpy Array\n        ```\n    > NOTE!!! Input image must be a clear Indonesian ID Card (KTP) no/less background noise for optimal performance\n\n3. Result Text Area\n    ```json\n    {\n        \"image\": [originalImage],\n        \"provinsiArea\": [segmented_provinsi_img_matrix_list],\n        \"nikArea\": [segmented_nik_img_matrix_list],\n        \"detailArea\": [segmented_detail_img_matrix_list],\n    }\n    ```\n\n4. Preview\n    - Original Image\n\n        <img src=\"./tests/sample.jpg\" alt=\"Beautiful Landscape\" width=\"500\">\n\n    - Provinsi Area Cropped\n        \n        <img src=\"./assets/8-5-provinsi.jpg\" alt=\"Beautiful Landscape\" width=\"500\">\n    \n    - NIK Area Cropped\n        \n        <img src=\"./assets/8-6-nik.jpg\" alt=\"Beautiful Landscape\" width=\"500\">\n\n    - Detail Area Cropped\n        \n        <img src=\"./assets/8-7-detail.jpg\" alt=\"Beautiful Landscape\" width=\"500\">\n\n## How to Show in Matplotlib\n### Input ==> Image Path\n```py\nfrom pisahkan_ktp.ktp_segmenter import segmenter\nimport matplotlib.pyplot as plt\nimport cv2\n\ndef show_result(result_dict):\n    num_boxes = len(result_dict)\n    fig, axes = plt.subplots(num_boxes, 1)\n    if num_boxes == 1:\n        axes = [axes]\n    for i, bbox in enumerate(result_dict):\n        ax = axes[i]\n        if bbox.size:\n            ax.imshow(cv2.cvtColor(bbox, cv2.COLOR_BGR2RGB))\n            ax.axis('off')\n    plt.tight_layout()\n    plt.show()\n\nimage_path = \"./tests/sample.jpg\"\nresult = segmenter(image_path)\n\n# Close pop up window first to see other result -> VSCODE\nshow_result(result[\"provinsiArea\"])\nshow_result(result[\"nikArea\"])\nshow_result(result[\"detailArea\"])\n```\n\n### Input ==> Numpy Array Image ==> cv2.imread(image_path)\n```py\nfrom pisahkan_ktp.ktp_segmenter import segmenter_ndarray\nimport matplotlib.pyplot as plt\nimport cv2\n\ndef show_result(result_dict):\n    num_boxes = len(result_dict)\n    fig, axes = plt.subplots(num_boxes, 1)\n    if num_boxes == 1:\n        axes = [axes]\n    for i, bbox in enumerate(result_dict):\n        ax = axes[i]\n        if bbox.size:\n            ax.imshow(cv2.cvtColor(bbox, cv2.COLOR_BGR2RGB))\n            ax.axis('off')\n    plt.tight_layout()\n    plt.show()\n\nimage_path = \"./tests/sample.jpg\"\nimage = cv2.imread(image_path)\nresult = segmenter_ndarray(image)\n\n# Close pop up window first to see other result\nshow_result(result[\"provinsiArea\"])\nshow_result(result[\"nikArea\"])\nshow_result(result[\"detailArea\"])\n```\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Python package for detecting entities in text based on a dictionary and fuzzy similarity",
    "version": "0.2.10",
    "project_urls": {
        "Homepage": "https://github.com/hanifabd/pisahkan-ktp",
        "Repository": "https://github.com/hanifabd/pisahkan-ktp"
    },
    "split_keywords": [
        "ktp",
        " segmentation",
        " segmentasi",
        " id-card",
        " identity-card"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "acf29c34e40d03e135c07192e1522c1d1ce002df81b470faed7fe9378e86789c",
                "md5": "03cd3e020f52ff0fcc5f7adc5b77c4dc",
                "sha256": "466ee1a591dbfaa09af0b2a20805a9c26792aa3758ef8750b2aef100ad86a0ee"
            },
            "downloads": -1,
            "filename": "pisahkan_ktp-0.2.10-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "03cd3e020f52ff0fcc5f7adc5b77c4dc",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 7710,
            "upload_time": "2024-05-14T06:45:31",
            "upload_time_iso_8601": "2024-05-14T06:45:31.401797Z",
            "url": "https://files.pythonhosted.org/packages/ac/f2/9c34e40d03e135c07192e1522c1d1ce002df81b470faed7fe9378e86789c/pisahkan_ktp-0.2.10-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7abaefaba7df0f7035fc00ec27a28a6a703ced05e4ac74d5f61e493f61af4a1b",
                "md5": "a32d0ffa294f77d9700ac9f1d6d31784",
                "sha256": "3cf355f15d2a8d396bdb5ad731756168d587039b40a654261b37b3cdbb332edc"
            },
            "downloads": -1,
            "filename": "pisahkan_ktp-0.2.10.tar.gz",
            "has_sig": false,
            "md5_digest": "a32d0ffa294f77d9700ac9f1d6d31784",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 8062,
            "upload_time": "2024-05-14T06:45:33",
            "upload_time_iso_8601": "2024-05-14T06:45:33.188996Z",
            "url": "https://files.pythonhosted.org/packages/7a/ba/efaba7df0f7035fc00ec27a28a6a703ced05e4ac74d5f61e493f61af4a1b/pisahkan_ktp-0.2.10.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-14 06:45:33",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "hanifabd",
    "github_project": "pisahkan-ktp",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "pisahkan-ktp"
}
        
Elapsed time: 0.27232s