keypoints = detector.detect(im) cv2.error: Unknown C++ exception from OpenCV code 解决方法

问题描述:

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

参考链接:

https://stackoverflow.com/questions/68964996/how-to-fix-cv2-error-unknown-c-exception-from-opencv-code

猜你喜欢

转载自blog.csdn.net/Thinkin9/article/details/123130700