簡體   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