Is 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.
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With