问题描述:
Opencv Blob Detection 中的python调用片段
# Standard imports
import cv2
import numpy as np;
# Read image
im = cv2.imread("blob.jpg", cv2.IMREAD_GRAYSCALE)
# Set up the detector with default parameters.
detector = cv2.SimpleBlobDetector()
# 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
im_with_keypoints = cv2.drawKeypoints(im, keypoints, np.array([]), (0,0,255), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
# Show keypoints
cv2.imshow("Keypoints", im_with_keypoints)
cv2.waitKey(0)
会出现如下错误:
keypoints = detector.detect(im)
cv2.error: Unknown C++ exception from OpenCV code
问题描述:
在新版本中cv2.SimpleBlobDetector()
已经弃用。
解决方法:
detector = cv2.SimpleBlobDetector()
改为
detector = cv2.SimpleBlobDetector_create()