コード例 #1
0
def selectBlob(img):

    gray = sf.image_gray(img)

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

    # Detect blobs.
    # print dir(keypoints)
    keypoints = detector.detect(gray)
    if not keypoints:
        x = 0
        y = 0
    else:
        x = keypoints[0].pt[0]
        y = keypoints[0].pt[1]

    # 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
    )

    # Show keypoints
    # sf.display_image(im_with_keypoints)
    return im_with_keypoints, x, y
コード例 #2
0
def selectBlob_v2(image, params, detector):
    gray = sf.image_gray(image)
    # gray=sf.invert(gray)
    keypoints = detector.detect(gray)

    if not keypoints:
        x = 0
        y = 0
    else:
        x = keypoints[0].pt[0]
        y = keypoints[0].pt[1]

    im_with_keypoints = cv2.drawKeypoints(
        image, keypoints, np.array([]), (0, 0, 255), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS
    )
    return im_with_keypoints, x, y