I need to identify the following dots in the given images. But it doesn't give correct detection. Can someone give a methodology to identify these dots in an image like this?
I have done some enhancement to this as follows,
enhanced image, by dilation followed by sharpened
I Used template matching for detecting these dots in the image. But it didn't work well. Code is as follows. Is there any other way to detect these?
import cv2 import numpy as np
img_rgb = cv2.imread(file)
cv2.imwrite("D:/4/Detect/"+str(i)+".0.jpg",img_rgb)
img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
template = cv2.imread('a.jpg',0)
w, h = template.shape[::-1]
res = cv2.matchTemplate(img_gray,template,cv2.TM_CCOEFF_NORMED)
threshold = 0.455
loc = np.where( res >= threshold)
for pt in zip(*loc[::-1]):
cv2.rectangle(img_rgb, pt, (pt[0] + w, pt[1] + h), (0,255,255), 0)
cv2.imshow('Detected',img_rgb)
cv2.imwrite("D:/4/Detect/"+str(i)+".1.jpg",img_rgb)
cv2.waitKey(0)
cv2.destroyAllWindows()
Here's the main part of the code for better result (shown in the image below), that I developed quickly:
Tune the parameters for desired result.