How to fix cv2.error: Unknown C++ exception from OpenCV code?

Viewed 4632

I need to detect semicircles on image and I find follow stuff for this:

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)

But I give follow error when I try to run it:

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

Image: click

1 Answers

I figured out your problem. You have used cv2.SimpleBlobDetector() which is old version. Use cv2.SimpleBlobDetector_create() instead.

Related