evaluate_localizer.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:ObjectDetection 作者: PhilippParis 项目源码 文件源码
def mask_to_objects(mask, threshold):
    """
    applies a blob detection algorithm to the image
    Args:
        mask: image mask scaled between 0 and 255 
        threshold: min pixel intensity of interest
    Returns:
        list of objects [(x,y)]
    """

    params = cv2.SimpleBlobDetector_Params()
    params.minThreshold = threshold
    params.maxThreshold = 255

    params.filterByArea = True
    params.minArea = 150
    params.maxArea = 10000

    params.filterByCircularity = False
    params.filterByInertia = False
    params.filterByConvexity = False
    params.filterByColor = False
    params.blobColor = 255

    # Create a detector with the parameters
    ver = (cv2.__version__).split('.')
    if int(ver[0]) < 3:
        detector = cv2.SimpleBlobDetector(params)
    else: 
        detector = cv2.SimpleBlobDetector_create(params)

    keypoints = detector.detect(mask)

    objects = []
    for k in keypoints:
        objects.append(Rect(int(k.pt[0] - k.size), int(k.pt[1] - k.size), int(k.size * 2), int(k.size * 2)))

    return objects
# ============================================================= #
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号