Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting non-textual data from an image: Python

Tags:

python

opencv

enter image description hereIs there any way I can extract non-textual data from an image which has text as well? I have an image of let's say a letter which has text as well as a signature and logo. I would like to extract just the sign and logo or rather remove every thing which is textual. Is there any way of doing it? Thanks in advance.

like image 495
AIMCognitiveGurgaon BigData Avatar asked Sep 20 '25 01:09

AIMCognitiveGurgaon BigData


1 Answers

python solution:

import cv2
image = cv2.imread("test.png", 1)
img = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
cv2.threshold(img,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU,img)
cv2.bitwise_not(img,img)
rect_kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (30, 5))
img = cv2.morphologyEx(img, cv2.MORPH_CLOSE, rect_kernel)
im2, contours, hier = cv2.findContours(img, cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_NONE)

if len(contours) != 0:
    for c in contours:
        x,y,w,h = cv2.boundingRect(c)
        if(h>20):
            cv2.rectangle(image,(x,y),(x+w,y+h),(0,0,255),1)

cv2.imshow("Result", image)
cv2.waitKey(0)

RESULT:

enter image description here

like image 147
Ishara Madhawa Avatar answered Sep 21 '25 16:09

Ishara Madhawa