Python cv2 模块,SimpleBlobDetector_Params() 实例源码

我们从Python开源项目中,提取了以下8个代码示例,用于说明如何使用cv2.SimpleBlobDetector_Params()

项目:Robo-Plot    作者:JackBuck    | 项目源码 | 文件源码
def _extract_spots(self) -> None:
        # Dilate and Erode to 'clean' the spot (nb that this harms the number itself, so we only do it to extract spots)
        kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (3, 3))
        img = cv2.dilate(self._img, kernel, iterations=1)
        img = cv2.erode(img, kernel, iterations=2)
        img = cv2.dilate(img, kernel, iterations=1)

        # Perform a simple blob detect
        params = cv2.SimpleBlobDetector_Params()
        params.filterByArea = True
        params.minArea = 20  # The dot in 20pt font has area of about 30
        params.filterByCircularity = True
        params.minCircularity = 0.7
        params.filterByConvexity = True
        params.minConvexity = 0.8
        params.filterByInertia = True
        params.minInertiaRatio = 0.4
        detector = cv2.SimpleBlobDetector_create(params)
        self.spot_keypoints = detector.detect(img)

        # Log intermediate image
        img_with_keypoints = cv2.drawKeypoints(img, self.spot_keypoints, outImage=np.array([]), color=(0, 0, 255),
                                               flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
        self.intermediate_images.append(NamedImage(img_with_keypoints, 'Spot Detection Image'))
项目:dream2016_dm    作者:lishen    | 项目源码 | 文件源码
def create_blob_detector(roi_size=(128, 128), blob_min_area=3, 
                         blob_min_int=.5, blob_max_int=.95, blob_th_step=10):
    params = cv2.SimpleBlobDetector_Params()
    params.filterByArea = True
    params.minArea = blob_min_area
    params.maxArea = roi_size[0]*roi_size[1]
    params.filterByCircularity = False
    params.filterByColor = False
    params.filterByConvexity = False
    params.filterByInertia = False
    # blob detection only works with "uint8" images.
    params.minThreshold = int(blob_min_int*255)
    params.maxThreshold = int(blob_max_int*255)
    params.thresholdStep = blob_th_step
    ver = (cv2.__version__).split('.')
    if int(ver[0]) < 3:
        return cv2.SimpleBlobDetector(params)
    else:
        return cv2.SimpleBlobDetector_create(params)
项目:CS412_ComputerVision    作者:Tmbao    | 项目源码 | 文件源码
def get_detector(detector_name, params):

  if detector_name == 'harris':
    detector = harris.HarrisDetector(
      params['quality_level'],
      params['block_size'],
      params['aperture_size'],
      params['alpha'],
      params['feature_size'])
  elif detector_name == 'blob':
    blob_params = cv2.SimpleBlobDetector_Params()
    blob_params.filterByArea = params['filter_by_area']
    blob_params.minArea = params['min_area']
    blob_params.maxArea = params['max_area']
    blob_params.minThreshold = params['min_threshold']
    blob_params.maxThreshold = params['max_threshold']
    blob_params.filterByColor = params['filter_by_color'];
    blob_params.blobColor = params['blob_color'];
    blob_params.filterByCircularity = params['filter_by_circularity'] 
    blob_params.minCircularity = params['min_circularity']
    blob_params.filterByConvexity = params['filter_by_convexity']
    blob_params.minConvexity = params['min_convexity']
    blob_params.filterByInertia = params['filter_by_inertia']
    blob_params.minInertiaRatio = params['min_inertia_ratio']
    detector = cv2.SimpleBlobDetector_create(blob_params)
  elif detector_name == 'dog':
    detector = cv2.xfeatures2d.SIFT_create(
      params['n_features'],
      params['n_octave_layers'],
      params['contrast_threshold'],
      params['edge_threshold'],
      params['sigma'])

  return detector
项目:cozmo_beyond    作者:PeterMitrano    | 项目源码 | 文件源码
def __find_blobs(input, min_area, circularity, dark_blobs):
        """Detects groups of pixels in an image.
        Args:
            input: A numpy.ndarray.
            min_area: The minimum blob size to be found.
            circularity: The min and max circularity as a list of two numbers.
            dark_blobs: A boolean. If true looks for black. Otherwise it looks for white.
        Returns:
            A list of KeyPoint.
        """
        params = cv2.SimpleBlobDetector_Params()
        params.filterByColor = 1
        params.blobColor = (0 if dark_blobs else 255)
        params.minThreshold = 10
        params.maxThreshold = 220
        params.filterByArea = True
        params.minArea = min_area
        params.filterByCircularity = True
        params.minCircularity = circularity[0]
        params.maxCircularity = circularity[1]
        params.filterByConvexity = False
        params.filterByInertia = False
        detector = cv2.SimpleBlobDetector_create(params)
        return detector.detect(input)
项目:reconstruction    作者:microelly2    | 项目源码 | 文件源码
def execute_BlobDetector(proxy,obj):

    try: img=obj.sourceObject.Proxy.img.copy()
    except: img=cv2.imread(__dir__+'/icons/freek.png')

    im = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    im=255-im
    im2 = img

    params = cv2.SimpleBlobDetector_Params()

    params.filterByArea = True
    params.minArea = obj.Area

    params.filterByConvexity = True
    params.minConvexity = obj.Convexity/200


    # Set up the detector with default parameters.
    detector = cv2.SimpleBlobDetector_create(params)

    # Detect blobs.
    keypoints = detector.detect(im)
    # Draw detected blobs as red circles.
    # cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS ensures the size of the circle corresponds to the size of blob
    if not obj.showBlobs:
        im_with_keypoints = cv2.drawKeypoints(im, keypoints, np.array([]), (0,0,255), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
        obj.Proxy.img = im_with_keypoints

        for k in keypoints:
            (x,y)=k.pt
            x=int(round(x))
            y=int(round(y))
#           cv2.circle(im,(x,y),4,0,5)
            cv2.circle(im,(x,y),4,255,5)
            cv2.circle(im,(x,y),4,0,5)
            im[y,x]=255
            im[y,x]=0
        obj.Proxy.img = cv2.cvtColor(im, cv2.COLOR_GRAY2BGR)

    else:
        for k in keypoints:
            (x,y)=k.pt
            x=int(round(x))
            y=int(round(y))
            cv2.circle(im2,(x,y),4,(255,0,0),5)
            cv2.circle(im2,(x,y),4,(0,0,0),5)
            im2[y,x]=(255,0,0)
            im2[y,x]=(0,0,0)
        obj.Proxy.img = im2
项目: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
# ============================================================= #
项目:bib-tagger    作者:KateRita    | 项目源码 | 文件源码
def find_blobs(img):
    # Setup SimpleBlobDetector parameters.
    params = cv2.SimpleBlobDetector_Params()

    # Change thresholds
    params.minThreshold = 100;
    params.maxThreshold = 5000;

    # Filter by Area.
    params.filterByArea = True
    params.minArea = 200

    # Filter by Circularity
    params.filterByCircularity = False
    params.minCircularity = 0.785

    # Filter by Convexity
    params.filterByConvexity = False
    params.minConvexity = 0.87

    # Filter by Inertia
    #params.filterByInertia = True
    #params.minInertiaRatio = 0.01

    # Set up the detector with default parameters.
    detector = cv2.SimpleBlobDetector(params)

    # Detect blobs.
    keypoints = detector.detect(img)
    print keypoints

    # Draw detected blobs as red circles.
    # cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS ensures the size of the circle corresponds to the size of blob
    im_with_keypoints = cv2.drawKeypoints(img, keypoints, np.array([]),
            (0,0,255), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
    cv2.imwrite("blobs.jpg", im_with_keypoints);
项目:Conquest_kshitij    作者:pigeon-kgp    | 项目源码 | 文件源码
def blobdetect(img):
    hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)

    yellowMin = (20,100,100)
    yellowMax = (30, 255, 255)

    blueMin=(50,100,100)
    blueMax=(100,255,255)

    brownMin=(0,100,0)
    brownMax=(20,255,255)
    yellow=cv2.inRange(hsv,yellowMin, yellowMax)
    blue=cv2.inRange(hsv,blueMin,blueMax)
    brown=cv2.inRange(hsv,brownMin,brownMax)

    params = cv2.SimpleBlobDetector_Params()
    params.filterByArea = True
    params.minArea=150
    detector=cv2.SimpleBlobDetector(params)
    keypoints=detector.detect(255-yellow)
    food=[]
    for i in keypoints:
        x=i.pt[0]; y=i.pt[1]
        food.append([x,y])

    params.maxArea=250
    detector=cv2.SimpleBlobDetector(params)
    keypoints=detector.detect(255-yellow)

    wood=[]
    for i in keypoints:
        x=i.pt[0]; y=i.pt[1]
        wood.append([x,y])

    params=cv2.SimpleBlobDetector()
    keypoints=params.detect(255-blue)
    rivers=[]
    for i in keypoints:
        x=i.pt[0]; y=i.pt[1]
        rivers.append([x,y])

    keypoints=params.detect(255-brown)
    centre=[]
    for i in keypoints:
        x=i.pt[0]; y=i.pt[1]
        centre.append([x,y])

    return [food, wood, rivers, centre]