Search code examples
pythonuser-interfacepycharmglob

Crash when reading bit map image in python


Using the following code block, I am trying to read and store a bmp image in order to make some image processing using a matching algorithm.

  print("starting read image function")
    fimage = glob.glob("test.bmp")
    incomingFingerprint = cv2.imread(fimage)
    cv2.imwrite(fimage.replace('.bmp', '.jpg'), incomingFingerprint)

I got my code crashed and printed this line in the terminal:

Process finished with exit code -1073740791 (0xC0000409)

I want to successfully read and store an image in a variable and then apply some image processing algorithms.


Solution

  • You're incorrectly using glob — it gives you a list on output. Instead, simply pass image name to the imread and imwrite functions:

    import cv2
    
    incoming_fingerprint = cv2.imread('test.bmp')
    cv2.imwrite('test.jpg', incoming_fingerprint)