简体   繁体   中英

python opencv 'SystemError: <built-in function drawKeypoints> returned NULL without setting an error'

I have a blob detector:

class ImgProcessor:
def __init__(self, **kwargs):

    params = cv2.SimpleBlobDetector_Params()  # create a new list of parameters for blob detector
    params.filterByArea = True
    params.maxArea = 1500

    self.blob_detector = cv2.SimpleBlobDetector_create(params)  # create blob detector and assign parameter list

def blob_process(self, img):

    keypoints = self.blob_detector.detect(img)

    # check if there is more than one keypoint and keep the largest.
    if len(keypoints) > 1:
        kp = keypoints[0]
        for k in keypoints[1:]:
            if k.size > kp.size:
                kp = k
    else:
        kp = keypoints
    print(kp)

    blob_img = cv2.drawKeypoints(img, kp, img, (255,255,255),cv2.DRAW_MATCHES_FLAGS_DEFAULT)
    return blob_img

def threshold_process(self, _img, _threshold):
    gray_frame = cv2.cvtColor(_img, cv2.COLOR_RGB2GRAY) # turn image into bw version
    ret, img = cv2.threshold(gray_frame, _threshold, 255, cv2.THRESH_BINARY) # create threshold image
    img = cv2.erode(img, None, iterations=2)  # 1
    img = cv2.dilate(img, None, iterations=4)  # 2
    img = cv2.medianBlur(img, 5)
    return img

when I run the testing code:

if __name__ == "__main__":
    classifier = Classifier()
    ImgProcessor = ImgProcessor()

    img = cv2.imread("img.png")
    threshold_img = ImgProcessor.threshold_process(img, 51)
    cv2.imshow("threshold", threshold_img)
    blob = ImgProcessor.blob_process(threshold_img)
    cv2.imshow("Blob", blob)


    cv2.waitKey(0)
    cv2.destroyAllWindows()

I get this error:

blob_img = cv2.drawKeypoints(img, kp, img, (255,255,255),cv2.DRAW_MATCHES_FLAGS_DEFAULT) SystemError: returned NULL without setting an error

I know that there is a keypoint being detected from previous testing.

I have so far tried changing this line to different draw matches however, my understanding of open cv is not great so any assistance would be greatly appreciated.

Figured it out, I was using a Keypoint value, not an array of Keypoints

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM