点击下方卡片,关注“机器视觉与AI深度学习”
视觉/图像重磅干货,第一时间送达!

https://github.com/sebastiengilbert73/pattern_matching_tutorial为什么 PCB 需要基准标记?
在 PCB 组装过程中,自动化系统会将分立元件(芯片、电容器、连接器等)放置在 PCB 上的相应位置,然后再焊接到焊盘上。基准标记的检测允许将元件精确放置在 PCB 上。放置后,自动检查系统将检查所有元件是否都放置在应在的位置并放置在公差范围内。同样,基准标记将提供将物理点从 PCB 图纸(以毫米为单位)转换为图像点(以像素为单位)所需的参考点。


# Create a synthetic fiducial imagepattern_sizeHW = [args.fiducialOuterDiameterInPixels, args.fiducialOuterDiameterInPixels]if args.fiducialOuterDiameterInPixels %2 == 0: # Make sure the pattern size is oddpattern_sizeHW[0] += 1pattern_sizeHW[1] += 1fiducial_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) # The outer disk is dark graycv2.circle(fiducial_pattern, (pattern_sizeHW[1]//2, pattern_sizeHW[0]//2), args.fiducialInnerDiameterInPixels//2, 255, cv2.FILLED) # The inner disk is white# Standardize the pattern imagestandardized_fiducial_pattern = (fiducial_pattern.astype(np.float32) - fiducial_pattern.mean())/fiducial_pattern.std()

# Pattern matchmatch_img = cv2.matchTemplate(grayscale_img.astype(np.float32), standardized_fiducial_pattern, cv2.TM_CCOEFF_NORMED)# Create an 8-bit version of the match image for visualization, padded with zeros to get an image the same size as the originalpadded_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)

# Find the optimal threshold to detect the expected number of fiducialsblob_detector = blob_analysis.BinaryBlobDetector()optimal_threshold = Noneoptimal_seedPoint_boundingBox_list = Noneoptimal_annotated_blobs_img = Nonefor threshold in range(255, 1, -1):_, thresholded_img = cv2.threshold(padded_match_8bits_img, threshold, 255, cv2.THRESH_BINARY)# Count the number of blobsseedPoint_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 = thresholdoptimal_seedPoint_boundingBox_list = seedPoint_boundingBox_listoptimal_annotated_blobs_img = annotated_blobs_imgbreaklogging.info("The optimal match threshold is {}. The number of found blobs is {}".format(optimal_threshold, len(optimal_seedPoint_boundingBox_list)))


—THE END— 
觉得有用,麻烦给个赞和在看

觉得有用,麻烦给个赞和在看
夜雨聆风