Is there any way to find rectangles in a pcb board using python? My goal is to find the pcb components. I tried to smooth the picture and then apply cunny edge and contour detection but the only correct contour that i managed to find is the contour around the board. Is there any way to find the components of the board and draw a rectangle around them? Any help will be highly appreciated! Thank you!
UPDATE
The code i used is about trying to find contours based on color.
import numpy as np
import cv2
from matplotlib import pyplot as plt
im = cv2.imread('img14.jpg')
#gray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
#ret, thresh = cv2.threshold(gray, 80, 255, 0)
#blur = cv2.bilateralFilter(img,9,75,75)
kernel = np.ones((5,5),np.float32)/25
dst = cv2.filter2D(im,-1,kernel)
# find all the 'black' shapes in the image
lower = np.array([0, 0, 0])
upper = np.array([100, 100, 100])
shapeMask = cv2.inRange(dst, lower, upper)
(cnts, _) = cv2.findContours(shapeMask.copy(), cv2.RETR_EXTERNAL,
cv2.CHAIN_APPROX_SIMPLE)
print "I found %d black shapes" % (len(cnts))
for c in cnts:
cv2.drawContours(im, [c], -1, (0, 255, 0), 2)
cv2.imshow('shapemask', shapeMask)
cv2.imshow('contours', im)
cv2.waitKey(0)
it print that 322 contours have been found and that's the problem. I need only the 8 biggest. Is there any way to take only those with the biggest area? Or maybe i have to process the image first for better results?