有没有办法在使用python的pcb板中找到矩形?我的目标是找到pcb组件 . 我试图平滑图片,然后应用cunny边缘和轮廓检测,但我设法找到的唯一正确的轮廓是板周围的轮廓 . 有没有办法找到电路板的组件并在它们周围画一个矩形?任何帮助将非常感谢!谢谢!

UPDATE

我使用的代码是关于尝试根据颜色找到轮廓 .

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)

enter image description here

enter image description here

它打印出已找到322个轮廓,这就是问题所在 . 我只需要8个最大的 . 有没有办法只采取面积最大的那些?或者我可能首先要处理图像以获得更好的效果?