OpenCV SimpleBlobDetector detector() 调用抛出 cv2.error:OpenCV 代码中的未知 C++ 异常?

buy*_*pps 7 python ocr opencv object-detection

我需要检测图像上的半圆,我找到了以下内容:

import cv2
import numpy as np


def get_circle(img_path):
    im = cv2.imread(img_path, cv2.IMREAD_GRAYSCALE)
    detector = cv2.SimpleBlobDetector()
    keypoints = detector.detect(im)
    im_with_keypoints = cv2.drawKeypoints(im, keypoints, np.array([]), (0,0,255), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
    cv2.imshow("Keypoints", im_with_keypoints)
    cv2.waitKey(0)
Run Code Online (Sandbox Code Playgroud)

但是当我尝试运行它时出现以下错误:

Traceback (most recent call last):
  File "D:\giveaway_bot\main.py", line 16, in <module>
    get_circle("blob.png")
  File "D:\giveaway_bot\main.py", line 11, in get_circle
    keypoints = detector.detect(im)
cv2.error: Unknown C++ exception from OpenCV code
Run Code Online (Sandbox Code Playgroud)

图片: 点击

小智 19

我弄清楚了你的问题。您使用的cv2.SimpleBlobDetector()是旧版本。cv2.SimpleBlobDetector_create()代替使用。