Python Opencv-python crashes when running


As the title state python is crashing whenever I try to call sift.detectAndComputer()

def compare_images():
    cwd = os.getcwd()
    target = os.path.join(cwd, 'target.png')
    images_list = os.listdir('images')
    for image in images_list:
        # get my 2 images
        img1 = cv2.imread(os.path.join(cwd, 'images', image))
        img2 = cv2.imread(target)

        # Initiate SIFT detector
        sift = cv2.SIFT()

        # find the key points and descriptors with SIFT
        kp1, des1 = sift.detectAndCompute(img1, None)
        kp2, des2 = sift.detectAndCompute(img2, None)

        # bf matcher with default params
        bf = cv2.BFMatcher()
        matches = bf.knnMatch(des1, des2, k=2)

        # apply ratio test
        good = []
        for m, n in matches:
            if m.distance < .75 * n.distance:

        img3 = cv2.drawMatchesKnn(img1, kp1, img2, kp2, good, flags=2)

if __name__ == '__main__':

When I hit this line kp1, des1 = sift.detectAndCompute(img1, None) I get a windows popup that says: "Python has stopped working

A problem cause the program to stop working correctly. Please close the program."

Then in the console output I get this:

Process finished with exit code -1073741819 (0xC0000005)

Not sure what's going on here and why I am not getting a more descriptive error of failure for this. Any help/fixes?

asked on Stack Overflow May 5, 2021 by mike_gundy123

0 Answers

Nobody has answered this question yet.

User contributions licensed under CC BY-SA 3.0