1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] How to extract the handwritten signature in a picture of a check?

Discussão em 'Python' iniciado por Stack, Setembro 27, 2024 às 15:52.

  1. Stack

    Stack Membro Participativo

    I am trying to extract a region from an image of a check sample (from the web) which contains a signature, besides other information. The said image (check sample) is as shown below.

    I am trying to extract only the signature part using the following code (from here https://stackoverflow.com/a/57383828).

    import numpy as np
    import cv2

    image = cv2.imread('chk.png')

    hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
    lower = np.array([90, 38, 0])
    upper = np.array([145, 255, 255])
    mask = cv2.inRange(hsv, lower, upper)
    result = cv2.bitwise_and(image, image, mask=mask)
    result[mask==0] = (255, 255, 255)

    # Find contours on extracted mask, combine boxes, and extract ROI
    cnts = cv2.findContours(mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
    cnts = cnts[0] if len(cnts) == 2 else cnts[1]
    cnts = np.concatenate(cnts)
    x,y,w,h = cv2.boundingRect(cnts)
    cv2.rectangle(image, (x, y), (x + w, y + h), (36,255,12), 2)
    ROI = result[y:y+h, x:x+w]

    cv2.imshow('result', result)
    cv2.imshow('mask', mask)
    cv2.imshow('image', image)
    cv2.imshow('ROI', ROI)
    cv2.waitKey()


    The resultant images are shown below.

    [​IMG]

    [​IMG]

    [​IMG]

    Is there a way to get the bounding box only around a specific area which in my case is the area reserved for the signature (marked with a blue rectangle.

    Continue reading...

Compartilhe esta Página