繁体   English   中英

python opencv '系统错误:<built-in function drawkeypoints> 在没有设置错误的情况下返回 NULL'</built-in>

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

我有一个斑点检测器:

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

当我运行测试代码时:

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

我收到此错误:

blob_img = cv2.drawKeypoints(img, kp, img, (255,255,255),cv2.DRAW_MATCHES_FLAGS_DEFAULT) SystemError: 返回 NULL 没有设置错误

我知道从之前的测试中检测到了一个关键点。

到目前为止,我已经尝试将这条线更改为不同的平局比赛,但是,我对 open cv 的理解不是很好,因此非常感谢任何帮助。

弄清楚了,我使用的是关键点值,而不是关键点数组

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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