I have this image: raw
I want to remove the square brackets from this image. I've come so far:
# Import packages
import cv2
import numpy as np
#Create MSER object
mser = cv2.MSER_create()
#Your image path i-e receipt path
img = cv2.imread('uky.JPG')
#Convert to gray scale
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
vis = img.copy()
#detect regions in gray scale image
regions, _ = mser.detectRegions(gray)
hulls = [cv2.convexHull(p.reshape(-1, 1, 2)) for p in regions]
cv2.polylines(vis, hulls, 1, (0, 255, 0))
cv2_imshow(vis)
mask = np.zeros((img.shape[0], img.shape[1], 1), dtype=np.uint8)
for contour in hulls:
cv2.drawContours(mask, [contour], -1, (255, 255, 255), -1)
#this is used to find only text regions, remaining are ignored
text_only = cv2.bitwise_and(img, img, mask=mask)
cv2_imshow(text_only)
Result of this code: detected
Expected output: expected
But I couldn't figure out how to remove the square brackets. I'm sure that it's so simple question but since I'm not familiar with OpenCV I couldn't solve this problem for hours.
If somebody could explain this to me, I'd be much glad. Thank you very much in advance.


