Removing or preventing duplicate template matches in OpenCV with Python -
I have a map on which there are similar symbols spread across the map. I am using OpenCV to find X, Y coordinates of all symbols.
It is less well-working, but I'm getting duplicate results in a large number that I number of duplicated by many symbols increases filter threshold I I results based on proximity I tried to write some code to filter but I'm not fortunate enough. Anyone have any info in what I can try here?
img_rgb = cv2.imread ( 'images / map.jpg') img_gray = cv2.cvtColor (img_rgb, cv2.COLOR_BGR2GRAY) template = cv2.imread ( 'images / tree.jpg', 0) W, h = template.shape [:: - 1] Race = cv2.matchTemplate (img_gray, template, cv2.TM_CCOEFF_NORMED) pt_count border = 0.35 matches = np.where (RAC & gt; = threshold) match = at 0 pt: tree_count + = 1 cv2.rectangle (Aimji_arjibi, PT (PT [0] + W, PT [1] + H), (255,0,0), 1) cv2.imwrite ( 'found_map.jpg ', Img_rgb) print "end" + map
I think of two options Can
-
result Do outline of the image, unless you have to be not only points. This module has many functions. For example OpenCV and schemaz
-
Using the image of the result, you can try to calculate the figure and draw it inside each contour.
Without some sample data, it is difficult to say what would be the best option. Different data often requires different methods
Comments
Post a Comment