Quantcast
Channel: OpenCV Q&A Forum - RSS feed
Viewing all articles
Browse latest Browse all 2088

How to merge rectangles of matchTemplate?

$
0
0
Good morning. I'm with some trouble with this code. I want to check if the PCB is ok with manual insertions, i found some codes to check this with a template, ok. But when the componentes are found, the code create some rectangles, but sometimes, create overlap rectangles, here is the code. [C:\fakepath\azul.png](/upfiles/15887724695566471.png) [C:\fakepath\PlacaBoa.png](/upfiles/15887725088295845.png) import cv2 import numpy as np img_rgb = cv2.imread('placaboa.png') img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY) #Azul azul = cv2.imread('azul.png',0) w, h = azul.shape[::-1] res = cv2.matchTemplate(img_gray, azul, cv2.TM_CCOEFF_NORMED) threshold = 0.75 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), 2) cv2.imshow('Detected',img_rgb) cv2.waitKey(0) cv2.destroyAllWindows()

Viewing all articles
Browse latest Browse all 2088

Trending Articles