基于模式匹配的PCB基准标记检测
点击下方“AI算法与图像处理”,一起进步!
重磅干货,第一时间送达
为什么PCB需要基准标记?
预处理
# 创建一个合成基准图像
pattern_sizeHW = [args.fiducialOuterDiameterInPixels, args.fiducialOuterDiameterInPixels]
if args.fiducialOuterDiameterInPixels %2 == 0: # 确保图案大小是奇数
pattern_sizeHW[0] += 1
pattern_sizeHW[1] += 1
fiducial_pattern = np.zeros(pattern_sizeHW, dtype=np.uint8)
cv2.circle(fiducial_pattern, (pattern_sizeHW[1]//2, pattern_sizeHW[0]//2), args.fiducialOuterDiameterInPixels//2, 70, cv2.FILLED) # 外层是深灰色
cv2.circle(fiducial_pattern, (pattern_sizeHW[1]//2, pattern_sizeHW[0]//2), args.fiducialInnerDiameterInPixels//2, 255, cv2.FILLED) # 内部是白色的
# 标准化模式图像
standardized_fiducial_pattern = (fiducial_pattern.astype(np.float32) - fiducial_pattern.mean())/fiducial_pattern.std()
模式匹配
# 模式匹配
match_img = cv2.matchTemplate(grayscale_img.astype(np.float32), standardized_fiducial_pattern, cv2.TM_CCOEFF_NORMED)
# 用于可视化,填充0以获得与原始图像相同大小的图像
padded_match_8bits_img = np.zeros((img_shapeHWC[0], img_shapeHWC[1]), dtype=np.uint8)
padded_match_8bits_img[fiducial_pattern.shape[0]//2: fiducial_pattern.shape[0]//2 + match_img.shape[0],
fiducial_pattern.shape[1]//2: fiducial_pattern.shape[1]//2 + match_img.shape[1]] = (128 * (match_img + 1.0)).astype(np.uint8)
# 找到最优阈值,以检测预期的基准数
blob_detector = blob_analysis.BinaryBlobDetector()
optimal_threshold = None
optimal_seedPoint_boundingBox_list = None
optimal_annotated_blobs_img = None
for threshold in range(255, 1, -1):
_, thresholded_img = cv2.threshold(padded_match_8bits_img, threshold, 255, cv2.THRESH_BINARY)
# 计算blobs的数量
seedPoint_boundingBox_list, annotated_blobs_img = blob_detector.DetectBlobs(thresholded_img)
logging.info("threshold = {}; len(seedPoint_boundingBox_list) = {}".format(threshold, len(seedPoint_boundingBox_list) ))
if len(seedPoint_boundingBox_list) >= args.numberOfFiducials:
optimal_threshold = threshold
optimal_seedPoint_boundingBox_list = seedPoint_boundingBox_list
optimal_annotated_blobs_img = annotated_blobs_img
break
logging.info("The optimal match threshold is {}. The number of found blobs is {}".format(optimal_threshold, len(optimal_seedPoint_boundingBox_list)))
变换矩阵的计算
交流群
欢迎加入公众号读者群一起和同行交流,目前有美颜、三维视觉、计算摄影、检测、分割、识别、医学影像、GAN、算法竞赛等微信群
个人微信(如果没有备注不拉群!) 请注明:地区+学校/企业+研究方向+昵称
下载1:何恺明顶会分享
在「AI算法与图像处理」公众号后台回复:何恺明,即可下载。总共有6份PDF,涉及 ResNet、Mask RCNN等经典工作的总结分析
下载2:终身受益的编程指南:Google编程风格指南
在「AI算法与图像处理」公众号后台回复:c++,即可下载。历经十年考验,最权威的编程规范!
下载3 CVPR2021 在「AI算法与图像处理」公众号后台回复:CVPR,即可下载1467篇CVPR 2020论文 和 CVPR 2021 最新论文
评论