import cv2
import numpy as np
im_m = cv2.imread("primary.png", cv2.IMREAD_GRAYSCALE)
# 50, 130
# Otsu's thresholding after Gaussian filtering
blur = cv2.GaussianBlur(im_m,(25,25),0)
#(thresh, im2) = cv2.threshold(blur,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)
# Black region overflowing into digit regions with otsu
(thresh, im) = cv2.threshold(im_m, 55, 130, cv2.THRESH_BINARY)
kernel = np.ones((5,5), np.uint8)
img_dilation = cv2.dilate(im, kernel, iterations=1)
img_erosion = cv2.erode(img_dilation, kernel, iterations=1)
params = cv2.SimpleBlobDetector_Params()
params.minThreshold = 10;
params.maxThreshold = 225;
params.filterByArea = True
params.minArea = 100
params.maxArea = 1500
params.filterByCircularity = False
params.minCircularity = 0.5
params.filterByConvexity = False
params.minConvexity = 0.2
params.filterByInertia = False
params.minInertiaRatio = 0.01
ver = (cv2.__version__).split('.')
if int(ver[0]) < 3 :
detector = cv2.SimpleBlobDetector(params)
else :
detector = cv2.SimpleBlobDetector_create(params)
keypoints = detector.detect(im)
im_key = cv2.drawKeypoints(im, keypoints, np.array([]), (0,0,255), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
cv2.imshow("Keypoints", im_key)
cv2.imshow("Erosion", img_erosion)
cv2.imshow("Dilation", img_dilation)
cv2.waitKey(0)
I am pretty new to image processing with opencv. I am trying to detect digits from a noisy image.
I did some experiments, tuning thresholds and filtering by parameters but can't detect the blobs with 3, 4, 0 and sometimes 5, 7 and 2. I just need to detect the digits. Are there any other better way than blob detection for this task?